betfair 1.0.3 → 1.0.6

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.
@@ -1,3 +1,3 @@
1
1
  module Betfair
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.6'
3
3
  end
@@ -3,15 +3,17 @@ require 'spec_helper'
3
3
 
4
4
  module Betfair
5
5
 
6
+
6
7
  describe "Helper methods for mashing the data from the API - " do
7
8
 
9
+ include LoginHelper
10
+
8
11
  before(:all) do
9
- @bf = Betfair::API.new
10
- @session_token = @bf.login('username', 'password', 82, 0, 0, nil)
12
+ login()
11
13
  @helpers = Betfair::Helpers.new
12
14
  end
13
15
 
14
- describe "create a hash from the get_all_markets API call" do
16
+ describe "Create a hash from the get_all_markets API call" do
15
17
  it "pulls the relevant stuff out of get_all_markets and puts it in a hash" do
16
18
  savon.expects(:get_all_markets).returns(:success)
17
19
  markets = @bf.get_all_markets(@session_token, 2)
@@ -20,7 +22,7 @@ module Betfair
20
22
  end
21
23
  end
22
24
 
23
- describe "create a hash for the market details" do
25
+ describe "Create a hash for the market details" do
24
26
  it "pulls the relevant stuff out of market details and puts it in a hash" do
25
27
  savon.expects(:get_market).returns(:success)
26
28
  market = @bf.get_market(@session_token, 2, 10038633)
@@ -29,8 +31,8 @@ module Betfair
29
31
  end
30
32
  end
31
33
 
32
- describe "cleans up the get market details" do
33
- it "sort the runners for each market out " do
34
+ describe "Cleans up the get market details" do
35
+ it "sort the selections for each market out " do
34
36
  savon.expects(:get_market).returns(:success)
35
37
  market = @bf.get_market(@session_token, 2, 10038633)
36
38
  details = @helpers.details(market)
@@ -38,7 +40,7 @@ module Betfair
38
40
  end
39
41
  end
40
42
 
41
- describe "get the price string for a runner" do
43
+ describe "Get the price string for a selection" do
42
44
  it "so that we can combine it together with market info" do
43
45
  savon.expects(:get_market_prices_compressed).returns(:success)
44
46
  prices = @bf.get_market_prices_compressed(@session_token, 2, 10038633)
@@ -47,8 +49,8 @@ module Betfair
47
49
  end
48
50
  end
49
51
 
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
+ describe "Combine market details and selection prices api call" do
53
+ it "Combines the two api calls of get_market and get_market_prices_compressed " do
52
54
 
53
55
  savon.expects(:get_market).returns(:success)
54
56
  market = @bf.get_market(@session_token, 2, 10038633)
@@ -60,60 +62,60 @@ module Betfair
60
62
  combined.should_not be_nil
61
63
  end
62
64
  end
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
-
110
- end
111
65
 
66
+ describe "set up an odds tables of all possible Betfair Odds" do
67
+ it "should return a hash of all possible Betfair odds with correct increments" do
68
+ odds_table = @helpers.odds_table
69
+ odds_table.should_not be_nil
70
+ odds_table.should be_an_instance_of(Array)
71
+ odds_table.count.should eq(350)
72
+ odds_table[256].should eq(85)
73
+ end
74
+
75
+ it "should return a standard hash" do
76
+ betfair_odds = @helpers.set_betfair_odds(275, 0, false, false)
77
+ betfair_odds.should be_an_instance_of(Hash)
78
+ betfair_odds[:price].should eq(275)
79
+ betfair_odds[:prc].should eq(280)
80
+ betfair_odds[:increment].should eq(10)
81
+ betfair_odds[:pips].should eq(0)
82
+ end
83
+
84
+ it "should return a standard hash with prc at 1 pip and price rounded up" do
85
+ betfair_odds = @helpers.set_betfair_odds(2.31, 1, true, false)
86
+ betfair_odds.should be_an_instance_of(Hash)
87
+ betfair_odds[:price].should eq(2.31)
88
+ betfair_odds[:prc].should eq(2.34)
89
+ betfair_odds[:increment].should eq(0.02)
90
+ betfair_odds[:pips].should eq(1)
91
+ end
92
+
93
+ it "should return a standard hash with prc at 2 pip and price rounded down" do
94
+ betfair_odds = @helpers.set_betfair_odds(2.31, 5, false, true)
95
+ betfair_odds.should be_an_instance_of(Hash)
96
+ betfair_odds[:price].should eq(2.31)
97
+ betfair_odds[:prc].should eq(2.4)
98
+ betfair_odds[:increment].should eq(0.02)
99
+ betfair_odds[:pips].should eq(5)
100
+ end
101
+
102
+ it "should return an even spread of odds based on the odds_table method" do
103
+ spread = @helpers.get_odds_spread(271, 343)
104
+ spread.should eq(70.0)
105
+ spread = @helpers.get_odds_spread(1.28, 3.43)
106
+ spread.should eq(2.17)
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+
112
113
  describe "Placing and cancelling bets - " do
