betfair 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +30 -29
- data/examples/simplebot/simplebot.rb +4 -2
- data/lib/betfair/api.rb +221 -196
- data/lib/betfair/version.rb +1 -1
- metadata +12 -13
- data/examples/simplebot/simplebot.log +0 -0
data/README.md
CHANGED
@@ -42,12 +42,12 @@ as the UK.
|
|
42
42
|
At the heart of the Betfair API is the `session_token`. In order to
|
43
43
|
get one of these simply call:
|
44
44
|
|
45
|
-
username
|
46
|
-
password
|
47
|
-
product_id
|
48
|
-
vendor_software_id
|
49
|
-
location_id
|
50
|
-
ip_address
|
45
|
+
username = 'foo'
|
46
|
+
password = 'bar'
|
47
|
+
product_id = 82
|
48
|
+
vendor_software_id = 0
|
49
|
+
location_id = 0
|
50
|
+
ip_address = nil
|
51
51
|
|
52
52
|
session_token = bf.login(username, password, product_id, vendor_software_id, location_id, ip_address)
|
53
53
|
|
@@ -172,14 +172,14 @@ The API PlaceBets service allows you to place multiple (1 to 60) bets on a singl
|
|
172
172
|
## Update Bet ##
|
173
173
|
The API UpdateBets service allows you to edit multiple (1 to 15) bets on a single Market.
|
174
174
|
|
175
|
-
exchange_id
|
176
|
-
bet_id
|
177
|
-
new_bet_persistence_type
|
178
|
-
new_price
|
179
|
-
new_size
|
180
|
-
old_bet_persistence_type
|
181
|
-
old_price= 5.0
|
182
|
-
old_size
|
175
|
+
exchange_id = 1
|
176
|
+
bet_id = 1234,
|
177
|
+
new_bet_persistence_type = 'NONE'
|
178
|
+
new_price = 10.0
|
179
|
+
new_size = 10.0
|
180
|
+
old_bet_persistence_type = 'NONE'
|
181
|
+
old_price = 5.0
|
182
|
+
old_size = 5.0
|
183
183
|
|
184
184
|
update_bet =
|
185
185
|
bf.update_bet(session_token, exchange_id, bet_id, new_bet_persistence_type, new_price, new_size, old_bet_persistence_type, old_price, old_size)
|
@@ -188,7 +188,7 @@ The API UpdateBets service allows you to edit multiple (1 to 15) bets on a singl
|
|
188
188
|
The API UpdateBets service allows you to edit multiple (1 to 15) bets on a single Market.
|
189
189
|
|
190
190
|
exchange_id = 1
|
191
|
-
bets
|
191
|
+
bets = []
|
192
192
|
bets << { bet_id: 1234, new_bet_persistence_type: 'NONE', new_price: 10.0, new_size: 10.0,
|
193
193
|
old_bet_persistence_type: 'NONE', old_price: 5.0, old_size: 5.0 }
|
194
194
|
bets << { bet_id: 1235, new_bet_persistence_type: 'NONE', new_price: 2.0, new_size: 10.0,
|
@@ -247,7 +247,7 @@ This function does the same as the #all_markets method. Not sure how/why it has
|
|
247
247
|
duplicated, but it has so here is how it works.
|
248
248
|
|
249
249
|
all_markets = bf.get_all_markets(session_token, 2, [61420], nil, nil, nil, nil)
|
250
|
-
foo
|
250
|
+
foo = helpers.split_markets_string(all_markets)
|
251
251
|
|
252
252
|
The output looks a little different to the #all_markets method.
|
253
253
|
|
@@ -262,8 +262,8 @@ foo.first returns
|
|
262
262
|
## Market Info ##
|
263
263
|
This helper sorts out a nice hash from the
|
264
264
|
|
265
|
-
market
|
266
|
-
foo
|
265
|
+
market = bf.get_market(session_token, 2, 100388290)
|
266
|
+
foo = helpers.market_info(details)
|
267
267
|
|
268
268
|
Which returns
|
269
269
|
|
@@ -272,15 +272,15 @@ Which returns
|
|
272
272
|
## Prices ##
|
273
273
|
This helper cleans up the prices
|
274
274
|
|
275
|
-
prices
|
276
|
-
foo
|
275
|
+
prices = bf.get_market_prices_compressed(session_token, 2, 100388290)
|
276
|
+
foo = helpers.prices(prices)
|
277
277
|
|
278
278
|
## Combine ##
|
279
279
|
Use this to combine `runner_names` and prices from the #market_info and #prices helpers
|
280
280
|
|
281
|
-
market
|
282
|
-
prices
|
283
|
-
foo
|
281
|
+
market = bf.get_market(session_token, 2, 100388290)
|
282
|
+
prices = bf.get_market_prices_compressed(session_token, 2, 100388290)
|
283
|
+
foo = helpers.combine(market, prices)
|
284
284
|
|
285
285
|
foo.first returns
|
286
286
|
|
@@ -293,8 +293,8 @@ foo.first returns
|
|
293
293
|
## Details ##
|
294
294
|
Gets the `market_id`/`market_name` and the `runner_id`/`runner_name`
|
295
295
|
|
296
|
-
market
|
297
|
-
foo
|
296
|
+
market = bf.get_market(session_token, 2, 100388290)
|
297
|
+
foo = helpers.details(market)
|
298
298
|
|
299
299
|
Which returns
|
300
300
|
|
@@ -313,8 +313,8 @@ Which returns
|
|
313
313
|
## Prices Complete ##
|
314
314
|
Helper to deal with the prices string from a market.
|
315
315
|
|
316
|
-
prices
|
317
|
-
foo
|
316
|
+
prices = bf.get_market_prices_compressed(session_token, 2, 100388290)
|
317
|
+
foo = helpers.prices_complete(prices)
|
318
318
|
|
319
319
|
foo.first returns
|
320
320
|
|
@@ -326,8 +326,8 @@ foo.first returns
|
|
326
326
|
|
327
327
|
## Prices String ##
|
328
328
|
|
329
|
-
prices
|
330
|
-
foo
|
329
|
+
prices = bf.get_market_prices_compressed(session_token, 2, 100388290)
|
330
|
+
foo = helpers.price_string(prices, true)
|
331
331
|
|
332
332
|
{ :prices_string=>nil, :runner_matched=>0, :last_back_price=>0, :wom=>0.6054936499440416, :b1=>4.2, :b1_available=>430.35, :b2=>4.1, :b2_available=>311.51, :b3=>3.85,
|
333
333
|
:b3_available=>4.75, :l1=>4.4, :l1_available=>155.46, :l2=>4.6, :l2_available=>230.69, :l3=>5.9, :l3_available=>100.3
|
@@ -375,6 +375,7 @@ trying to set a threshold on when to place a bet.
|
|
375
375
|
* rake
|
376
376
|
|
377
377
|
## To Do ##
|
378
|
+
* Work out how to implement this https://github.com/jfairbairn/em-net-http, so that the libary uses eventmachine no blocking
|
378
379
|
* The WOM of money in Helpers#price_string returns 0 if either all b1,b2,b3 or l1,l2,l3 are all 0
|
379
380
|
* Add some error checking to the Betfair::Helper methods
|
380
381
|
* Finish of the mash method, to return a nice hash of all market and runner info
|
@@ -33,7 +33,7 @@ class SimpleBot
|
|
33
33
|
ODDS = 2.0 # Bet on odds below this
|
34
34
|
BET_SIDE = 'L' # What type of bet, B for back and L for Lay
|
35
35
|
BET_AMOUNT = 2.0 # Note this needs to be a minimum of $5 if you have an AUS account
|
36
|
-
BET_PIP =
|
36
|
+
BET_PIP = 1 # Place bet one pip above the ODDS I am checking for, ie this will try and lay 2.0 pounds on odds of 2.01
|
37
37
|
|
38
38
|
BF = Betfair::API.new # Initialize BF API methods
|
39
39
|
HELPERS = Betfair::Helpers.new # Initialize Helper API methods
|
@@ -153,7 +153,9 @@ class SimpleBot
|
|
153
153
|
begin
|
154
154
|
foo = []
|
155
155
|
bets.each do |bet|
|
156
|
-
|
156
|
+
price = @helpers.set_betfair_odds(bet[:b1], BET_PIP, false, false)[:prc]
|
157
|
+
|
158
|
+
foo << { market_id: market_id, runner_id: bet[:selection_id], bet_type: BET_SIDE, price: price, size: BET_AMOUNT, asian_line_id: 0,
|
157
159
|
bet_category_type: 'E', bet_peristence_type: 'NONE', bsp_liability: 0 }
|
158
160
|
end
|
159
161
|
bets = BF.place_multiple_bets(token, exchange_id, foo)
|
data/lib/betfair/api.rb
CHANGED
@@ -4,13 +4,8 @@ module Betfair
|
|
4
4
|
|
5
5
|
## Some handy constants...
|
6
6
|
|
7
|
-
EXCHANGE_IDS = {
|
8
|
-
:aus => 2,
|
9
|
-
:uk => 1
|
10
|
-
}
|
11
|
-
|
7
|
+
EXCHANGE_IDS = { aus: 2, uk: 1 }
|
12
8
|
PRODUCT_ID_FREE = 82
|
13
|
-
|
14
9
|
BET_TYPE_LAY = 'L'
|
15
10
|
BET_TYPE_BACK = 'B'
|
16
11
|
|
@@ -31,70 +26,70 @@ module Betfair
|
|
31
26
|
## Bet Placement API METHODS
|
32
27
|
#
|
33
28
|
|
34
|
-
def place_bet(session_token, exchange_id, market_id, selection_id, bet_type, price, size)
|
35
|
-
bf_bet = {
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
29
|
+
def place_bet(session_token, exchange_id, market_id, selection_id, bet_type, price, size)
|
30
|
+
bf_bet = {
|
31
|
+
marketId: market_id,
|
32
|
+
selectionId: selection_id,
|
33
|
+
betType: bet_type,
|
34
|
+
price: price,
|
35
|
+
size: size,
|
36
|
+
asianLineId: 0,
|
37
|
+
betCategoryType: 'E',
|
38
|
+
betPersistenceType: 'NONE',
|
39
|
+
bspLiability: 0
|
45
40
|
}
|
46
41
|
|
47
42
|
response = exchange(exchange_id).
|
48
43
|
session_request( session_token,
|
49
|
-
:placeBets,
|
44
|
+
:placeBets,
|
50
45
|
:place_bets_response,
|
51
|
-
:
|
46
|
+
bets: { 'PlaceBets' => [bf_bet] } )
|
52
47
|
|
53
48
|
return response.maybe_result( :bet_results, :place_bets_result )
|
54
49
|
end
|
55
50
|
|
56
51
|
|
57
|
-
def place_multiple_bets(session_token, exchange_id, bets)
|
52
|
+
def place_multiple_bets(session_token, exchange_id, bets)
|
58
53
|
bf_bets = []
|
59
54
|
bets.each do |bet|
|
60
|
-
bf_bets << {
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
55
|
+
bf_bets << {
|
56
|
+
marketId: bet[:market_id],
|
57
|
+
selectionId: bet[:runner_id],
|
58
|
+
betType: bet[:bet_type],
|
59
|
+
price: bet[:price],
|
60
|
+
size: bet[:size],
|
61
|
+
asianLineId: bet[:asian_line_id],
|
62
|
+
betCategoryType: bet[:bet_category_type],
|
63
|
+
betPersistenceType: bet[:bet_peristence_type],
|
64
|
+
bspLiability: bet[:bsp_liability]
|
70
65
|
}
|
71
66
|
end
|
72
67
|
|
73
68
|
response = exchange(exchange_id).
|
74
69
|
session_request( session_token,
|
75
|
-
:placeBets,
|
70
|
+
:placeBets,
|
76
71
|
:place_bets_response,
|
77
|
-
:
|
72
|
+
bets: { 'PlaceBets' => bf_bets } )
|
78
73
|
|
79
74
|
return response.maybe_result( :bet_results, :place_bets_result )
|
80
75
|
end
|
81
76
|
|
82
77
|
def update_bet(session_token, exchange_id, bet_id, new_bet_persitence_type, new_price, new_size, old_bet_persitance_type, old_price, old_size)
|
83
|
-
bf_bet = {
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
78
|
+
bf_bet = {
|
79
|
+
betId: bet_id,
|
80
|
+
newBetPersistenceType: new_bet_persitence_type,
|
81
|
+
newPrice: new_price,
|
82
|
+
newSize: new_size,
|
83
|
+
oldBetPersistenceType: old_bet_persitance_type,
|
84
|
+
oldPrice: old_price,
|
85
|
+
oldSize: old_size
|
91
86
|
}
|
92
87
|
|
93
88
|
response = exchange(exchange_id).
|
94
89
|
session_request( session_token,
|
95
|
-
:updateBets,
|
90
|
+
:updateBets,
|
96
91
|
:update_bets_response,
|
97
|
-
:
|
92
|
+
bets: { 'UpdateBets' => [bf_bet] } )
|
98
93
|
|
99
94
|
return response.maybe_result( :bet_results, :update_bets_result )
|
100
95
|
end
|
@@ -102,47 +97,47 @@ module Betfair
|
|
102
97
|
def update_multiple_bets(session_token, exchange_id, bets)
|
103
98
|
bf_bets = []
|
104
99
|
bets.each do |bet|
|
105
|
-
bf_bets << {
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
112
|
-
:
|
100
|
+
bf_bets << {
|
101
|
+
betId: bet[:bet_id],
|
102
|
+
newBetPersistenceType: bet[:new_bet_persitence_type],
|
103
|
+
newPrice: bet[:new_price],
|
104
|
+
newSize: bet[:new_size],
|
105
|
+
oldBetPersistenceType: bet[:old_bet_persitance_type],
|
106
|
+
oldPrice: bet[:old_price],
|
107
|
+
oldSize: bet[:old_size]
|
113
108
|
}
|
114
109
|
end
|
115
110
|
|
116
111
|
response = exchange(exchange_id).
|
117
112
|
session_request( session_token,
|
118
|
-
:updateBets,
|
113
|
+
:updateBets,
|
119
114
|
:update_bets_response,
|
120
|
-
:
|
115
|
+
bets: { 'UpdateBets' => bf_bets } )
|
121
116
|
|
122
|
-
return response.maybe_result( :bet_results, :update_bets_result )
|
117
|
+
return response.maybe_result( :bet_results, :update_bets_result )
|
123
118
|
end
|
124
119
|
|
125
120
|
def cancel_bet(session_token, exchange_id, bet_id)
|
126
|
-
bf_bet = { :
|
121
|
+
bf_bet = { betId: bet_id }
|
127
122
|
|
128
123
|
response = exchange(exchange_id).
|
129
124
|
session_request( session_token,
|
130
|
-
:cancelBets,
|
125
|
+
:cancelBets,
|
131
126
|
:cancel_bets_response,
|
132
|
-
:
|
127
|
+
bets: { 'CancelBets' => [bf_bet] } ) # "CancelBets" has to be a string, not a symbol!
|
133
128
|
|
134
129
|
return response.maybe_result( :bet_results, :cancel_bets_result )
|
135
130
|
end
|
136
131
|
|
137
132
|
def cancel_multiple_bets(session_token, exchange_id, bets)
|
138
133
|
bf_bets = []
|
139
|
-
bets.each { |bet_id| bf_bets << { :
|
134
|
+
bets.each { |bet_id| bf_bets << { betId: bet_id } }
|
140
135
|
|
141
136
|
response = exchange(exchange_id).
|
142
137
|
session_request( session_token,
|
143
|
-
:cancelBets,
|
138
|
+
:cancelBets,
|
144
139
|
:cancel_bets_response,
|
145
|
-
:
|
140
|
+
bets: { 'CancelBets' => bf_bets } ) # "CancelBets" has to be a string, not a symbol!
|
146
141
|
|
147
142
|
return response.maybe_result( :bet_results, :cancel_bets_result )
|
148
143
|
end
|
@@ -156,31 +151,31 @@ module Betfair
|
|
156
151
|
|
157
152
|
def get_mu_bets( session_token, exchange_id, market_id = 0, bet_status = 'MU', start_record = 0, record_count = 200, sort_order = 'ASC', order_by = 'PLACED_DATE') #, bet_ids = nil, , exclude_last_second = nil, matched_since = nil
|
158
153
|
response = exchange(exchange_id).
|
159
|
-
session_request( session_token,
|
160
|
-
:getMUBets,
|
154
|
+
session_request( session_token,
|
155
|
+
:getMUBets,
|
161
156
|
:get_mu_bets_response,
|
162
|
-
|
163
|
-
:
|
164
|
-
|
165
|
-
:
|
166
|
-
|
167
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
157
|
+
#betIds: bet_ids,
|
158
|
+
betStatus: bet_status,
|
159
|
+
#excludeLastSecond: exclude_last_second,
|
160
|
+
marketId: market_id,
|
161
|
+
#matchedSince: matched_since,
|
162
|
+
orderBy: order_by,
|
163
|
+
recordCount: record_count,
|
164
|
+
sortOrder: sort_order,
|
165
|
+
startRecord: start_record
|
171
166
|
)
|
172
167
|
|
173
168
|
return response.maybe_result( :bets, :mu_bet )
|
174
169
|
end
|
175
170
|
|
176
171
|
|
177
|
-
def get_market(session_token, exchange_id, market_id, locale = nil)
|
172
|
+
def get_market(session_token, exchange_id, market_id, locale = nil)
|
178
173
|
response = exchange(exchange_id).
|
179
|
-
session_request( session_token,
|
180
|
-
:getMarket,
|
174
|
+
session_request( session_token,
|
175
|
+
:getMarket,
|
181
176
|
:get_market_response,
|
182
|
-
:
|
183
|
-
:locale
|
177
|
+
marketId: market_id,
|
178
|
+
locale: locale )
|
184
179
|
|
185
180
|
return response.maybe_result( :market )
|
186
181
|
end
|
@@ -189,10 +184,10 @@ module Betfair
|
|
189
184
|
def get_market_prices_compressed(session_token, exchange_id, market_id, currency_code = nil)
|
190
185
|
response = exchange(exchange_id).
|
191
186
|
session_request( session_token,
|
192
|
-
:getMarketPricesCompressed,
|
187
|
+
:getMarketPricesCompressed,
|
193
188
|
:get_market_prices_compressed_response,
|
194
|
-
:
|
195
|
-
:
|
189
|
+
marketId: market_id,
|
190
|
+
currencyCode: currency_code )
|
196
191
|
|
197
192
|
return response.maybe_result( :market_prices )
|
198
193
|
end
|
@@ -201,9 +196,9 @@ module Betfair
|
|
201
196
|
def get_active_event_types(session_token, locale = nil)
|
202
197
|
response = @global_service.
|
203
198
|
session_request( session_token,
|
204
|
-
:getActiveEventTypes,
|
199
|
+
:getActiveEventTypes,
|
205
200
|
:get_active_event_types_response,
|
206
|
-
:
|
201
|
+
locale: locale )
|
207
202
|
|
208
203
|
return response.maybe_result( :event_type_items, :event_type )
|
209
204
|
end
|
@@ -211,14 +206,14 @@ module Betfair
|
|
211
206
|
|
212
207
|
def get_all_markets(session_token, exchange_id, event_type_ids = nil, locale = nil, countries = nil, from_date = nil, to_date = nil)
|
213
208
|
response = exchange(exchange_id).
|
214
|
-
session_request( session_token,
|
215
|
-
:getAllMarkets,
|
209
|
+
session_request( session_token,
|
210
|
+
:getAllMarkets,
|
216
211
|
:get_all_markets_response,
|
217
|
-
:
|
218
|
-
:
|
219
|
-
:
|
220
|
-
:
|
221
|
-
:
|
212
|
+
eventTypeIds: { 'int' => event_type_ids },
|
213
|
+
locale: locale,
|
214
|
+
countries: { 'Country' => countries },
|
215
|
+
fromDate: from_date,
|
216
|
+
toDate: to_date )
|
222
217
|
|
223
218
|
return response.maybe_result( :market_data )
|
224
219
|
end
|
@@ -226,22 +221,22 @@ module Betfair
|
|
226
221
|
|
227
222
|
def get_account_funds( session_token, exchange_id )
|
228
223
|
response = exchange(exchange_id).
|
229
|
-
session_request( session_token,
|
230
|
-
:getAccountFunds,
|
224
|
+
session_request( session_token,
|
225
|
+
:getAccountFunds,
|
231
226
|
:get_account_funds_response )
|
232
227
|
|
233
228
|
return response.maybe_result
|
234
229
|
end
|
235
230
|
|
236
231
|
def login(username, password, product_id, vendor_software_id, location_id, ip_address)
|
237
|
-
response = @global_service.request( :login,
|
238
|
-
:login_response,
|
239
|
-
:
|
240
|
-
:
|
241
|
-
:
|
242
|
-
:
|
243
|
-
:
|
244
|
-
:
|
232
|
+
response = @global_service.request( :login,
|
233
|
+
:login_response,
|
234
|
+
username: username,
|
235
|
+
password: password,
|
236
|
+
productId: product_id,
|
237
|
+
vendorSoftwareId: vendor_software_id,
|
238
|
+
locationId: location_id,
|
239
|
+
ipAddress: ip_address )
|
245
240
|
|
246
241
|
return response.maybe_result( :header, :session_token )
|
247
242
|
end
|
@@ -252,11 +247,11 @@ module Betfair
|
|
252
247
|
def keep_alive(session_token)
|
253
248
|
response = @global_service.
|
254
249
|
session_request( session_token,
|
255
|
-
:keep_alive,
|
250
|
+
:keep_alive,
|
256
251
|
:keep_alive_response )
|
257
252
|
|
258
253
|
# Need to do the old school way of checking as the keep_alive response doesn't return a minorErrorCode, so fails
|
259
|
-
error_code = response[:header][:error_code]
|
254
|
+
error_code = response[:header][:error_code]
|
260
255
|
#return error_code == 'OK' ? response[:header][:session_token] : error_code
|
261
256
|
return error_code == 'OK' ? response[:header][:session_token].extend( Success ) : error_code.extend( Failure )
|
262
257
|
end
|
@@ -264,7 +259,7 @@ module Betfair
|
|
264
259
|
def logout(session_token)
|
265
260
|
response = @global_service.
|
266
261
|
session_request( session_token,
|
267
|
-
:logout,
|
262
|
+
:logout,
|
268
263
|
:logout_response )
|
269
264
|
return response.maybe_result( :header, :session_token )
|
270
265
|
end
|
@@ -273,11 +268,11 @@ module Betfair
|
|
273
268
|
## END OF API METHODS
|
274
269
|
|
275
270
|
|
276
|
-
def exchange(exchange_id)
|
271
|
+
def exchange(exchange_id)
|
277
272
|
exchange_id == EXCHANGE_IDS[:aus] ? @aus_service : @uk_service
|
278
273
|
end
|
279
274
|
|
280
|
-
def session_token(response_header)
|
275
|
+
def session_token(response_header)
|
281
276
|
response_header[:error_code] == 'OK' ? response_header[:session_token] : response_header[:error_code]
|
282
277
|
end
|
283
278
|
|
@@ -302,13 +297,13 @@ module Betfair
|
|
302
297
|
|
303
298
|
# Handy constants
|
304
299
|
NAMESPACES = {
|
305
|
-
:
|
306
|
-
:
|
307
|
-
:
|
300
|
+
aus: 'http://www.betfair.com/exchange/v3/BFExchangeService/AUS',
|
301
|
+
global: 'https://www.betfair.com/global/v3/BFGlobalService',
|
302
|
+
uk: 'http://www.betfair.com/exchange/v3/BFExchangeService/UK' }
|
308
303
|
ENDPOINTS = {
|
309
|
-
:
|
310
|
-
:
|
311
|
-
:
|
304
|
+
aus: 'https://api-au.betfair.com/exchange/v5/BFExchangeService',
|
305
|
+
global: 'https://api.betfair.com/global/v3/BFGlobalService',
|
306
|
+
uk: 'https://api.betfair.com/exchange/v5/BFExchangeService' }
|
312
307
|
|
313
308
|
|
314
309
|
# Factory methods for building clients to the different endpoints
|
@@ -350,15 +345,15 @@ module Betfair
|
|
350
345
|
# For those requests which take place in the context of a session,
|
351
346
|
# this method constructs the correct header and delegates to #request.
|
352
347
|
def session_request( session_token, method, result_field, body = {})
|
353
|
-
header_body = { :
|
348
|
+
header_body = { header: api_request_header(session_token) }
|
354
349
|
full_body = header_body.merge( body )
|
355
350
|
|
356
351
|
request method, result_field, full_body
|
357
352
|
end
|
358
353
|
|
359
354
|
|
360
|
-
def api_request_header(session_token)
|
361
|
-
{ :
|
355
|
+
def api_request_header(session_token)
|
356
|
+
{ client_stamp: 0, session_token: session_token }
|
362
357
|
end
|
363
358
|
protected :api_request_header
|
364
359
|
|
@@ -371,7 +366,7 @@ module Betfair
|
|
371
366
|
module ErrorPresenter
|
372
367
|
|
373
368
|
def success?
|
374
|
-
self[:error_code] ==
|
369
|
+
self[:error_code] == 'OK'
|
375
370
|
end
|
376
371
|
|
377
372
|
|
@@ -408,26 +403,26 @@ module Betfair
|
|
408
403
|
markets.each do |piece|
|
409
404
|
piece.gsub! "\0", '\:'
|
410
405
|
foo = piece.split('~')
|
411
|
-
market_hash[foo[0].to_i] = {
|
412
|
-
:
|
413
|
-
:
|
414
|
-
:
|
415
|
-
:
|
406
|
+
market_hash[foo[0].to_i] = {
|
407
|
+
market_id: foo[0].to_i,
|
408
|
+
market_name: foo[1].to_s,
|
409
|
+
market_type: foo[2].to_s,
|
410
|
+
market_status: foo[3].to_s,
|
411
|
+
# bf returns in this case time in Epoch, but in milliseconds
|
412
|
+
event_date: Time.at(foo[4].to_i/1000),
|
413
|
+
menu_path: foo[5].to_s,
|
414
|
+
event_hierarchy: foo[6].to_s,
|
415
|
+
bet_delay: foo[7].to_s,
|
416
|
+
exchange_id: foo[8].to_i,
|
417
|
+
iso3_country_code: foo[9].to_s,
|
416
418
|
# bf returns in this case time in Epoch, but in milliseconds
|
417
|
-
:
|
418
|
-
:
|
419
|
-
:
|
420
|
-
:
|
421
|
-
:
|
422
|
-
:
|
423
|
-
|
424
|
-
:last_refresh => Time.at(foo[10].to_i/1000),
|
425
|
-
:number_of_runners => foo[11].to_i,
|
426
|
-
:number_of_winners => foo[12].to_i,
|
427
|
-
:total_amount_matched => foo[13].to_f,
|
428
|
-
:bsp_market => foo[14] == 'Y' ? true : false,
|
429
|
-
:turning_in_play => foo[15] == 'Y' ? true : false
|
430
|
-
}
|
419
|
+
last_refresh: Time.at(foo[10].to_i/1000),
|
420
|
+
number_of_runners: foo[11].to_i,
|
421
|
+
number_of_winners: foo[12].to_i,
|
422
|
+
total_amount_matched: foo[13].to_f,
|
423
|
+
bsp_market: foo[14] == 'Y' ? true : false,
|
424
|
+
turning_in_play: foo[15] == 'Y' ? true : false
|
425
|
+
}
|
431
426
|
end
|
432
427
|
return market_hash
|
433
428
|
end
|
@@ -446,9 +441,25 @@ module Betfair
|
|
446
441
|
event_date = Time.at(bar[4].to_i/1000).utc
|
447
442
|
last_refresh = Time.at(bar[10].to_i/1000).utc
|
448
443
|
|
449
|
-
doh = {
|
450
|
-
|
451
|
-
|
444
|
+
doh = {
|
445
|
+
market_id: bar[0].to_i,
|
446
|
+
market_name: bar[1],
|
447
|
+
market_type: bar[2],
|
448
|
+
market_status: bar[3],
|
449
|
+
event_date: event_date,
|
450
|
+
menu_path: bar[5],
|
451
|
+
event_heirachy: bar[6],
|
452
|
+
bet_delay: bar[7].to_i,
|
453
|
+
exchange_id: bar[8].to_i,
|
454
|
+
iso3_country_code: bar[9],
|
455
|
+
last_refresh: last_refresh,
|
456
|
+
number_of_runners: bar[11].to_i,
|
457
|
+
number_of_winners: bar[12].to_i,
|
458
|
+
total_amount_matched: bar[13].to_f,
|
459
|
+
bsp_market: bsp_market,
|
460
|
+
turning_in_play: turning_in_play
|
461
|
+
}
|
462
|
+
|
452
463
|
foo << doh if !doh[:market_name].nil?
|
453
464
|
end
|
454
465
|
end
|
@@ -456,24 +467,24 @@ module Betfair
|
|
456
467
|
end
|
457
468
|
|
458
469
|
def market_info(details)
|
459
|
-
{ :
|
460
|
-
:
|
461
|
-
:
|
462
|
-
:
|
463
|
-
:
|
464
|
-
:
|
465
|
-
:
|
470
|
+
{ exchange_id: nil,
|
471
|
+
market_type_id: nil,
|
472
|
+
market_matched: nil,
|
473
|
+
menu_path: details[:menu_path],
|
474
|
+
market_id: details[:market_id],
|
475
|
+
market_name: details[:name],
|
476
|
+
market_type_name: details[:menu_path].to_s.split('\\')[1]
|
466
477
|
}
|
467
478
|
end
|
468
479
|
|
469
480
|
def details(market)
|
470
481
|
runners = []
|
471
|
-
market[:runners][:runner].each { |runner| runners << { :
|
472
|
-
return { :
|
482
|
+
market[:runners][:runner].each { |runner| runners << { runner_id: runner[:selection_id].to_i, runner_name: runner[:name] } }
|
483
|
+
return { market_id: market[:market_id].to_i, market_type_id: market[:event_type_id].to_i, runners: runners }
|
473
484
|
end
|
474
485
|
|
475
486
|
def prices(prices)
|
476
|
-
price_hash = {}
|
487
|
+
price_hash = {}
|
477
488
|
prices.gsub! '\:', "\0"
|
478
489
|
pieces = prices.split ":"
|
479
490
|
pieces.each do |piece|
|
@@ -484,11 +495,11 @@ module Betfair
|
|
484
495
|
end
|
485
496
|
|
486
497
|
def combine(market, prices)
|
487
|
-
market = details(market)
|
498
|
+
market = details(market)
|
488
499
|
prices = prices(prices)
|
489
500
|
market[:runners].each do |runner|
|
490
|
-
runner.merge!( { :
|
491
|
-
runner.merge!( { :
|
501
|
+
runner.merge!( { market_id: market[:market_id] } )
|
502
|
+
runner.merge!( { market_type_id: market[:market_type_id] } )
|
492
503
|
runner.merge!(price_string(prices[runner[:runner_id]]))
|
493
504
|
end
|
494
505
|
end
|
@@ -501,7 +512,7 @@ module Betfair
|
|
501
512
|
##
|
502
513
|
def prices_complete(prices)
|
503
514
|
aux_hash = {}
|
504
|
-
price_hash = {}
|
515
|
+
price_hash = {}
|
505
516
|
|
506
517
|
prices.gsub! '\:', "\0"
|
507
518
|
pieces = prices.split ":"
|
@@ -510,21 +521,21 @@ module Betfair
|
|
510
521
|
aux = pieces.first
|
511
522
|
aux.gsub! "\0", '\:'
|
512
523
|
foo = aux.split('~')
|
513
|
-
aux_hash = {
|
514
|
-
:
|
515
|
-
:
|
516
|
-
:
|
517
|
-
:
|
518
|
-
:
|
519
|
-
:
|
520
|
-
:
|
521
|
-
:
|
522
|
-
:
|
523
|
-
:
|
524
|
-
:
|
524
|
+
aux_hash = {
|
525
|
+
market_id: foo[0].to_i,
|
526
|
+
currency: foo[1].to_s,
|
527
|
+
market_status: foo[2].to_s,
|
528
|
+
in_play_delay: foo[3].to_i,
|
529
|
+
number_of_winners: foo[4].to_i,
|
530
|
+
market_information: foo[5].to_s,
|
531
|
+
discount_allowed: foo[6] == 'true' ? true : false,
|
532
|
+
market_base_rate: foo[7].to_s,
|
533
|
+
refresh_time_in_milliseconds: foo[8].to_i,
|
534
|
+
removed_runners: foo[9].to_s,
|
535
|
+
bsp_market: foo[10] == 'Y' ? true : false
|
525
536
|
}
|
526
537
|
|
527
|
-
# now iterating over the prices excluding the first piece that we already parsed above
|
538
|
+
# now iterating over the prices excluding the first piece that we already parsed above
|
528
539
|
pieces[1..-1].each do |piece|
|
529
540
|
piece.gsub! "\0", '\:'
|
530
541
|
|
@@ -532,17 +543,17 @@ module Betfair
|
|
532
543
|
# using the selection_id as hash key
|
533
544
|
price_hash_key = bar[0].to_i
|
534
545
|
|
535
|
-
price_hash[price_hash_key] = {
|
536
|
-
:
|
537
|
-
:
|
538
|
-
:
|
539
|
-
:
|
540
|
-
:
|
541
|
-
:
|
542
|
-
:
|
543
|
-
:
|
544
|
-
:
|
545
|
-
:
|
546
|
+
price_hash[price_hash_key] = {
|
547
|
+
selection_id: bar[0].to_i,
|
548
|
+
order_index: bar[1].to_i,
|
549
|
+
total_amount_matched: bar[2].to_f,
|
550
|
+
last_price_matched: bar[3].to_f,
|
551
|
+
handicap: bar[4].to_f,
|
552
|
+
reduction_factor: bar[5].to_f,
|
553
|
+
vacant: bar[6] == 'true' ? true : false,
|
554
|
+
far_sp_price: bar[7].to_f,
|
555
|
+
near_sp_price: bar[8].to_f,
|
556
|
+
actual_sp_price: bar[9].to_f
|
546
557
|
}
|
547
558
|
|
548
559
|
# merge lay and back prices into price_hash
|
@@ -558,13 +569,27 @@ module Betfair
|
|
558
569
|
string_raw = string
|
559
570
|
string = string.split('|')
|
560
571
|
|
561
|
-
price = {
|
562
|
-
:
|
563
|
-
:
|
572
|
+
price = {
|
573
|
+
prices_string: nil,
|
574
|
+
runner_matched: 0,
|
575
|
+
last_back_price: 0,
|
576
|
+
wom: 0,
|
577
|
+
b1: 0,
|
578
|
+
b1_available: 0,
|
579
|
+
b2: 0,
|
580
|
+
b2_available: 0,
|
581
|
+
b3: 0,
|
582
|
+
b3_available: 0,
|
583
|
+
l1: 0,
|
584
|
+
l1_available: 0,
|
585
|
+
l2: 0,
|
586
|
+
l2_available: 0,
|
587
|
+
l3: 0,
|
588
|
+
l3_available: 0
|
564
589
|
}
|
565
590
|
|
566
591
|
if !string[0].nil? and !prices_only
|
567
|
-
str = string[0].split('~')
|
592
|
+
str = string[0].split('~')
|
568
593
|
price[:prices_string] = string_raw
|
569
594
|
price[:runner_matched] = str[2].to_f
|
570
595
|
price[:last_back_price] = str[3].to_f
|
@@ -572,15 +597,15 @@ module Betfair
|
|
572
597
|
|
573
598
|
# Get the b prices (which are actually the l prices)
|
574
599
|
if !string[1].nil?
|
575
|
-
b = string[1].split('~')
|
600
|
+
b = string[1].split('~')
|
576
601
|
price[:b1] = b[0].to_f if !b[0].nil?
|
577
602
|
price[:b1_available] = b[1].to_f if !b[1].nil?
|
578
603
|
price[:b2] = b[4].to_f if !b[5].nil?
|
579
604
|
price[:b2_available] = b[5].to_f if !b[6].nil?
|
580
605
|
price[:b3] = b[8].to_f if !b[8].nil?
|
581
|
-
price[:b3_available] = b[9].to_f if !b[9].nil?
|
606
|
+
price[:b3_available] = b[9].to_f if !b[9].nil?
|
582
607
|
combined_b = price[:b1_available] + price[:b2_available] + price[:b3_available]
|
583
|
-
end
|
608
|
+
end
|
584
609
|
|
585
610
|
# Get the l prices (which are actually the l prices)
|
586
611
|
if !string[2].nil?
|
@@ -590,27 +615,27 @@ module Betfair
|
|
590
615
|
price[:l2] = l[4].to_f if !l[4].nil?
|
591
616
|
price[:l2_available] = l[5].to_f if !l[5].nil?
|
592
617
|
price[:l3] = l[8].to_f if !l[8].nil?
|
593
|
-
price[:l3_available] = l[9].to_f if !l[9].nil?
|
618
|
+
price[:l3_available] = l[9].to_f if !l[9].nil?
|
594
619
|
combined_l = price[:l1_available] + price[:l2_available] + price[:l3_available]
|
595
620
|
end
|
596
621
|
|
597
622
|
price[:wom] = combined_b / ( combined_b + combined_l ) unless combined_b.nil? or combined_l.nil?
|
598
623
|
|
599
|
-
return price
|
624
|
+
return price
|
600
625
|
end
|
601
626
|
|
602
627
|
def odds_table
|
603
628
|
odds_table = []
|
604
|
-
(1.01..1.99).step(0.01).each
|
605
|
-
(2..2.98).step(0.02).each
|
606
|
-
(3..3.95).step(0.05).each
|
607
|
-
(4..5.9).step(0.1).each
|
608
|
-
(6..9.8).step(0.2).each
|
609
|
-
(10..19.5).step(0.5).each
|
610
|
-
(20..29).step(1).each
|
611
|
-
(30..48).step(2).each
|
612
|
-
(50..95).step(5).each
|
613
|
-
(100..1000).step(10).each
|
629
|
+
(1.01..1.99).step(0.01).each { |i| odds_table << i.round(2) }
|
630
|
+
(2..2.98).step(0.02).each { |i| odds_table << i.round(2) }
|
631
|
+
(3..3.95).step(0.05).each { |i| odds_table << i.round(2) }
|
632
|
+
(4..5.9).step(0.1).each { |i| odds_table << i.round(2) }
|
633
|
+
(6..9.8).step(0.2).each { |i| odds_table << i.round(2) }
|
634
|
+
(10..19.5).step(0.5).each { |i| odds_table << i.round(2) }
|
635
|
+
(20..29).step(1).each { |i| odds_table << i.round }
|
636
|
+
(30..48).step(2).each { |i| odds_table << i.round }
|
637
|
+
(50..95).step(5).each { |i| odds_table << i.round }
|
638
|
+
(100..1000).step(10).each { |i| odds_table << i.round }
|
614
639
|
return odds_table
|
615
640
|
end
|
616
641
|
|
@@ -635,15 +660,15 @@ module Betfair
|
|
635
660
|
end
|
636
661
|
|
637
662
|
if round_up == true
|
638
|
-
prc = ( (prc / increment).ceil * increment ).round(2)
|
663
|
+
prc = ( (prc / increment).ceil * increment ).round(2)
|
639
664
|
elsif round_down == true
|
640
|
-
prc = ( (prc / increment).floor * increment ).round(2)
|
665
|
+
prc = ( (prc / increment).floor * increment ).round(2)
|
641
666
|
else
|
642
|
-
prc = ( (prc / increment).round * increment ).round(2)
|
667
|
+
prc = ( (prc / increment).round * increment ).round(2)
|
643
668
|
end
|
644
669
|
|
645
670
|
ot = odds_table # Set up the odds table
|
646
|
-
unless pips == 0 and odds_table.count > 0 # If pips is 0
|
671
|
+
unless pips == 0 and odds_table.count > 0 # If pips is 0
|
647
672
|
index = ot.index(prc) + pips
|
648
673
|
index = 0 if index < 0
|
649
674
|
index = 349 if index > 349
|
@@ -654,7 +679,7 @@ module Betfair
|
|
654
679
|
|
655
680
|
end
|
656
681
|
|
657
|
-
def get_odds_spread(back_odds = 0, lay_odds = 0)
|
682
|
+
def get_odds_spread(back_odds = 0, lay_odds = 0)
|
658
683
|
back_odds = set_betfair_odds(back_odds)
|
659
684
|
lay_odds = set_betfair_odds(lay_odds)
|
660
685
|
diff = lay_odds[:prc] - back_odds[:prc]
|
data/lib/betfair/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betfair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-10 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
16
|
-
requirement: &
|
16
|
+
requirement: &70101392500940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70101392500940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70101392500220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70101392500220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70101392499420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70101392499420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: savon_spec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70101392498480 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70101392498480
|
58
58
|
description: Gem for accessing the Betfair API.
|
59
59
|
email:
|
60
60
|
- lukeb@lukebyrne.com
|
@@ -75,7 +75,6 @@ files:
|
|
75
75
|
- examples/simplebot/README.md
|
76
76
|
- examples/simplebot/daemonize.rb
|
77
77
|
- examples/simplebot/monit.conf
|
78
|
-
- examples/simplebot/simplebot.log
|
79
78
|
- examples/simplebot/simplebot.rb
|
80
79
|
- lib/betfair.rb
|
81
80
|
- lib/betfair/api.rb
|
@@ -121,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
120
|
version: '0'
|
122
121
|
segments:
|
123
122
|
- 0
|
124
|
-
hash:
|
123
|
+
hash: 3477477127880861030
|
125
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
125
|
none: false
|
127
126
|
requirements:
|
@@ -130,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
129
|
version: '0'
|
131
130
|
segments:
|
132
131
|
- 0
|
133
|
-
hash:
|
132
|
+
hash: 3477477127880861030
|
134
133
|
requirements: []
|
135
134
|
rubyforge_project: betfair
|
136
135
|
rubygems_version: 1.8.10
|
File without changes
|