betfair 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +29 -0
- data/lib/betfair/api.rb +61 -0
- data/lib/betfair/version.rb +1 -1
- data/spec/betfair/api_spec.rb +53 -7
- metadata +12 -12
data/README.md
CHANGED
@@ -332,6 +332,35 @@ foo.first returns
|
|
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
|
334
334
|
}
|
335
|
+
|
336
|
+
|
337
|
+
## Set Betfair Odds ##
|
338
|
+
Method for dealing with calculating the Betfair increments from a price passed in.
|
339
|
+
|
340
|
+
set_betfair_odds(price, pips = 0, round_up = false, round_down = false)
|
341
|
+
|
342
|
+
helpers.set_betfair_odds(2.31, 1, false, false)
|
343
|
+
|
344
|
+
{ :price=>2.31, :prc=>2.34, :pips=>1, :increment=>0.02 }
|
345
|
+
|
346
|
+
helpers.set_betfair_odds(2.31, 1, false, true)
|
347
|
+
|
348
|
+
{ :price=>2.31, :prc=>2.32, :pips=>1, :increment=>0.02 }
|
349
|
+
|
350
|
+
helpers.set_betfair_odds(2.31, 1, false, true)
|
351
|
+
|
352
|
+
{ :price=>2.31, :prc=>2.32, :pips=>1, :increment=>0.02 }
|
353
|
+
|
354
|
+
helpers.set_betfair_odds(132, 0, false, true)
|
355
|
+
|
356
|
+
{ :price=>132.0, :prc=>130.0, :pips=>0, :increment=>10 }
|
357
|
+
|
358
|
+
## Get Odds Spead ##
|
359
|
+
|
360
|
+
Work out the distance between a high and low spread. Useful for when the B1 and L1 are miles apart and you are
|
361
|
+
trying to set a threshold on when to place a bet.
|
362
|
+
|
363
|
+
helpers.get_odds_spread(1.28, 3.43)
|
335
364
|
|
336
365
|
# Extra
|
337
366
|
## API Limits ##
|
data/lib/betfair/api.rb
CHANGED
@@ -599,6 +599,67 @@ module Betfair
|
|
599
599
|
return price
|
600
600
|
end
|
601
601
|
|
602
|
+
def odds_table
|
603
|
+
odds_table = []
|
604
|
+
(1.01..1.99).step(0.01).each { |i| odds_table << i.round(2) }
|
605
|
+
(2..2.98).step(0.02).each { |i| odds_table << i.round(2) }
|
606
|
+
(3..3.95).step(0.05).each { |i| odds_table << i.round(2) }
|
607
|
+
(4..5.9).step(0.1).each {|i| odds_table << i.round(2) }
|
608
|
+
(6..9.8).step(0.2).each {|i| odds_table << i.round(2) }
|
609
|
+
(10..19.5).step(0.5).each {|i| odds_table << i.round(2) }
|
610
|
+
(20..29).step(1).each {|i| odds_table << i.round }
|
611
|
+
(30..48).step(2).each {|i| odds_table << i.round }
|
612
|
+
(50..95).step(5).each {|i| odds_table << i.round }
|
613
|
+
(100..1000).step(10).each {|i| odds_table << i.round }
|
614
|
+
return odds_table
|
615
|
+
end
|
616
|
+
|
617
|
+
def set_betfair_odds(price, pips = 0, round_up = false, round_down = false)
|
618
|
+
price = price.to_f
|
619
|
+
prc = price
|
620
|
+
case price
|
621
|
+
when 0..1 then prc = increment = 1.01
|
622
|
+
when 1.01..1.99 then increment = 0.01
|
623
|
+
when 2..2.98 then increment = 0.02
|
624
|
+
when 3..3.95 then increment = 0.05
|
625
|
+
when 4..5.9 then increment = 0.1
|
626
|
+
when 6..9.8 then increment = 0.2
|
627
|
+
when 10..19.5 then increment = 0.5
|
628
|
+
when 20..29 then increment = 1
|
629
|
+
when 30..48 then increment = 2
|
630
|
+
when 50..95 then increment = 5
|
631
|
+
when 100..1000 then increment = 10
|
632
|
+
else
|
633
|
+
price = 1000
|
634
|
+
increment = 1000
|
635
|
+
end
|
636
|
+
|
637
|
+
if round_up == true
|
638
|
+
prc = ( (prc / increment).ceil * increment ).round(2)
|
639
|
+
elsif round_down == true
|
640
|
+
prc = ( (prc / increment).floor * increment ).round(2)
|
641
|
+
else
|
642
|
+
prc = ( (prc / increment).round * increment ).round(2)
|
643
|
+
end
|
644
|
+
|
645
|
+
ot = odds_table # Set up the odds table
|
646
|
+
unless pips == 0 and odds_table.count > 0 # If pips is 0
|
647
|
+
index = ot.index(prc) + pips
|
648
|
+
index = 0 if index < 0
|
649
|
+
index = 349 if index > 349
|
650
|
+
prc = ot[index] # Grab x number of pips above
|
651
|
+
end
|
652
|
+
|
653
|
+
{ price: price, prc: prc, pips: pips, increment: increment }
|
654
|
+
|
655
|
+
end
|
656
|
+
|
657
|
+
def get_odds_spread(back_odds = 0, lay_odds = 0)
|
658
|
+
back_odds = set_betfair_odds(back_odds)
|
659
|
+
lay_odds = set_betfair_odds(lay_odds)
|
660
|
+
diff = lay_odds[:prc] - back_odds[:prc]
|
661
|
+
end
|
662
|
+
|
602
663
|
end
|
603
664
|
|
604
665
|
end
|
data/lib/betfair/version.rb
CHANGED
data/spec/betfair/api_spec.rb
CHANGED
@@ -11,7 +11,7 @@ module Betfair
|
|
11
11
|
@helpers = Betfair::Helpers.new
|
12
12
|
end
|
13
13
|
|
14
|
-
describe "
|
14
|
+
describe "create a hash from the get_all_markets API call" do
|
15
15
|
it "pulls the relevant stuff out of get_all_markets and puts it in a hash" do
|
16
16
|
savon.expects(:get_all_markets).returns(:success)
|
17
17
|
markets = @bf.get_all_markets(@session_token, 2)
|
@@ -20,7 +20,7 @@ module Betfair
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe "
|
23
|
+
describe "create a hash for the market details" do
|
24
24
|
it "pulls the relevant stuff out of market details and puts it in a hash" do
|
25
25
|
savon.expects(:get_market).returns(:success)
|
26
26
|
market = @bf.get_market(@session_token, 2, 10038633)
|
@@ -29,7 +29,7 @@ module Betfair
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe "
|
32
|
+
describe "cleans up the get market details" do
|
33
33
|
it "sort the runners for each market out " do
|
34
34
|
savon.expects(:get_market).returns(:success)
|
35
35
|
market = @bf.get_market(@session_token, 2, 10038633)
|
@@ -38,7 +38,7 @@ module Betfair
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe "
|
41
|
+
describe "get the price string for a runner" do
|
42
42
|
it "so that we can combine it together with market info" do
|
43
43
|
savon.expects(:get_market_prices_compressed).returns(:success)
|
44
44
|
prices = @bf.get_market_prices_compressed(@session_token, 2, 10038633)
|
@@ -47,8 +47,8 @@ module Betfair
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe "
|
51
|
-
it "
|
50
|
+
describe "combine market details and runner prices api call" do
|
51
|
+
it "combines the two api calls of get_market and get_market_prices_compressed " do
|
52
52
|
|
53
53
|
savon.expects(:get_market).returns(:success)
|
54
54
|
market = @bf.get_market(@session_token, 2, 10038633)
|
@@ -60,7 +60,53 @@ module Betfair
|
|
60
60
|
combined.should_not be_nil
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
|
+
describe "set up an odds tables of all possible Betfair Odds" do
|
65
|
+
it "should return a hash of all possible Betfair odds with correct increments" do
|
66
|
+
odds_table = @helpers.odds_table
|
67
|
+
odds_table.should_not be_nil
|
68
|
+
odds_table.should be_an_instance_of(Array)
|
69
|
+
odds_table.count.should eq(350)
|
70
|
+
odds_table[256].should eq(85)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return a standard hash" do
|
74
|
+
betfair_odds = @helpers.set_betfair_odds(275, 0, false, false)
|
75
|
+
betfair_odds.should be_an_instance_of(Hash)
|
76
|
+
betfair_odds[:price].should eq(275)
|
77
|
+
betfair_odds[:prc].should eq(280)
|
78
|
+
betfair_odds[:increment].should eq(10)
|
79
|
+
betfair_odds[:pips].should eq(0)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return a standard hash with prc at 1 pip and price rounded up" do
|
83
|
+
betfair_odds = @helpers.set_betfair_odds(2.31, 1, true, false)
|
84
|
+
betfair_odds.should be_an_instance_of(Hash)
|
85
|
+
betfair_odds[:price].should eq(2.31)
|
86
|
+
betfair_odds[:prc].should eq(2.34)
|
87
|
+
betfair_odds[:increment].should eq(0.02)
|
88
|
+
betfair_odds[:pips].should eq(1)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return a standard hash with prc at 2 pip and price rounded down" do
|
92
|
+
betfair_odds = @helpers.set_betfair_odds(2.31, 5, false, true)
|
93
|
+
betfair_odds.should be_an_instance_of(Hash)
|
94
|
+
betfair_odds[:price].should eq(2.31)
|
95
|
+
betfair_odds[:prc].should eq(2.4)
|
96
|
+
betfair_odds[:increment].should eq(0.02)
|
97
|
+
betfair_odds[:pips].should eq(5)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return an even spread off odds based on the odds_table method" do
|
101
|
+
spread = @helpers.get_odds_spread(271, 343)
|
102
|
+
spread.should eq(70.0)
|
103
|
+
spread = @helpers.get_odds_spread(1.28, 3.43)
|
104
|
+
spread.should eq(2.17)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
64
110
|
end
|
65
111
|
|
66
112
|
describe "Placing and cancelling bets - " do
|
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.2
|
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-04-
|
12
|
+
date: 2012-04-17 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
16
|
-
requirement: &
|
16
|
+
requirement: &70363472030920 !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: *70363472030920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70363472037000 !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: *70363472037000
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70363472064740 !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: *70363472064740
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: savon_spec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70363472247640 !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: *70363472247640
|
58
58
|
description: Gem for accessing the Betfair API.
|
59
59
|
email:
|
60
60
|
- lukeb@lukebyrne.com
|
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: -2850645110970383050
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
none: false
|
127
127
|
requirements:
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash:
|
133
|
+
hash: -2850645110970383050
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project: betfair
|
136
136
|
rubygems_version: 1.8.10
|