mtgox 0.9.0 → 0.9.1
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.tar.gz.sig +0 -0
- data/README.md +30 -25
- data/lib/mtgox.rb +1 -3
- data/lib/mtgox/ask.rb +3 -2
- data/lib/mtgox/bid.rb +3 -2
- data/lib/mtgox/client.rb +62 -29
- data/lib/mtgox/configuration.rb +0 -7
- data/lib/mtgox/connection.rb +1 -1
- data/lib/mtgox/lag.rb +12 -0
- data/lib/mtgox/min_ask.rb +0 -2
- data/lib/mtgox/offer.rb +1 -1
- data/lib/mtgox/request.rb +3 -3
- data/lib/mtgox/version.rb +1 -1
- data/spec/fixtures/cancel.json +5 -5
- data/spec/fixtures/idkey.json +4 -0
- data/spec/fixtures/lag.json +1 -0
- data/spec/helper.rb +4 -4
- data/spec/mtgox/client_spec.rb +117 -29
- metadata +7 -2
- metadata.gz.sig +3 -2
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -42,41 +42,46 @@ typing `btc` in your bash shell:
|
|
42
42
|
[documentation]: http://rdoc.info/gems/mtgox
|
43
43
|
|
44
44
|
## Usage Examples
|
45
|
-
|
46
|
-
|
45
|
+
```ruby
|
46
|
+
require 'rubygems'
|
47
|
+
require 'mtgox'
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
# Fetch the latest price for 1 BTC in USD
|
50
|
+
puts MtGox.ticker.sell
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
# Fetch open asks
|
53
|
+
puts MtGox.asks
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
# Fetch open bids
|
56
|
+
puts MtGox.bids
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
# Fetch the last 48 hours worth of trades (takes a minute)
|
59
|
+
puts MtGox.trades
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
# Certain methods require authentication
|
62
|
+
MtGox.configure do |config|
|
63
|
+
config.key = YOUR_MTGOX_KEY
|
64
|
+
config.secret = YOUR_MTGOX_SECRET
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
67
|
+
# Fetch your current balance
|
68
|
+
puts MtGox.balance
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
# Place a limit order to buy one bitcoin for $0.011
|
71
|
+
MtGox.buy! 1.0, 0.011
|
71
72
|
|
72
|
-
|
73
|
-
|
73
|
+
# Place a limit order to sell one bitcoin for $100
|
74
|
+
MtGox.sell! 1.0, 100.0
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
# Place a market order to sell one bitcoin
|
77
|
+
MtGox.sell! 1.0, :market
|
77
78
|
|
78
|
-
|
79
|
-
|
79
|
+
# Cancel order #1234567890
|
80
|
+
MtGox.cancel 1234567890
|
81
|
+
|
82
|
+
# Withdraw 1 BTC from your account
|
83
|
+
MtGox.withdraw! 1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"
|
84
|
+
```
|
80
85
|
|
81
86
|
## Contributing
|
82
87
|
In the spirit of [free software][free-sw], **everyone** is encouraged to help
|
data/lib/mtgox.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'mtgox/client'
|
2
|
-
require 'mtgox/configuration'
|
3
2
|
require 'mtgox/error'
|
4
3
|
|
5
4
|
module MtGox
|
6
|
-
extend Configuration
|
7
5
|
class << self
|
8
6
|
# Alias for MtGox::Client.new
|
9
7
|
#
|
10
8
|
# @return [MtGox::Client]
|
11
9
|
def new
|
12
|
-
MtGox::Client.new
|
10
|
+
@client ||= MtGox::Client.new
|
13
11
|
end
|
14
12
|
|
15
13
|
# Delegate to MtGox::Client
|
data/lib/mtgox/ask.rb
CHANGED
@@ -5,7 +5,8 @@ module MtGox
|
|
5
5
|
class Ask < Offer
|
6
6
|
include MtGox::Value
|
7
7
|
|
8
|
-
def initialize(hash = nil)
|
8
|
+
def initialize(client, hash = nil)
|
9
|
+
self.client = client
|
9
10
|
if hash
|
10
11
|
self.price = value_currency hash, 'price_int'
|
11
12
|
self.amount = value_bitcoin hash, 'amount_int'
|
@@ -14,7 +15,7 @@ module MtGox
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def eprice
|
17
|
-
price / (1 -
|
18
|
+
price / (1 - self.client.commission)
|
18
19
|
end
|
19
20
|
|
20
21
|
end
|
data/lib/mtgox/bid.rb
CHANGED
@@ -5,7 +5,8 @@ module MtGox
|
|
5
5
|
class Bid < Offer
|
6
6
|
include MtGox::Value
|
7
7
|
|
8
|
-
def initialize(hash = nil)
|
8
|
+
def initialize(client, hash = nil)
|
9
|
+
self.client = client
|
9
10
|
if hash
|
10
11
|
self.price = value_currency hash, 'price_int'
|
11
12
|
self.amount = value_bitcoin hash, 'amount_int'
|
@@ -14,7 +15,7 @@ module MtGox
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def eprice
|
17
|
-
price * (1 -
|
18
|
+
price * (1 - self.client.commission)
|
18
19
|
end
|
19
20
|
|
20
21
|
end
|
data/lib/mtgox/client.rb
CHANGED
@@ -11,15 +11,22 @@ require 'mtgox/sell'
|
|
11
11
|
require 'mtgox/ticker'
|
12
12
|
require 'mtgox/trade'
|
13
13
|
require 'mtgox/value'
|
14
|
+
require 'mtgox/lag'
|
15
|
+
require 'mtgox/configuration'
|
14
16
|
|
15
17
|
module MtGox
|
16
18
|
class Client
|
17
19
|
include MtGox::Connection
|
18
20
|
include MtGox::Request
|
19
21
|
include MtGox::Value
|
22
|
+
include MtGox::Configuration
|
20
23
|
|
21
24
|
ORDER_TYPES = {sell: "ask", buy: "bid"}
|
22
25
|
|
26
|
+
def initialize
|
27
|
+
reset
|
28
|
+
end
|
29
|
+
|
23
30
|
# Fetch a deposit address
|
24
31
|
# @authenticated true
|
25
32
|
# @return [String]
|
@@ -29,6 +36,14 @@ module MtGox
|
|
29
36
|
post('/api/1/generic/bitcoin/address')['addr']
|
30
37
|
end
|
31
38
|
|
39
|
+
# Get an idKey for subscribing to private channels in WebSocket API
|
40
|
+
# @authenticated true
|
41
|
+
# @return [String] the idKey to use in your WebSocket client
|
42
|
+
# @example
|
43
|
+
# MtGox.idkey
|
44
|
+
def idkey
|
45
|
+
post('/api/1/generic/idkey')
|
46
|
+
end
|
32
47
|
|
33
48
|
# Fetch the latest ticker data
|
34
49
|
#
|
@@ -43,16 +58,29 @@ module MtGox
|
|
43
58
|
Ticker.instance.price = value_currency ticker['last_all']
|
44
59
|
Ticker.instance.low = value_currency ticker['low']
|
45
60
|
Ticker.instance.sell = value_currency ticker['sell']
|
46
|
-
Ticker.instance.volume = value_bitcoin
|
61
|
+
Ticker.instance.volume = value_bitcoin ticker['vol']
|
47
62
|
Ticker.instance.vwap = value_currency ticker['vwap']
|
48
|
-
Ticker.instance.avg
|
63
|
+
Ticker.instance.avg = value_currency ticker['avg']
|
49
64
|
Ticker.instance
|
50
65
|
end
|
51
66
|
|
67
|
+
# Fetch the latest lag data
|
68
|
+
#
|
69
|
+
# @authenticated false
|
70
|
+
# @return [MtGox::Lag]
|
71
|
+
# @example
|
72
|
+
# MtGox.lag
|
73
|
+
def lag
|
74
|
+
lag = get('/api/1/generic/order/lag')
|
75
|
+
Lag.new(lag['lag'], lag['lag_secs'], lag['lag_text'], lag['length'])
|
76
|
+
end
|
77
|
+
alias order_lag lag
|
78
|
+
alias orderlag lag
|
79
|
+
|
52
80
|
# Fetch both bids and asks in one call, for network efficiency
|
53
81
|
#
|
54
82
|
# @authenticated false
|
55
|
-
# @return [Hash] with keys :asks and :
|
83
|
+
# @return [Hash] with keys :asks and :bids, which contain arrays as described in {MtGox::Client#asks} and {MtGox::Clients#bids}
|
56
84
|
# @example
|
57
85
|
# MtGox.offers
|
58
86
|
def offers
|
@@ -60,12 +88,12 @@ module MtGox
|
|
60
88
|
asks = offers['asks'].sort_by do |ask|
|
61
89
|
ask['price_int'].to_i
|
62
90
|
end.map! do |ask|
|
63
|
-
Ask.new(ask)
|
91
|
+
Ask.new(self, ask)
|
64
92
|
end
|
65
93
|
bids = offers['bids'].sort_by do |bid|
|
66
94
|
-bid['price_int'].to_i
|
67
95
|
end.map! do |bid|
|
68
|
-
Bid.new(bid)
|
96
|
+
Bid.new(self, bid)
|
69
97
|
end
|
70
98
|
{asks: asks, bids: bids}
|
71
99
|
end
|
@@ -97,10 +125,7 @@ module MtGox
|
|
97
125
|
# @example
|
98
126
|
# MtGox.min_ask
|
99
127
|
def min_ask
|
100
|
-
|
101
|
-
MinAsk.instance.price = min_ask.price
|
102
|
-
MinAsk.instance.amount = min_ask.amount
|
103
|
-
MinAsk.instance
|
128
|
+
asks.first
|
104
129
|
end
|
105
130
|
|
106
131
|
# Fetch the highest priced bid
|
@@ -110,10 +135,7 @@ module MtGox
|
|
110
135
|
# @example
|
111
136
|
# MtGox.max_bid
|
112
137
|
def max_bid
|
113
|
-
|
114
|
-
MaxBid.instance.price = max_bid.price
|
115
|
-
MaxBid.instance.amount = max_bid.amount
|
116
|
-
MaxBid.instance
|
138
|
+
bids.first
|
117
139
|
end
|
118
140
|
|
119
141
|
# Fetch recent trades
|
@@ -122,8 +144,10 @@ module MtGox
|
|
122
144
|
# @return [Array<MtGox::Trade>] an array of trades, sorted in chronological order
|
123
145
|
# @example
|
124
146
|
# MtGox.trades
|
125
|
-
|
126
|
-
|
147
|
+
# MtGox.trades :since => 12341234
|
148
|
+
def trades(opts={})
|
149
|
+
get('/api/1/BTCUSD/trades/fetch', opts).
|
150
|
+
sort_by{|trade| trade['date']}.map do |trade|
|
127
151
|
Trade.new(trade)
|
128
152
|
end
|
129
153
|
end
|
@@ -135,7 +159,7 @@ module MtGox
|
|
135
159
|
# @example
|
136
160
|
# MtGox.balance
|
137
161
|
def balance
|
138
|
-
parse_balance(post('/api/1/generic/info'
|
162
|
+
parse_balance(post('/api/1/generic/info'))
|
139
163
|
end
|
140
164
|
|
141
165
|
# Fetch your open orders, both buys and sells, for network efficiency
|
@@ -145,7 +169,7 @@ module MtGox
|
|
145
169
|
# @example
|
146
170
|
# MtGox.orders
|
147
171
|
def orders
|
148
|
-
parse_orders
|
172
|
+
parse_orders(post('/api/1/generic/orders'))
|
149
173
|
end
|
150
174
|
|
151
175
|
# Fetch your open buys
|
@@ -172,26 +196,26 @@ module MtGox
|
|
172
196
|
#
|
173
197
|
# @authenticated true
|
174
198
|
# @param amount [Numeric] the number of bitcoins to purchase
|
175
|
-
# @param price [Numeric] the bid price in US dollars
|
199
|
+
# @param price [Numeric or Symbol] the bid price in US dollars, or :market if placing a market order
|
176
200
|
# @return [String] order ID for the buy, can be inspected using order_result
|
177
201
|
# @example
|
178
202
|
# # Buy one bitcoin for $0.011
|
179
203
|
# MtGox.buy! 1.0, 0.011
|
180
204
|
def buy!(amount, price)
|
181
|
-
|
205
|
+
add_order!(:buy, amount, price)
|
182
206
|
end
|
183
207
|
|
184
208
|
# Place a limit order to sell BTC
|
185
209
|
#
|
186
210
|
# @authenticated true
|
187
211
|
# @param amount [Numeric] the number of bitcoins to sell
|
188
|
-
# @param price [Numeric] the ask price in US dollars
|
212
|
+
# @param price [Numeric or Symbol] the ask price in US dollars, or :market if placing a market order
|
189
213
|
# @return [String] order ID for the sell, can be inspected using order_result
|
190
214
|
# @example
|
191
215
|
# # Sell one bitcoin for $100
|
192
216
|
# MtGox.sell! 1.0, 100.0
|
193
217
|
def sell!(amount, price)
|
194
|
-
|
218
|
+
add_order!(:sell, amount, price)
|
195
219
|
end
|
196
220
|
|
197
221
|
# Create a new order
|
@@ -199,14 +223,20 @@ module MtGox
|
|
199
223
|
# @authenticated true
|
200
224
|
# @param type [String] the type of order to create, either "buy" or "sell"
|
201
225
|
# @param amount [Numberic] the number of bitcoins to buy/sell
|
202
|
-
# @param price [Numeric] the bid/ask price in USD
|
226
|
+
# @param price [Numeric or Symbol] the bid/ask price in USD, or :market if placing a market order
|
203
227
|
# @return [String] order ID for the order, can be inspected using order_result
|
204
228
|
# @example
|
205
229
|
# # Sell one bitcoin for $123
|
206
|
-
# MtGox.
|
207
|
-
def
|
208
|
-
|
230
|
+
# MtGox.add_order! :sell, 1.0, 123.0
|
231
|
+
def order!(type, amount, price)
|
232
|
+
order = {type: order_type(type), amount_int: intify(amount,:btc)}
|
233
|
+
if price != :market
|
234
|
+
order[:price_int] = intify(price, :usd)
|
235
|
+
end
|
236
|
+
post('/api/1/BTCUSD/order/add', order)
|
209
237
|
end
|
238
|
+
alias add_order! order!
|
239
|
+
alias addorder! order!
|
210
240
|
|
211
241
|
# Cancel an open order
|
212
242
|
#
|
@@ -230,16 +260,18 @@ module MtGox
|
|
230
260
|
args = args['oid']
|
231
261
|
end
|
232
262
|
|
233
|
-
orders = post('/api/1/generic/orders'
|
263
|
+
orders = post('/api/1/generic/orders')
|
234
264
|
order = orders.find{|order| order['oid'] == args.to_s}
|
235
265
|
if order
|
236
|
-
res = post('/api/1/BTCUSD/order/cancel',
|
237
|
-
orders.delete_if
|
266
|
+
res = post('/api/1/BTCUSD/order/cancel', oid: order['oid'])
|
267
|
+
orders.delete_if{|o| o['oid'] == res['oid']}
|
238
268
|
parse_orders(orders)
|
239
269
|
else
|
240
270
|
raise Faraday::Error::ResourceNotFound, {status: 404, headers: {}, body: 'Order not found.'}
|
241
271
|
end
|
242
272
|
end
|
273
|
+
alias cancel_order cancel
|
274
|
+
alias cancelorder cancel
|
243
275
|
|
244
276
|
# Transfer bitcoins from your Mt. Gox account into another account
|
245
277
|
#
|
@@ -259,7 +291,7 @@ module MtGox
|
|
259
291
|
end
|
260
292
|
end
|
261
293
|
|
262
|
-
|
294
|
+
private
|
263
295
|
|
264
296
|
def parse_balance(info)
|
265
297
|
balances = []
|
@@ -291,5 +323,6 @@ module MtGox
|
|
291
323
|
type
|
292
324
|
end
|
293
325
|
end
|
326
|
+
|
294
327
|
end
|
295
328
|
end
|
data/lib/mtgox/configuration.rb
CHANGED
@@ -23,13 +23,6 @@ module MtGox
|
|
23
23
|
yield self
|
24
24
|
end
|
25
25
|
|
26
|
-
# Create a hash of options and their values
|
27
|
-
def options
|
28
|
-
options = {}
|
29
|
-
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
30
|
-
options
|
31
|
-
end
|
32
|
-
|
33
26
|
# Reset all configuration options to defaults
|
34
27
|
def reset
|
35
28
|
self.commission = DEFAULT_COMMISSION
|
data/lib/mtgox/connection.rb
CHANGED
data/lib/mtgox/lag.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module MtGox
|
2
|
+
class Lag
|
3
|
+
attr_accessor :microseconds, :seconds, :text, :length
|
4
|
+
|
5
|
+
def initialize(lag=nil, lag_secs=nil, lag_text=nil, length=nil)
|
6
|
+
self.microseconds = lag.to_i
|
7
|
+
self.seconds = lag_secs.to_f
|
8
|
+
self.text = lag_text
|
9
|
+
self.length = length.to_i
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/mtgox/min_ask.rb
CHANGED
data/lib/mtgox/offer.rb
CHANGED
data/lib/mtgox/request.rb
CHANGED
@@ -10,7 +10,7 @@ module MtGox
|
|
10
10
|
request(:post, path, options)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
private
|
14
14
|
|
15
15
|
def request(method, path, options)
|
16
16
|
response = connection.send(method) do |request|
|
@@ -33,10 +33,10 @@ module MtGox
|
|
33
33
|
def headers(request)
|
34
34
|
signature = Base64.strict_encode64(
|
35
35
|
OpenSSL::HMAC.digest 'sha512',
|
36
|
-
Base64.decode64(
|
36
|
+
Base64.decode64(secret),
|
37
37
|
request
|
38
38
|
)
|
39
|
-
{'Rest-Key' =>
|
39
|
+
{'Rest-Key' => key, 'Rest-Sign' => signature}
|
40
40
|
end
|
41
41
|
|
42
42
|
def body_from_options(options)
|
data/lib/mtgox/version.rb
CHANGED
data/spec/fixtures/cancel.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
|
-
"return": {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
"result": "success"
|
2
|
+
"return": {
|
3
|
+
"qid": "09354767-455f-412e-9a0c-efb7bb98c958g",
|
4
|
+
"oid": "fda8917a-63d3-4415-b827-758408013690"
|
5
|
+
},
|
6
|
+
"result": "success"
|
7
7
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"result":"success","return":{"lag":535998,"lag_secs":0.535998,"lag_text":"0.535998 seconds","length":"3"}}
|
data/spec/helper.rb
CHANGED
@@ -40,20 +40,20 @@ end
|
|
40
40
|
|
41
41
|
module MtGox
|
42
42
|
module Request
|
43
|
-
|
43
|
+
private
|
44
44
|
def add_nonce(options)
|
45
45
|
options.merge!({nonce: 1321745961249676})
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def test_headers(body=test_body)
|
50
|
+
def test_headers(client, body=test_body)
|
51
51
|
signature = Base64.strict_encode64(
|
52
52
|
OpenSSL::HMAC.digest 'sha512',
|
53
|
-
Base64.decode64(
|
53
|
+
Base64.decode64(client.secret),
|
54
54
|
body
|
55
55
|
)
|
56
|
-
{'Rest-Key' =>
|
56
|
+
{'Rest-Key' => client.key, 'Rest-Sign' => signature}
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_body(options={})
|
data/spec/mtgox/client_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
describe MtGox::Client do
|
4
4
|
before do
|
5
5
|
@client = MtGox::Client.new
|
6
|
-
|
6
|
+
@client.configure do |config|
|
7
7
|
config.key = "key"
|
8
8
|
config.secret = "secret"
|
9
9
|
end
|
@@ -12,7 +12,7 @@ describe MtGox::Client do
|
|
12
12
|
describe '#address' do
|
13
13
|
before do
|
14
14
|
stub_post('/api/1/generic/bitcoin/address').
|
15
|
-
to_return(
|
15
|
+
to_return(body: fixture('address.json'))
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should fetch a deposit address" do
|
@@ -23,10 +23,24 @@ describe MtGox::Client do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
describe '#idkey' do
|
27
|
+
before do
|
28
|
+
stub_post('/api/1/generic/idkey').
|
29
|
+
to_return(body: fixture('idkey.json'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should fetch an idkey suitable to WS Api usage" do
|
33
|
+
key = @client.idkey
|
34
|
+
a_post('/api/1/generic/idkey').
|
35
|
+
should have_been_made
|
36
|
+
key.should == 'YCKvmyU4QsaHEqM/AvKlqAAAAABRbR5y0vCn1roteQx/Ux/lyLF27X8Em1e4AN/2etPECzIT6dU'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
26
40
|
describe '#ticker' do
|
27
41
|
before do
|
28
42
|
stub_get('/api/1/BTCUSD/ticker').
|
29
|
-
to_return(
|
43
|
+
to_return(body: fixture('ticker.json'))
|
30
44
|
end
|
31
45
|
|
32
46
|
it "should fetch the ticker" do
|
@@ -42,12 +56,40 @@ describe MtGox::Client do
|
|
42
56
|
ticker.vwap.should == 5.61048
|
43
57
|
ticker.avg.should == 5.56112
|
44
58
|
end
|
59
|
+
|
60
|
+
it "should fetch the ticker and keep previous price" do
|
61
|
+
ticker = @client.ticker
|
62
|
+
ticker = @client.ticker
|
63
|
+
a_get('/api/1/BTCUSD/ticker').
|
64
|
+
should have_been_made.twice
|
65
|
+
ticker.up?.should == false
|
66
|
+
ticker.down?.should == false
|
67
|
+
ticker.changed?.should == false
|
68
|
+
ticker.unchanged?.should == true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#lag' do
|
73
|
+
before do
|
74
|
+
stub_get('/api/1/generic/order/lag').
|
75
|
+
to_return(status:200, body: fixture('lag.json'))
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should fetch the lag" do
|
79
|
+
lag = @client.lag
|
80
|
+
a_get('/api/1/generic/order/lag').
|
81
|
+
should have_been_made
|
82
|
+
lag.microseconds.should == 535998
|
83
|
+
lag.seconds.should == 0.535998
|
84
|
+
lag.text.should == "0.535998 seconds"
|
85
|
+
lag.length.should == 3
|
86
|
+
end
|
45
87
|
end
|
46
88
|
|
47
89
|
describe 'depth methods' do
|
48
90
|
before :each do
|
49
91
|
stub_get('/api/1/BTCUSD/depth/fetch').
|
50
|
-
to_return(
|
92
|
+
to_return(body: fixture('depth.json'))
|
51
93
|
end
|
52
94
|
|
53
95
|
describe '#asks' do
|
@@ -124,7 +166,7 @@ describe MtGox::Client do
|
|
124
166
|
describe '#trades' do
|
125
167
|
before do
|
126
168
|
stub_get('/api/1/BTCUSD/trades/fetch').
|
127
|
-
to_return(
|
169
|
+
to_return(body: fixture('trades.json'))
|
128
170
|
end
|
129
171
|
|
130
172
|
it "should fetch trades" do
|
@@ -138,17 +180,35 @@ describe MtGox::Client do
|
|
138
180
|
end
|
139
181
|
end
|
140
182
|
|
183
|
+
describe '#trades :since' do
|
184
|
+
before do
|
185
|
+
trades = MultiJson.load(fixture('trades.json'))
|
186
|
+
stub_get('/api/1/BTCUSD/trades/fetch?since=1365780002144150').
|
187
|
+
to_return(body: MultiJson.dump({result: 'success', return: trades['return'].select{|t| t['tid'] >= '1365780002144150'}}))
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should fetch trades since an id" do
|
191
|
+
trades = @client.trades :since => 1365780002144150
|
192
|
+
#puts trades.inspect
|
193
|
+
a_get('/api/1/BTCUSD/trades/fetch?since=1365780002144150').
|
194
|
+
should have_been_made
|
195
|
+
trades.first.price.should == 72.98274
|
196
|
+
trades.first.amount.should == 11.76583944
|
197
|
+
trades.first.id.should == 1365780002144150
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
141
201
|
describe '#balance' do
|
142
202
|
before do
|
143
203
|
stub_post('/api/1/generic/info').
|
144
|
-
with(body: test_body, headers: test_headers).
|
145
|
-
to_return(
|
204
|
+
with(body: test_body, headers: test_headers(@client)).
|
205
|
+
to_return(body: fixture('info.json'))
|
146
206
|
end
|
147
207
|
|
148
208
|
it "should fetch balance" do
|
149
209
|
balance = @client.balance
|
150
210
|
a_post("/api/1/generic/info").
|
151
|
-
with(body: test_body, headers: test_headers).
|
211
|
+
with(body: test_body, headers: test_headers(@client)).
|
152
212
|
should have_been_made
|
153
213
|
balance.first.currency.should == "BTC"
|
154
214
|
balance.first.amount.should == 42.0
|
@@ -160,15 +220,15 @@ describe MtGox::Client do
|
|
160
220
|
describe "order methods" do
|
161
221
|
before :each do
|
162
222
|
stub_post('/api/1/generic/orders').
|
163
|
-
with(body: test_body, headers: test_headers).
|
164
|
-
to_return(
|
223
|
+
with(body: test_body, headers: test_headers(@client)).
|
224
|
+
to_return(body: fixture('orders.json'))
|
165
225
|
end
|
166
226
|
|
167
227
|
describe "#buys" do
|
168
228
|
it "should fetch orders" do
|
169
229
|
buys = @client.buys
|
170
230
|
a_post("/api/1/generic/orders").
|
171
|
-
with(body: test_body, headers: test_headers).
|
231
|
+
with(body: test_body, headers: test_headers(@client)).
|
172
232
|
should have_been_made
|
173
233
|
buys.last.price.should == 7
|
174
234
|
buys.last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
|
@@ -179,7 +239,7 @@ describe MtGox::Client do
|
|
179
239
|
it "should fetch sells" do
|
180
240
|
sells = @client.sells
|
181
241
|
a_post("/api/1/generic/orders").
|
182
|
-
with(body: test_body, headers: test_headers).
|
242
|
+
with(body: test_body, headers: test_headers(@client)).
|
183
243
|
should have_been_made
|
184
244
|
sells.last.price.should == 99.0
|
185
245
|
sells.last.date.should == Time.utc(2011, 6, 27, 18, 20, 20)
|
@@ -190,7 +250,7 @@ describe MtGox::Client do
|
|
190
250
|
it "should fetch both buys and sells, with only one call" do
|
191
251
|
orders = @client.orders
|
192
252
|
a_post("/api/1/generic/orders").
|
193
|
-
with(body: test_body, headers: test_headers).
|
253
|
+
with(body: test_body, headers: test_headers(@client)).
|
194
254
|
should have_been_made
|
195
255
|
orders[:buys].last.price.should == 7.0
|
196
256
|
orders[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
|
@@ -203,16 +263,30 @@ describe MtGox::Client do
|
|
203
263
|
describe "#buy!" do
|
204
264
|
before do
|
205
265
|
body = test_body({"type" => "bid", "amount_int" => "88000000", "price_int" => "89000"})
|
266
|
+
body_market = test_body({"type" => "bid", "amount_int" => "88000000"})
|
267
|
+
|
268
|
+
stub_post('/api/1/BTCUSD/order/add').
|
269
|
+
with(body: body, headers: test_headers(@client, body)).
|
270
|
+
to_return(body: fixture('buy.json'))
|
206
271
|
stub_post('/api/1/BTCUSD/order/add').
|
207
|
-
with(body:
|
208
|
-
to_return(
|
272
|
+
with(body: body_market, headers: test_headers(@client, body_market)).
|
273
|
+
to_return(body: fixture('buy.json'))
|
209
274
|
end
|
210
275
|
|
211
276
|
it "should place a bid" do
|
212
277
|
buy = @client.buy!(0.88, 0.89)
|
213
278
|
body = test_body({"type" => "bid", "amount_int" => "88000000", "price_int" => "89000"})
|
214
279
|
a_post("/api/1/BTCUSD/order/add").
|
215
|
-
with(body: body, headers: test_headers(body)).
|
280
|
+
with(body: body, headers: test_headers(@client, body)).
|
281
|
+
should have_been_made
|
282
|
+
buy.should == "490a214f-9a30-449f-acb8-780f9046502f"
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should place a market bid" do
|
286
|
+
buy = @client.buy!(0.88, :market)
|
287
|
+
body_market = test_body({"type" => "bid", "amount_int" => "88000000"})
|
288
|
+
a_post("/api/1/BTCUSD/order/add").
|
289
|
+
with(body: body_market, headers: test_headers(@client, body_market)).
|
216
290
|
should have_been_made
|
217
291
|
buy.should == "490a214f-9a30-449f-acb8-780f9046502f"
|
218
292
|
end
|
@@ -221,16 +295,30 @@ describe MtGox::Client do
|
|
221
295
|
describe "#sell!" do
|
222
296
|
before do
|
223
297
|
body = test_body({"type" => "ask", "amount_int" => "88000000", "price_int" => "8900000"})
|
298
|
+
body_market = test_body({"type" => "ask", "amount_int" => "88000000"})
|
299
|
+
|
300
|
+
stub_post('/api/1/BTCUSD/order/add').
|
301
|
+
with(body: body, headers: test_headers(@client, body)).
|
302
|
+
to_return(body: fixture('sell.json'))
|
224
303
|
stub_post('/api/1/BTCUSD/order/add').
|
225
|
-
with(body:
|
226
|
-
to_return(
|
304
|
+
with(body: body_market, headers: test_headers(@client, body_market)).
|
305
|
+
to_return(body: fixture('sell.json'))
|
227
306
|
end
|
228
307
|
|
229
308
|
it "should place an ask" do
|
230
309
|
body = test_body({"type" => "ask", "amount_int" => "88000000", "price_int" => "8900000"})
|
231
310
|
sell = @client.sell!(0.88, 89.0)
|
232
311
|
a_post("/api/1/BTCUSD/order/add").
|
233
|
-
with(body: body, headers: test_headers(body)).
|
312
|
+
with(body: body, headers: test_headers(@client, body)).
|
313
|
+
should have_been_made
|
314
|
+
sell.should == "a20329fe-c0d5-4378-b204-79a7800d41e7"
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should place a market ask" do
|
318
|
+
body_market = test_body({"type" => "ask", "amount_int" => "88000000"})
|
319
|
+
sell = @client.sell!(0.88, :market)
|
320
|
+
a_post("/api/1/BTCUSD/order/add").
|
321
|
+
with(body: body_market, headers: test_headers(@client, body_market)).
|
234
322
|
should have_been_made
|
235
323
|
sell.should == "a20329fe-c0d5-4378-b204-79a7800d41e7"
|
236
324
|
end
|
@@ -240,11 +328,11 @@ describe MtGox::Client do
|
|
240
328
|
before do
|
241
329
|
cancel_body = test_body({"oid" => "fda8917a-63d3-4415-b827-758408013690"})
|
242
330
|
stub_post('/api/1/generic/orders').
|
243
|
-
with(body: test_body, headers: test_headers).
|
244
|
-
to_return(
|
331
|
+
with(body: test_body, headers: test_headers(@client)).
|
332
|
+
to_return(body: fixture('orders.json'))
|
245
333
|
stub_post('/api/1/BTCUSD/order/cancel').
|
246
|
-
with(body: cancel_body, headers: test_headers(cancel_body)).
|
247
|
-
to_return(
|
334
|
+
with(body: cancel_body, headers: test_headers(@client, cancel_body)).
|
335
|
+
to_return(body: fixture('cancel.json'))
|
248
336
|
end
|
249
337
|
|
250
338
|
context "with a valid oid passed" do
|
@@ -252,10 +340,10 @@ describe MtGox::Client do
|
|
252
340
|
cancel = @client.cancel("fda8917a-63d3-4415-b827-758408013690")
|
253
341
|
cancel_body = test_body({"oid" => "fda8917a-63d3-4415-b827-758408013690"})
|
254
342
|
a_post("/api/1/generic/orders").
|
255
|
-
with(body: test_body, headers: test_headers).
|
343
|
+
with(body: test_body, headers: test_headers(@client)).
|
256
344
|
should have_been_made.once
|
257
345
|
a_post('/api/1/BTCUSD/order/cancel').
|
258
|
-
with(body: cancel_body, headers: test_headers(cancel_body)).
|
346
|
+
with(body: cancel_body, headers: test_headers(@client, cancel_body)).
|
259
347
|
should have_been_made
|
260
348
|
cancel[:buys].length.should == 0
|
261
349
|
end
|
@@ -272,7 +360,7 @@ describe MtGox::Client do
|
|
272
360
|
cancel = @client.cancel({'oid' => "fda8917a-63d3-4415-b827-758408013690", 'type' => 2})
|
273
361
|
body = test_body({"oid" => "fda8917a-63d3-4415-b827-758408013690"})
|
274
362
|
a_post('/api/1/BTCUSD/order/cancel').
|
275
|
-
with(body: body, headers: test_headers(body)).
|
363
|
+
with(body: body, headers: test_headers(@client, body)).
|
276
364
|
should have_been_made
|
277
365
|
cancel[:buys].length.should == 0
|
278
366
|
cancel[:sells].last.price.should == 99.0
|
@@ -285,15 +373,15 @@ describe MtGox::Client do
|
|
285
373
|
before do
|
286
374
|
body = test_body({"amount_int" => "100000000", "address" => "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"})
|
287
375
|
stub_post('/api/1/generic/bitcoin/send_simple').
|
288
|
-
with(body: body, headers: test_headers(body)).
|
289
|
-
to_return(
|
376
|
+
with(body: body, headers: test_headers(@client, body)).
|
377
|
+
to_return(body: fixture('withdraw.json'))
|
290
378
|
end
|
291
379
|
|
292
380
|
it "should withdraw funds" do
|
293
381
|
withdraw = @client.withdraw!(1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L")
|
294
382
|
body = test_body({"amount_int" => "100000000", "address" => "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"})
|
295
383
|
a_post("/api/1/generic/bitcoin/send_simple").
|
296
|
-
with(body: body, headers: test_headers(body)).
|
384
|
+
with(body: body, headers: test_headers(@client, body)).
|
297
385
|
should have_been_made
|
298
386
|
withdraw.should == "311295deadbeef390a13c038e2b8ba77feebdaed2c1a59e6e0bdf001656e1314"
|
299
387
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mtgox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
|
37
37
|
cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
|
38
38
|
cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
39
|
-
date: 2013-
|
39
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/mtgox/configuration.rb
|
117
117
|
- lib/mtgox/connection.rb
|
118
118
|
- lib/mtgox/error.rb
|
119
|
+
- lib/mtgox/lag.rb
|
119
120
|
- lib/mtgox/max_bid.rb
|
120
121
|
- lib/mtgox/min_ask.rb
|
121
122
|
- lib/mtgox/offer.rb
|
@@ -135,7 +136,9 @@ files:
|
|
135
136
|
- spec/fixtures/cancel.json
|
136
137
|
- spec/fixtures/depth.json
|
137
138
|
- spec/fixtures/error.json
|
139
|
+
- spec/fixtures/idkey.json
|
138
140
|
- spec/fixtures/info.json
|
141
|
+
- spec/fixtures/lag.json
|
139
142
|
- spec/fixtures/mysql_error
|
140
143
|
- spec/fixtures/orders.json
|
141
144
|
- spec/fixtures/sell.json
|
@@ -177,7 +180,9 @@ test_files:
|
|
177
180
|
- spec/fixtures/cancel.json
|
178
181
|
- spec/fixtures/depth.json
|
179
182
|
- spec/fixtures/error.json
|
183
|
+
- spec/fixtures/idkey.json
|
180
184
|
- spec/fixtures/info.json
|
185
|
+
- spec/fixtures/lag.json
|
181
186
|
- spec/fixtures/mysql_error
|
182
187
|
- spec/fixtures/orders.json
|
183
188
|
- spec/fixtures/sell.json
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
��O�^�(�QC@����Sf�q���5;��:�Ώ]�:��٩�̼��N^�vTR�l��6��>x�SI2VȘi������1�}\�����⧾��K�z
|
2
|
+
��L��=T���k���m|�A�U�$�� E��}>�\i*���s���m=����֍���v���~����o���E�&�1�fNn&P�Q�[��*�\_E���~�+V�_[s�(G(� ���Ǥ�y��\�
|
3
|
+
h��G�.��c�
|