Skip to content

Commit

Permalink
endpoints added
Browse files Browse the repository at this point in the history
gofmt on all files
  • Loading branch information
liampauling committed Jul 10, 2017
1 parent d76b197 commit d9a6740
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 346 deletions.
135 changes: 56 additions & 79 deletions betting.go
Original file line number Diff line number Diff line change
@@ -1,123 +1,107 @@
package gofair


type eventType struct {
Id string `json:"id"`
Name string `json:"name"`
Id string `json:"id"`
Name string `json:"name"`
}


type eventTypeResult struct {
MarketCount int `json:"marketCount"`
EventType *eventType `json:"eventType"`
MarketCount int `json:"marketCount"`
EventType *eventType `json:"eventType"`
}


type competition struct {
Id string `json:"id"`
Name string `json:"name"`
Id string `json:"id"`
Name string `json:"name"`
}


type competitionResult struct {
MarketCount int `json:"marketCount"`
CompetitionRegion string `json:"competitionRegion"`
Competition *competition `json:"competition"`
MarketCount int `json:"marketCount"`
CompetitionRegion string `json:"competitionRegion"`
Competition *competition `json:"competition"`
}


type timeRange struct {
From string `json:"from"`
To string `json:"to"`
From string `json:"from"`
To string `json:"to"`
}


type timeRangeResult struct {
MarketCount int `json:"marketCount"`
TimeRange *timeRange `json:"timeRange"`
MarketCount int `json:"marketCount"`
TimeRange *timeRange `json:"timeRange"`
}


type event struct {
Id string `json:"id"`
OpenDate string `json:"openDate"`
TimeZone string `json:"timezone"`
CountryCode string `json:"countryCode"`
Name string `json:"name"`
Venue string `json:"venue"`
Id string `json:"id"`
OpenDate string `json:"openDate"`
TimeZone string `json:"timezone"`
CountryCode string `json:"countryCode"`
Name string `json:"name"`
Venue string `json:"venue"`
}


type eventResult struct {
MarketCount int `json:"marketCount"`
Event *event `json:"event"`
MarketCount int `json:"marketCount"`
Event *event `json:"event"`
}


type marketTypeResult struct {
MarketCount int `json:"marketCount"`
MarketType string `json:"marketType"`
MarketCount int `json:"marketCount"`
MarketType string `json:"marketType"`
}


type countryResult struct {
MarketCount int `json:"marketCount"`
CountryCode string `json:"countryCode"`
MarketCount int `json:"marketCount"`
CountryCode string `json:"countryCode"`
}


type venueResult struct {
MarketCount int `json:"marketCount"`
Venue string `json:"venue"`
MarketCount int `json:"marketCount"`
Venue string `json:"venue"`
}


type marketCatalogueDescription struct {
BettingType string `json:"bettingType"`
BSPMarket bool `json:"bspMarket"`
DiscountAllowed bool `json:"discountAllowed"`
MarketBaseRate float32 `json:"marketBaseRate"`
MarketTime string `json:"marketTime"`
MarketType string `json:"marketType"`
PersistenceEnabled bool `json:"persistenceEnabled"`
Regulator string `json:"regulator"`
Rules string `json:"rules"`
RulesHasDate bool `json:"rulesHasDate"`
SuspendDate string `json:"suspendTime"`
TurnInPlayEnabled bool `json:"turnInPlayEnabled"`
Wallet string `json:"wallet"`
EachWayDivisor float32 `json:"eachWayDivisor"`
Clarifications string `json:"clarifications"`
BettingType string `json:"bettingType"`
BSPMarket bool `json:"bspMarket"`
DiscountAllowed bool `json:"discountAllowed"`
MarketBaseRate float32 `json:"marketBaseRate"`
MarketTime string `json:"marketTime"`
MarketType string `json:"marketType"`
PersistenceEnabled bool `json:"persistenceEnabled"`
Regulator string `json:"regulator"`
Rules string `json:"rules"`
RulesHasDate bool `json:"rulesHasDate"`
SuspendDate string `json:"suspendTime"`
TurnInPlayEnabled bool `json:"turnInPlayEnabled"`
Wallet string `json:"wallet"`
EachWayDivisor float32 `json:"eachWayDivisor"`
Clarifications string `json:"clarifications"`
}


type metadata struct {
RunnerId int `json:"runnerId"`
RunnerId int `json:"runnerId"`
}


type runnerCatalogue struct {
SelectionId int `json:"selectionId"`
RunnerName string `json:"runnerName"`
SortPriority int `json:"sortPriority"`
Handicap float32 `json:"handicap"`
SelectionId int `json:"selectionId"`
RunnerName string `json:"runnerName"`
SortPriority int `json:"sortPriority"`
Handicap float32 `json:"handicap"`
//Metadata *metadata `json:"metadata"` //todo
}


type marketCatalogue struct {
MarketId string `json:"marketId"`
MarketName string `json:"marketName"`
TotalMatched float32 `json:"totalMatched"`
MarketStartTime string `json:"marketStartTime"`
Competition *competition `json:"competition"`
Event *event `json:"event"`
EventType *eventType `json:"eventType"`
MarketCatalogueDescription *marketCatalogueDescription `json:"description"`
Runners *[]runnerCatalogue `json:"runners"`
MarketId string `json:"marketId"`
MarketName string `json:"marketName"`
TotalMatched float32 `json:"totalMatched"`
MarketStartTime string `json:"marketStartTime"`
Competition *competition `json:"competition"`
Event *event `json:"event"`
EventType *eventType `json:"eventType"`
MarketCatalogueDescription *marketCatalogueDescription `json:"description"`
Runners *[]runnerCatalogue `json:"runners"`
}


