-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbetting.go
261 lines (224 loc) · 6.98 KB
/
betting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Copyright 2013 Alessandro De Donno
// "Betfair API-NG Golang Library" is dual-licensed: for free software projects
// please refer to GPLv3 (see declaration above), for commercial software
// please contact the author.
// If you are a contributor and need any clarification, please contact the
// author.
// For free software projects:
// This file is part of "Betfair API-NG Golang Library".
// "Betfair API-NG Golang Library" is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
// "Betfair API-NG Golang Library" is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with "Betfair API-NG Golang Library". If not, see
// <http://www.gnu.org/licenses/>.
package betfair
import (
"time"
"encoding/json"
"strings"
// "log"
)
type MarketFilter struct {
TextQuery string `json:"textQuery,omitempty"`
ExchangeIds []string `json:"exchangeIds,omitempty"`
EventTypeIds []string `json:"eventTypeIds,omitempty"`
MarketCountries []string `json:"marketCountries,omitempty"`
MarketIds []string `json:"marketIds,omitempty"`
}
type PriceProjection struct {
PriceData []string `json:"priceData,omitempty"`
}
type Params struct {
MarketFilter *MarketFilter `json:"filter,omitempty"`
MarketIds []string `json:"marketIds,omitempty"`
PriceProjection *PriceProjection `json:"priceProjection,omitempty"`
MaxResults int `json:"maxResults,omitempty"`
Locale string `json:"locale,omitempty"`
}
type EventType struct {
Id string
Name string
}
type EventTypeResult struct {
EventType *EventType
MarketCount int
}
type Competition struct {
Id string
Name string
}
type CompetitionResult struct {
Competition *Competition
MarketCount int
CompetitionRegion string
}
type CountryCodeResult struct {
CountryCode string
MarketCount int
}
type Event struct {
Id string
Name string
CountryCode string
Timezone string
Venue string
OpenDate time.Time
}
type EventResult struct {
Event *Event
MarketCount int
}
type MarketBook struct {
MarketId string
IsMarketDataDelayed bool
Status string
BetDelay int
BspReconciled bool
Complete bool
Inplay bool
NumberOfWinners int
NumberOfRunners int
NumberOfActiveRunners int
LastMatchTime time.Time
TotalMatched float32
TotalAvailable float32
CrossMatching bool
RunnersVoidable bool
Version int
Runners []Runner
}
type Runner struct {
SelectionId int
}
// Information about the Runners (selections) in a market.
type RunnerCatalog struct {
SelectionId uint32
RunnerName string
Handicap float32
SortPriority int
Metadata map[string]string
}
// Information about a market.
type MarketCatalogue struct {
MarketId string
MarketName string
MarketStartTime time.Time
Description *MarketDescription
Runners []RunnerCatalog
EventType *EventType
Competition *Competition
Event *Event
}
// Market definition.
type MarketDescription struct {
PersistenceEnabled bool
BspMarket bool
MarketTime time.Time
SuspendTime time.Time
SettleTime time.Time
BettingType string
TurnInPlayEnabled bool
MarketType string
Regulator string
MarketBaseRate float32
DiscountAllowed bool
Wallet string
Rules string
RulesHasDate bool
Clarifications string
}
// MarketType Result.
type MarketTypeResult struct {
MarketType string
MarketCount int
}
// Returns a list of Competitions (i.e., World Cup 2013) associated with the
// markets selected by the MarketFilter.
func (s *Session) ListCompetitions(filter *MarketFilter) ([]CompetitionResult, error) {
var results []CompetitionResult
params := new(Params)
params.MarketFilter = filter
err := doBettingRequest(s, "listCompetitions", params, &results)
return results, err
}
// Returns a list of Countries associated with the markets selected by the
// MarketFilter.
func (s *Session) ListCountries(filter *MarketFilter) ([]CountryCodeResult, error) {
var results []CountryCodeResult
params := new(Params)
params.MarketFilter = filter
err := doBettingRequest(s, "listCountries", params, &results)
return results, err
}
// Returns a list of Events (i.e, Reading vs. Man United) associated with the
// markets selected by the MarketFilter.
func (s *Session) ListEvents(filter *MarketFilter) ([]EventResult, error) {
var results []EventResult
params := new(Params)
params.MarketFilter = filter
err := doBettingRequest(s, "listEvents", params, &results)
return results, err
}
// Returns a list of Event Types (i.e. Sports) associated with the markets
// selected by the MarketFilter.
func (s *Session) ListEventTypes(filter *MarketFilter) ([]EventTypeResult, error) {
var results []EventTypeResult
params := new(Params)
params.MarketFilter = filter
err := doBettingRequest(s, "listEventTypes", params, &results)
return results, err
}
// Returns a list of dynamic data about markets. Dynamic data includes prices,
// the status of the market, the status of selections, the traded volume, and
// the status of any orders you have placed in the market.
func (s *Session) ListMarketBook(marketIds []string) ([]MarketBook, error) {
var results []MarketBook
params := new(Params)
params.MarketIds = marketIds
err := doBettingRequest(s, "listMarketBook", params, &results)
return results, err
}
// Returns a list of information about markets that does not change (or
// changes very rarely). You use listMarketCatalogue to retrieve the name
// of the market, the names of selections and other information about markets.
// Market Data Request Limits apply to requests made to listMarketCatalogue.
func (s *Session) ListMarketCatalogue(filter *MarketFilter, maxResults int) ([]MarketCatalogue, error) {
var results []MarketCatalogue
params := new(Params)
params.MarketFilter = filter
params.MaxResults = maxResults
err := doBettingRequest(s, "listMarketCatalogue", params, &results)
return results, err
}
// Returns a list of market types (i.e. MATCH_ODDS, NEXT_GOAL) associated
// with the markets selected by the MarketFilter. The market types are always
// the same, regardless of locale.
func (s *Session) ListMarketTypes (filter *MarketFilter) ([]MarketTypeResult, error) {
var results []MarketTypeResult
params := new(Params)
params.MarketFilter = filter
err := doBettingRequest(s, "listMarketTypes", params, &results)
return results, err
}
func doBettingRequest(s *Session, method string, params *Params, v interface{}) error {
params.Locale = s.config.Locale
bytes, err := json.Marshal(params)
if err != nil {
return err
}
body := strings.NewReader(string(bytes))
data, err := doRequest(s, "betting", method + "/", body)
if err != nil {
return err
}
if err := json.Unmarshal(data, v); err != nil {
return err
}
return nil
}