betfair 0.0.14 → 0.0.16

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/.gitignore CHANGED
@@ -4,3 +4,5 @@ Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
6
  examples/bar.rb
7
+ examples/doh.rb
8
+ examples/doh.log
data/lib/betfair/api.rb CHANGED
@@ -2,7 +2,6 @@ module Betfair
2
2
 
3
3
  class API
4
4
 
5
-
6
5
  ## Some handy constants...
7
6
 
8
7
  EXCHANGE_IDS = {
@@ -19,10 +18,10 @@ module Betfair
19
18
  ## API METHODS
20
19
  #
21
20
 
22
- def place_bet(session_token, exchange_id, market_id, runner_id, bet_type, price, size)
21
+ def place_bet(session_token, exchange_id, market_id, selection_id, bet_type, price, size)
23
22
  bf_bet = {
24
23
  :marketId => market_id,
25
- :selectionId => runner_id,
24
+ :selectionId => selection_id,
26
25
  :betType => bet_type,
27
26
  :price => price,
28
27
  :size => size,
@@ -41,7 +40,33 @@ module Betfair
41
40
  return response.maybe_result( :bet_results, :place_bets_result )
42
41
  end
43
42
 
43
+
44
+ def place_multiple_bets(session_token, exchange_id, bets)
45
+ bf_bet = []
46
+ bets.each do |bet|
47
+ bf_bet << {
48
+ :marketId => bet[:market_id],
49
+ :selectionId => bet[:runner_id],
50
+ :betType => bet[:bet_type],
51
+ :price => bet[:price],
52
+ :size => bet[:size],
53
+ :asianLineId => bet[:asian_line_id],
54
+ :betCategoryType => bet[:bet_category_type],
55
+ :betPersistenceType => bet[:bet_peristence_type],
56
+ :bspLiability => bet[:bsp_liability]
57
+ }
58
+ end
44
59
 
60
+ response = exchange(exchange_id).
61
+ session_request( session_token,
62
+ :placeBets,
63
+ :place_bets_response,
64
+ :bets => { 'PlaceBets' => bf_bet } )
65
+
66
+ return response.maybe_result( :bet_results, :place_bets_result )
67
+ end
68
+
69
+
45
70
  def cancel_bet(session_token, exchange_id, bet_id)
46
71
  bf_bet = { :betId => bet_id }
47
72
 
@@ -53,7 +78,21 @@ module Betfair
53
78
 
54
79
  return response.maybe_result( :bet_results, :cancel_bets_result )
55
80
  end
81
+
82
+
83
+ def cancel_multiple_bets(session_token, exchange_id, bets)
84
+ bf_bet = []
85
+ bets.each { |bet_id| bf_bet << { :betId => bet_id } }
56
86
 
87
+ response = exchange(exchange_id).
88
+ session_request( session_token,
89
+ :cancelBets,
90
+ :cancel_bets_response,
91
+ :bets => { 'CancelBets' => bf_bet } ) # "CancelBets" has to be a string, not a symbol!
92
+
93
+ return response.maybe_result( :bet_results, :cancel_bets_result )
94
+ end
95
+
57
96
 
58
97
  def get_market(session_token, exchange_id, market_id, locale = nil)
59
98
  response = exchange(exchange_id).
@@ -113,6 +152,26 @@ module Betfair
113
152
 
114
153
  return response.maybe_result
115
154
  end
155
+
156
+
157
+ 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
+ response = exchange( exchange_id ).
159
+ session_request( session_token,
160
+ :getMUBets,
161
+ :get_mu_bets_response,
162
+ #:betIds => bet_ids,
163
+ :betStatus => bet_status,
164
+ #:excludeLastSecond => exclude_last_second,
165
+ :marketId => market_id,
166
+ #:matchedSince => matched_since,
167
+ :orderBy => order_by,
168
+ :recordCount => record_count,
169
+ :sortOrder => sort_order,
170
+ :startRecord => start_record
171
+ )
172
+
173
+ return response.maybe_result( :bets, :mu_bet )
174
+ end
116
175
 
117
176
 
118
177
  def login(username, password, product_id, vendor_software_id, location_id, ip_address)
@@ -424,4 +483,4 @@ module Betfair
424
483
 
425
484
  end
426
485
 
427
- end
486
+ end
@@ -1,3 +1,3 @@
1
1
  module Betfair
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require 'tempfile'
2
2
  require 'spec_helper'
3
3
 
4
-
5
4
  module Betfair
6
5
 
7
6
  describe "Helper methods for mashing the data from the API" do
@@ -78,7 +77,29 @@ module Betfair
78
77
  end
79
78
  end
80
79
 
81
- describe "cancel bet success" do
80
+ describe "place multiple bets success"do
81
+ it "should place mutliple bets on the exchange via the api" do
82
+ savon.expects(:place_bets).returns(:success)
83
+ bets = []
84
+ bets << { market_id: 104184109, runner_id: 58805, bet_type: 'B', price: 2.0, size: 2.0, asian_line_id: 0,
85
+ bet_category_type: 'E', bet_peristence_type: 'NONE', bsp_liability: 0 }
86
+ bets = @bf.place_multiple_bets(@session_token, 1, bets)
87
+ bets.should_not be_nil
88
+ end
89
+ end
90
+
91
+ describe "place multiple bets fail" do
92
+ it "should return an error message" do
93
+ savon.expects(:place_bets).returns(:fail)
94
+ bets = []
95
+ bets << { market_id: 104184109, runner_id: 58805, bet_type: 'B', price: 2.0, size: 2.0, asian_line_id: 0,
96
+ bet_category_type: 'E', bet_peristence_type: 'NONE', bsp_liability: 0 }
97
+ error_code = @bf.place_multiple_bets(@session_token, 1, bets)
98
+ error_code[:result_code].should eq('INVALID_SIZE')
99
+ end
100
+ end
101
+
102
+ describe "cancel bet success" do
82
103
  it "should cancel a bet on the exchange via the api" do
83
104
  savon.expects(:cancel_bets).returns(:success)
84
105
  bet = @bf.cancel_bet(@session_token, 3, 16939689578)
@@ -94,6 +115,22 @@ module Betfair
94
115
  end
95
116
  end
96
117
 
118
+ describe "cancel multiple bets success" do
119
+ it "should cancel a bet on the exchange via the api" do
120
+ savon.expects(:cancel_bets).returns(:success)
121
+ bets = @bf.cancel_multiple_bets(@session_token, 3, [16939689578, 16939689579, 169396895710])
122
+ bets.should_not be_nil
123
+ end
124
+ end
125
+
126
+ describe "cancel bet fail" do
127
+ it "should fail to cancel mulitple bets on the exchange via the api" do
128
+ savon.expects(:cancel_bets).returns(:fail)
129
+ error_code = @bf.cancel_multiple_bets(@session_token, 3, [16939689578, 16939689579, 169396895710])
130
+ error_code.should eq('API_ERROR - NO_SESSION')
131
+ end
132
+ end
133
+
97
134
  end
98
135
 
99
136
 
@@ -175,6 +212,24 @@ module Betfair
175
212
  events.should_not be_nil
176
213
  end
177
214
  end
215
+
216
+ describe "get matched/unmatched bets success" do
217
+ it "should return all of our unmatched and matched bets on an exchange, can take a market_id as the third arguement, plus many more" do
218
+ savon.expects(:getMUBets).returns(:success)
219
+ bets = @bf.get_mu_bets(@session_token, 1)
220
+ #bets.length.should eq(2)
221
+ bets[0][:selection_id].should eq("5986909")
222
+ bets[1][:selection_id].should eq("6230544")
223
+ end
224
+ end
225
+
226
+ describe "get matched/unmatched bets" do
227
+ it "should return an error message given the exchange id and and array of market type ids and no session id" do
228
+ savon.expects(:getMUBets).returns(:fail)
229
+ error_code = @bf.get_mu_bets(@session_token, 1)
230
+ error_code.should eq('API_ERROR - NO_SESSION')
231
+ end
232
+ end
178
233
 
179
234
  end
180
235
 
@@ -1,6 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
- xmlns:n2="http://www.betfair.com/publicapi/types/exchange/v5/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n2="http://www.betfair.com/publicapi/types/exchange/v5/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
4
3
  <soap:Body>
5
4
  <n:getAccountFundsResponse xmlns:n="http://www.betfair.com/publicapi/v5/BFExchangeService/">
6
5
  <n:Result xsi:type="n2:GetAccountFundsResp">
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n2="http://www.betfair.com/publicapi/types/exchange/v5/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <soap:Body>
4
+ <n:getMUBetsResponse xmlns:n="http://www.betfair.com/publicapi/v5/BFExchangeService/">
5
+ <n:Result xsi:type="n2:GetMUBetsResp">
6
+ <header xsi:type="n2:APIResponseHeader">
7
+ <errorCode xsi:type="n2:APIErrorEnum">NO_SESSION</errorCode>
8
+ <minorErrorCode xsi:nil="1"></minorErrorCode>
9
+ <sessionToken xsi:nil="1"></sessionToken>
10
+ <timestamp xsi:type="xsd:dateTime">2012-03-11T05:33:20.615Z</timestamp>
11
+ </header>
12
+ <bets xsi:nil="1"></bets>
13
+ <errorCode xsi:type="n2:GetMUBetsErrorEnum">API_ERROR</errorCode>
14
+ <minorErrorCode xsi:nil="1"></minorErrorCode>
15
+ <totalRecordCount xsi:type="xsd:int">0</totalRecordCount>
16
+ </n:Result>
17
+ </n:getMUBetsResponse>
18
+ </soap:Body>
19
+ </soap:Envelope>
@@ -0,0 +1,54 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n2="http://www.betfair.com/publicapi/types/exchange/v5/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <soap:Body>
4
+ <n:getMUBetsResponse xmlns:n="http://www.betfair.com/publicapi/v5/BFExchangeService/">
5
+ <n:Result xsi:type="n2:GetMUBetsResp">
6
+ <header xsi:type="n2:APIResponseHeader">
7
+ <errorCode xsi:type="n2:APIErrorEnum">OK</errorCode>
8
+ <minorErrorCode xsi:nil="1"></minorErrorCode>
9
+ <sessionToken xsi:type="xsd:string">tK5bi3RcJxzC7mtX6dIjCaaIe/DOvKzcX4GK8RQ7RGo=</sessionToken>
10
+ <timestamp xsi:type="xsd:dateTime">2012-03-11T05:35:21.219Z</timestamp>
11
+ </header>
12
+ <bets xsi:type="n2:ArrayOfMUBet">
13
+ <n2:MUBet xsi:type="n2:MUBet">
14
+ <asianLineId xsi:type="xsd:int">0</asianLineId>
15
+ <betId xsi:type="xsd:long">1828957078</betId>
16
+ <transactionId xsi:type="xsd:long">2433120449</transactionId>
17
+ <betStatus xsi:type="n2:BetStatusEnum">U</betStatus>
18
+ <betType xsi:type="n2:BetTypeEnum">L</betType>
19
+ <betCategoryType xsi:type="n2:BetCategoryTypeEnum">E</betCategoryType>
20
+ <betPersistenceType xsi:type="n2:BetPersistenceTypeEnum">NONE</betPersistenceType>
21
+ <marketId xsi:type="xsd:int">100470197</marketId>
22
+ <matchedDate xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</matchedDate>
23
+ <size xsi:type="xsd:double">5.0</size>
24
+ <bspLiability xsi:type="xsd:double">0.0</bspLiability>
25
+ <placedDate xsi:type="xsd:dateTime">2012-03-11T05:28:37.000Z</placedDate>
26
+ <price xsi:type="xsd:double">1.89</price>
27
+ <selectionId xsi:type="xsd:int">5986909</selectionId>
28
+ <handicap xsi:type="xsd:double">0.0</handicap>
29
+ </n2:MUBet>
30
+ <n2:MUBet xsi:type="n2:MUBet">
31
+ <asianLineId xsi:type="xsd:int">0</asianLineId>
32
+ <betId xsi:type="xsd:long">1828957079</betId>
33
+ <transactionId xsi:type="xsd:long">2433120450</transactionId>
34
+ <betStatus xsi:type="n2:BetStatusEnum">U</betStatus>
35
+ <betType xsi:type="n2:BetTypeEnum">L</betType>
36
+ <betCategoryType xsi:type="n2:BetCategoryTypeEnum">E</betCategoryType>
37
+ <betPersistenceType xsi:type="n2:BetPersistenceTypeEnum">NONE</betPersistenceType>
38
+ <marketId xsi:type="xsd:int">100470197</marketId>
39
+ <matchedDate xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</matchedDate>
40
+ <size xsi:type="xsd:double">5.0</size>
41
+ <bspLiability xsi:type="xsd:double">0.0</bspLiability>
42
+ <placedDate xsi:type="xsd:dateTime">2012-03-11T05:28:37.000Z</placedDate>
43
+ <price xsi:type="xsd:double">1.48</price>
44
+ <selectionId xsi:type="xsd:int">6230544</selectionId>
45
+ <handicap xsi:type="xsd:double">0.0</handicap>
46
+ </n2:MUBet>
47
+ </bets>
48
+ <errorCode xsi:type="n2:GetMUBetsErrorEnum">OK</errorCode>
49
+ <minorErrorCode xsi:nil="1"></minorErrorCode>
50
+ <totalRecordCount xsi:type="xsd:int">2</totalRecordCount>
51
+ </n:Result>
52
+ </n:getMUBetsResponse>
53
+ </soap:Body>
54
+ </soap:Envelope>
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: 0.0.14
4
+ version: 0.0.16
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-02-29 00:00:00.000000000Z
12
+ date: 2012-03-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
16
- requirement: &70236502261180 !ruby/object:Gem::Requirement
16
+ requirement: &70157897063020 !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: *70236502261180
24
+ version_requirements: *70157897063020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70236502258180 !ruby/object:Gem::Requirement
27
+ requirement: &70157897062340 !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: *70236502258180
35
+ version_requirements: *70157897062340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70236502252040 !ruby/object:Gem::Requirement
38
+ requirement: &70157897061740 !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: *70236502252040
46
+ version_requirements: *70157897061740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: savon_spec
49
- requirement: &70236502249320 !ruby/object:Gem::Requirement
49
+ requirement: &70157897061180 !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: *70236502249320
57
+ version_requirements: *70157897061180
58
58
  description: Gem for accessing the Betfair API.
59
59
  email:
60
60
  - lukeb@lukebyrne.com
@@ -68,6 +68,7 @@ files:
68
68
  - README
69
69
  - Rakefile
70
70
  - betfair.gemspec
71
+ - examples/doh.log
71
72
  - examples/foo.rb
72
73
  - lib/betfair.rb
73
74
  - lib/betfair/api.rb
@@ -83,6 +84,8 @@ files:
83
84
  - spec/fixtures/get_market/success.xml
84
85
  - spec/fixtures/get_market_prices_compressed/fail.xml
85
86
  - spec/fixtures/get_market_prices_compressed/success.xml
87
+ - spec/fixtures/get_mu_bets/fail.xml
88
+ - spec/fixtures/get_mu_bets/success.xml
86
89
  - spec/fixtures/login/fail.xml
87
90
  - spec/fixtures/login/success.xml
88
91
  - spec/fixtures/place_bets/fail.xml
@@ -102,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
105
  version: '0'
103
106
  segments:
104
107
  - 0
105
- hash: -2051552141254141461
108
+ hash: 1829796573211684180
106
109
  required_rubygems_version: !ruby/object:Gem::Requirement
107
110
  none: false
108
111
  requirements:
@@ -111,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
114
  version: '0'
112
115
  segments:
113
116
  - 0
114
- hash: -2051552141254141461
117
+ hash: 1829796573211684180
115
118
  requirements: []
116
119
  rubyforge_project: betfair
117
120
  rubygems_version: 1.8.10
@@ -130,6 +133,8 @@ test_files:
130
133
  - spec/fixtures/get_market/success.xml
131
134
  - spec/fixtures/get_market_prices_compressed/fail.xml
132
135
  - spec/fixtures/get_market_prices_compressed/success.xml
136
+ - spec/fixtures/get_mu_bets/fail.xml
137
+ - spec/fixtures/get_mu_bets/success.xml
133
138
  - spec/fixtures/login/fail.xml
134
139
  - spec/fixtures/login/success.xml
135
140
  - spec/fixtures/place_bets/fail.xml