113
114
 
115
+ include LoginHelper
116
+
114
117
  before(:all) do
115
- @bf = Betfair::API.new
116
- @session_token = @bf.login('username', 'password', 82, 0, 0, nil)
118
+ login()
117
119
  end
118
120
 
119
121
  describe "place bet success" do
@@ -136,9 +138,9 @@ module Betfair
136
138
  it "should place mutliple bets on the exchange via the api" do
137
139
  savon.expects(:place_bets).returns(:success)
138
140
  bets = []
139
- bets << { market_id: 104184109, runner_id: 58805, bet_type: 'B', price: 2.0, size: 2.0, asian_line_id: 0,
141
+ bets << { market_id: 104184109, selection_id: 58805, bet_type: 'B', price: 2.0, size: 2.0, asian_line_id: 0,
140
142
  bet_category_type: 'E', bet_peristence_type: 'NONE', bsp_liability: 0 }
141
- bets << { market_id: 104184109, runner_id: 12234, bet_type: 'L', price: 1.5, size: 2.0, asian_line_id: 0,
143
+ bets << { market_id: 104184109, selection_id: 12234, bet_type: 'L', price: 1.5, size: 2.0, asian_line_id: 0,
142
144
  bet_category_type: 'E', bet_peristence_type: 'NONE', bsp_liability: 0 }
143
145
  bets = @bf.place_multiple_bets(@session_token, 1, bets)
144
146
  bets[:bet_id].should eq('16939643915')
@@ -149,9 +151,9 @@ module Betfair
149
151
  it "should return an error message" do
150
152
  savon.expects(:place_bets).returns(:fail)
151
153
  bets = []
152
- bets << { market_id: 104184109, runner_id: 58805, bet_type: 'B', price: 2.0, size: 2.0, asian_line_id: 0,
154
+ bets << { market_id: 104184109, selection_id: 58805, bet_type: 'B', price: 2.0, size: 2.0, asian_line_id: 0,
153
155
  bet_category_type: 'E', bet_peristence_type: 'NONE', bsp_liability: 0 }
154
- bets << { market_id: 104184109, runner_id: 12234, bet_type: 'L', price: 1.5, size: 2.0, asian_line_id: 0,
156
+ bets << { market_id: 104184109, selection_id: 12234, bet_type: 'L', price: 1.5, size: 2.0, asian_line_id: 0,
155
157
  bet_category_type: 'E', bet_peristence_type: 'NONE', bsp_liability: 0 }
156
158
  error_code = @bf.place_multiple_bets(@session_token, 1, bets)
157
159
  error_code[:result_code].should eq('INVALID_SIZE')
@@ -235,9 +237,11 @@ module Betfair
235
237
  end
236
238
 
237
239
  describe "Reading account details - " do
240
+
241
+ include LoginHelper
242
+
238
243
  before(:all) do
239
- @bf = Betfair::API.new
240
- @session_token = @bf.login('username', 'password', 82, 0, 0, nil)
244
+ login()
241
245
  end
242
246
 
243
247
  describe "reading wallet contents" do
@@ -251,9 +255,10 @@ module Betfair
251
255
 
252
256
  describe "Basic read methods from the API - " do
253
257
 
258
+ include LoginHelper
259
+
254
260
  before(:all) do
255
- @bf = Betfair::API.new
256
- @session_token = @bf.login('username', 'password', 82, 0, 0, nil)
261
+ login()
257
262
  end
258
263
 
259
264
  describe "get all markets success" do
@@ -351,6 +356,7 @@ module Betfair
351
356
  savon.expects(:keep_alive).returns(:success)
352
357
  session_token = @bf.keep_alive(@session_token)
353
358
  session_token.should eq('AXwtUFENz+/mWaatVtjUosug26+TYLYWiHPhRFRiabs=')
359
+ session_token.should be_success
354
360
  end
355
361
  end
356
362
 
@@ -359,6 +365,7 @@ module Betfair
359
365
  savon.expects(:keep_alive).returns(:fail)
360
366
  error_code = @bf.keep_alive(@session_token)
361
367
  error_code.should eq('NO_SESSION')
368
+ error_code.should_not be_success
362
369
  end
363
370
  end
364
371
 
@@ -458,4 +465,4 @@ module Betfair
458
465
 
459
466
  end
460
467
 
461
- end
468
+ end
@@ -8,5 +8,13 @@ RSpec.configure do |config|
8
8
  HTTPI.log = false
9
9
  Savon.log = false
10
10
  config.include Savon::Spec::Macros
11
- Savon::Spec::Fixture.path = File.expand_path("../fixtures", __FILE__)
11
+ Savon::Spec::Fixture.path = File.expand_path('../fixtures', __FILE__)
12
+ end
13
+
14
+ module LoginHelper
15
+ def login( response=:success )
16
+ @bf = Betfair::API.new
17
+ savon.expects(:login).returns( response )
18
+ @session_token = @bf.login('username', 'password', 82, 0, 0, nil)
19
+ end
12
20
  end
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.3
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-10 00:00:00.000000000Z
12
+ date: 2012-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
16
- requirement: &70101392500940 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - <=
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.8.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70101392500940
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - <=
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.6
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &70101392500220 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70101392500220
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &70101392499420 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,18 +53,44 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70101392499420
47
- - !ruby/object:Gem::Dependency
48
- name: savon_spec
49
- requirement: &70101392498480 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
50
57
  none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: savon_spec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.1.5
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.1.5
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.10.4
55
86
  type: :development
56
87
  prerelease: false
57
- version_requirements: *70101392498480
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.10.4
58
94
  description: Gem for accessing the Betfair API.
59
95
  email:
60
96
  - lukeb@lukebyrne.com
@@ -66,16 +102,9 @@ files:
66
102
  - API Ref Doc.pdf
67
103
  - Gemfile
68
104
  - README.md
69
- - README_OLD
70
105
  - Rakefile
71
106
  - betfair.gemspec
72
- - examples/bar.rb
73
- - examples/foo.rb
74
- - examples/simplebot.log
75
- - examples/simplebot/README.md
76
- - examples/simplebot/daemonize.rb
77
- - examples/simplebot/monit.conf
78
- - examples/simplebot/simplebot.rb
107
+ - examples/README.md
79
108
  - lib/betfair.rb
80
109
  - lib/betfair/api.rb
81
110
  - lib/betfair/version.rb
@@ -120,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
149
  version: '0'
121
150
  segments:
122
151
  - 0
123
- hash: 3477477127880861030
152
+ hash: 741636228280030738
124
153
  required_rubygems_version: !ruby/object:Gem::Requirement
125
154
  none: false
126
155
  requirements:
@@ -129,10 +158,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
158
  version: '0'
130
159
  segments:
131
160
  - 0
132
- hash: 3477477127880861030
161
+ hash: 741636228280030738
133
162
  requirements: []
134
163
  rubyforge_project: betfair
135
- rubygems_version: 1.8.10
164
+ rubygems_version: 1.8.24
136
165
  signing_key:
137
166
  specification_version: 3
138
167
  summary: Betfair API gem.
data/README_OLD DELETED
@@ -1,170 +0,0 @@
1
- BETFAIR API
2
- ===========
3
-
4
- ------------
5
- Installation
6
- ------------
7
-
8
- Betfair is available through
9
- [Rubygems](http://rubygems.org/gems/betfair) and can be installed via:
10
-
11
- gem install betfair
12
-
13
- OR with bundler: `gem 'betfair'` and `bundle install`
14
-
15
- ------------
16
- Introduction
17
- ------------
18
-
19
- irb
20
-
21
- require 'betfair'
22
-
23
- or from a Gemfile
24
-
25
- gem 'betfair'
26
-
27
- # create a client for the General API so that you can log in.
28
- bf = Betfair::API.new
29
-
30
- If you want to use a proxy or turn on Savon's logging then just pass
31
- in like so:
32
-
33
- # This is a local squid proxy I tunnel to from my local
34
- # machine to access the host server in UK for dev purposes.
35
- proxy = 'http://localhost:8888'
36
- logging = true
37
- bf = Betfair::API.new(proxy, logging)
38
-
39
- Proxies can be useful if you want to host on a cloud service such as
40
- Heroku, as you will be denied access to the Betfair API from the
41
- USA. Just proxy via a server from a country that Betfair allows, such
42
- as the UK.
43
-
44
- At the heart of the Betfair API is the `session_token`. In order to
45
- get one of these simply call:
46
-
47
- session_token = bf.login('username', 'password', 82, 0, 0, nil)
48
-
49
- Username and Password are fairly obvious. The `session_token` value
50
- you get back responds to #success? which will tell you whether login
51
- was successful or not. If `session_token.success?` returns false,
52
- `session_token.to_s` will give you the error message.
53
-
54
- 82 is the standard Product Id, you may have a different one depending
55
- on the level of Betfair API access that you have.
56
-
57
- You can ignore the rest and leave as is, but they refer to Vendor
58
- Software Id, Location Id, Ip Address as required by the Betfair API.
59
-
60
- -----
61
- Read
62
- -----
63
-
64
- markets =
65
- bf.get_all_markets(session_token, 1, [1,3], nil, nil, nil, nil)
66
-
67
- # We can either pull the market ID out of `markets`, or use a
68
- # stored value:
69
-
70
- market_id = 100386338
71
- exchange_id = 1 # or 2 for the Australian exchange
72
-
73
- # get_market returns a Hash with the details of the identified
74
- # market, including the commission as
75
- # `details[:market_base_rate]`, and information on the runners
76
- # (including their ids, which you need to place a bet) as
77
- # `details[:runners]`.
78
-
79
- details =
80
- bf.get_market(session_token, exchange_id, market_id)
81
-
82
- # This returns an encoded string with some back prices and depths
83
- # for the given market.
84
-
85
- prices = bf.get_market_prices_compressed(session_token,
86
- exchange_id,
87
- market_id)
88
-
89
- helpers = Betfair::Helpers.new
90
-
91
- helpers.market_info(details)
92
- helpers.combine(details, prices)
93
-
94
- # The get_all_markets api call returns all markets in one huge
95
- # string. This helper provides them all in handy hashes with
96
- # market id as key.
97
-
98
- helpers.all_markets(markets)
99
-
100
- ---
101
- Bet
102
- ---
103
-
104
- bf.place_bet(session_token, 1, 104184109, 58805, 'B', 10.0, 5.0)
105
- bf.cancel_bet(session_token, 1, 16939730542)
106
-
107
- ----------
108
- API Limits
109
- ----------
110
- http://bdp.betfair.com/index.php?option=com_content&task=view&id=36&Itemid=64
111
-
112
- ------------
113
- Requirements
114
- ------------
115
-
116
- savon
117
-
118
- ------------------------
119
- Requirements for testing
120
- ------------------------
121
-
122
- savon_spec
123
- rspec
124
- rake
125
-
126
- ----------
127
- To Do
128
- ----------
129
-
130
- - The WOM of money in Helpers#price_string returns 0 if either all b1,b2,b3 or l1,l2,l3 are all 0
131
- - Add some error checking to the Betfair::Helper methods
132
- - Finish of the mash method, to return a nice hash of all market and
133
- runner info
134
- - Write a spec for the mashed method
135
-
136
- ----------
137
- Contribute
138
- ----------
139
-
140
- I have only added the Betfair API method calls that I need.
141
-
142
- Feel free to fork this repo, add what you need to with the relevant
143
- RSpec tests and send me a pull request.
144
-
145
- -------
146
- License
147
- -------
148
-
149
- (The MIT License)
150
-
151
- Copyright (c) 2011 Luke Byrne
152
-
153
- Permission is hereby granted, free of charge, to any person obtaining
154
- a copy of this software and associated documentation files (the
155
- 'Software'), to deal in the Software without restriction, including
156
- without limitation the rights to use, copy, modify, merge, publish,
157
- distribute, sublicense, and/or sell copies of the Software, and to
158
- permit persons to whom the Software is furnished to do so, subject to
159
- the following conditions:
160
-
161
- The above copyright notice and this permission notice shall be
162
- included in all copies or substantial portions of the Software.
163
-
164
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
165
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
166
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
167
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
168
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
169
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
170
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.