func (b *Betting) ListEventTypes(filter MarketFilter) ([]eventTypeResult, error) {
// create url
url := createUrl(api_betting_url, "listEventTypes/")
Expand All @@ -136,7 +120,6 @@ func (b *Betting) ListEventTypes(filter MarketFilter) ([]eventTypeResult, error)
return response, err
}


func (b *Betting) ListCompetitions(filter MarketFilter) ([]competitionResult, error) {
// create url
url := createUrl(api_betting_url, "listCompetitions/")
Expand All @@ -155,7 +138,6 @@ func (b *Betting) ListCompetitions(filter MarketFilter) ([]competitionResult, er
return response, err
}


func (b *Betting) ListTimeRanges(filter MarketFilter, granularity string) ([]timeRangeResult, error) {
// create url
url := createUrl(api_betting_url, "listTimeRanges/")
Expand All @@ -175,7 +157,6 @@ func (b *Betting) ListTimeRanges(filter MarketFilter, granularity string) ([]tim
return response, err
}


func (b *Betting) ListEvents(filter MarketFilter) ([]eventResult, error) {
// create url
url := createUrl(api_betting_url, "listEvents/")
Expand All @@ -194,7 +175,6 @@ func (b *Betting) ListEvents(filter MarketFilter) ([]eventResult, error) {
return response, err
}


func (b *Betting) ListMarketTypes(filter MarketFilter) ([]marketTypeResult, error) {
// create url
url := createUrl(api_betting_url, "listMarketTypes/")
Expand All @@ -213,7 +193,6 @@ func (b *Betting) ListMarketTypes(filter MarketFilter) ([]marketTypeResult, erro
return response, err
}


func (b *Betting) ListCountries(filter MarketFilter) ([]countryResult, error) {
// create url
url := createUrl(api_betting_url, "listCountries/")
Expand All @@ -232,7 +211,6 @@ func (b *Betting) ListCountries(filter MarketFilter) ([]countryResult, error) {
return response, err
}


func (b *Betting) ListVenues(filter MarketFilter) ([]venueResult, error) {
// create url
url := createUrl(api_betting_url, "listVenues/")
Expand All @@ -251,7 +229,6 @@ func (b *Betting) ListVenues(filter MarketFilter) ([]venueResult, error) {
return response, err
}


func (b *Betting) ListMarketCatalogue(filter MarketFilter, marketProjection []string, sort string, maxResults int) (
[]marketCatalogue, error) {
// create url
Expand Down
68 changes: 40 additions & 28 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,63 +1,68 @@
package gofair

import (
"time"
"crypto/tls"
"time"
)


// betfair api endpoints
const (
login_url = "https://identitysso-api.betfair.com/api/"
identity_url = "https://identitysso.betfair.com/api/"
login_url = "https://identitysso-api.betfair.com/api/"
identity_url = "https://identitysso.betfair.com/api/"
api_betting_url = "https://api.betfair.com/exchange/betting/rest/v1.0/"
api_account_url = "https://api.betfair.com/exchange/account/rest/v1.0/"
navigation_url = "https://api.betfair.com/exchange/betting/rest/v1/en/navigation/menu.json"
navigation_url = "https://api.betfair.com/exchange/betting/rest/v1/en/navigation/menu.json"
)


// holds login data
type Config struct {
Username string
Password string
AppKey string
CertFile string
KeyFile string
Locale string
Username string
Password string
AppKey string
CertFile string
KeyFile string
Locale string
}


// holds session data
type session struct {
SessionToken string
LoginTime time.Time
SessionToken string
LoginTime time.Time
}


// main client object
type Client struct {
config *Config
session *session
certificates *tls.Certificate
Betting *Betting
Historical *Historical
config *Config
session *session
certificates *tls.Certificate
Betting *Betting
Account *Account
Streaming *Streaming
Historical *Historical
}


// betting object
type Betting struct {
Client *Client
Client *Client
}

// account object
type Account struct {
Client *Client
}

// streaming object
type Streaming struct {
Client *Client
}

// historical object
type Historical struct {
Client *Client
Client *Client
}


// creates new client
func NewClient(config *Config)(*Client, error){
func NewClient(config *Config) (*Client, error) {
c := new(Client)

// create session
Expand All @@ -77,15 +82,22 @@ func NewClient(config *Config)(*Client, error){
c.Betting = new(Betting)
c.Betting.Client = c

// create account
c.Account = new(Account)
c.Account.Client = c

// create streaming
c.Streaming = new(Streaming)
c.Streaming.Client = c

// create historical
c.Historical = new(Historical)
c.Historical.Client = c

return c, nil
}


func (c *Client) SessionExpired() (bool){
func (c *Client) SessionExpired() bool {
// returns True if client not logged in or expired
// betfair requires keep alive every 4hrs (20mins ITA)
if c.session.SessionToken == "" {
Expand Down
Loading

0 comments on commit d9a6740

Please sign in to comment.