oddsapi

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2022 License: MIT Imports: 8 Imported by: 0

README

odds-api-go

Go Reference

Unofficial Go client library for the-odds-api.

Install

import "git.sr.ht/~swf/odds-api-go"

Then run go mod tidy

Usage

Getting valid sports
package main

import (
	"fmt"
	"git.sr.ht/~swf/odds-api-go"
)

func main() {
	c := oddsapi.NewClient("YOUR API KEY HERE")
	s, err := c.GetSports(oddsapi.GetSportsInput{
		IncludeInactive: false,
	})
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(s)
}
Getting events data
package main

import (
	"fmt"
	"git.sr.ht/~swf/odds-api-go"
)

func main() {
	c := oddsapi.NewClient("YOUR API KEY HERE")
	s, err := c.GetEvents(oddsapi.GetEventsInput{
		Sports:  []string{"americanfootball_nfl"},
		Regions: []oddsapi.RegionType{oddsapi.RegionUS},
		Markets: []oddsapi.MarketType{oddsapi.MarketMoneyline},
	})
	if err != nil {
		fmt.Println(err.Error())
        	return
	}
	fmt.Println(s)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated = errors.New("Unauthenticated or unauthorized. The API key might be missing or invalid (unauthenticated), or it might at its usage limit (unauthorized). The repsonse body will contain more info")
	ErrQueryParams     = errors.New("One or more of the query params are invalid. The repsonse body will contain more info")
	ErrThrottled       = errors.New("Requests are being sent too frequently - the request was throttled")
	ErrServer          = errors.New("Internal error")
	ErrUnknown         = errors.New("An unrecognized error has occured")
)

Functions

This section is empty.

Types

type Bookmaker

type Bookmaker struct {
	Key        string   `json:"key"`
	Title      string   `json:"title"`
	LastUpdate string   `json:"last_update"`
	Markets    []Market `json:"markets"`
}

type Client

type Client struct {
	ApiKey            string
	RequestsRemaining int
	RequestsUsed      int
}

func NewClient

func NewClient(apiKey string) (c Client)

func (*Client) GetEvents

func (c *Client) GetEvents(input GetEventsInput) (evs []Event, err error)

GetEvents reaches out to the-odds-api and returns the latest odds

func (*Client) GetSports

func (c *Client) GetSports(input GetSportsInput) (sports []Sport, err error)

GetSports reaches out to the-odds-api and returns the list of in or out of season sports

type Event

type Event struct {
	Id           string      `json:"id"`
	SportKey     string      `json:"sport_key"`
	SportTitle   string      `json:"sport_title"`
	CommenceTime time.Time   `json:"commence_time"`
	HomeTeam     string      `json:"home_team"`
	AwayTeam     string      `json:"away_team"`
	Bookmakers   []Bookmaker `json:"bookmakers"`
}

type GetEventsInput

type GetEventsInput struct {
	Sports     []string
	Regions    []RegionType
	Markets    []MarketType
	OddsFormat OddsFormatType
}

type GetSportsInput

type GetSportsInput struct {
	IncludeInactive bool
}

type Market

type Market struct {
	Key      string    `json:"key"`
	Outcomes []Outcome `json:"outcomes"`
}

type MarketType

type MarketType int
const (
	MarketMoneyline MarketType = iota
	MarketMoneylineLay
	MarketSpread
	MarketTotal
	MarketOutright
)

func (MarketType) String

func (m MarketType) String() string

type OddsFormatType

type OddsFormatType int
const (
	OddsFormatDecimal OddsFormatType = iota
	OddsFormatAmerican
)

func (OddsFormatType) String

func (fo OddsFormatType) String() string

type Outcome

type Outcome struct {
	Name   string  `json:"name"`
	Price  float64 `json:"price"`
	Points float64 `json:"points"`
}

type RegionType

type RegionType int
const (
	RegionUS RegionType = iota
	RegionEU
	RegionUK
	RegionAU
)

func (RegionType) String

func (r RegionType) String() string

type Sport

type Sport struct {
	Key          string `json:"key"`
	Active       bool   `json:"active"`
	Group        string `json:"group"`
	Description  string `json:"description"`
	Title        string `json:"title"`
	HasOutrights bool   `json:"has_outrights"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL