mtgox 0.6.0 → 0.7.0
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 +1 -1
- data/lib/mtgox/balance.rb +10 -0
- data/lib/mtgox/buy.rb +6 -0
- data/lib/mtgox/client.rb +74 -56
- data/lib/mtgox/connection.rb +0 -2
- data/lib/mtgox/max_bid.rb +2 -24
- data/lib/mtgox/min_ask.rb +2 -24
- data/lib/mtgox/order.rb +14 -0
- data/lib/mtgox/price_ticker.rb +27 -0
- data/lib/mtgox/sell.rb +6 -0
- data/lib/mtgox/ticker.rb +10 -0
- data/lib/mtgox/trade.rb +13 -0
- data/lib/mtgox/version.rb +1 -1
- data/mtgox.gemspec +0 -2
- data/spec/mtgox/client_spec.rb +62 -26
- metadata +29 -44
data/README.md
CHANGED
data/lib/mtgox/buy.rb
ADDED
data/lib/mtgox/client.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
require 'faraday/error'
|
2
2
|
require 'mtgox/ask'
|
3
|
+
require 'mtgox/balance'
|
3
4
|
require 'mtgox/bid'
|
5
|
+
require 'mtgox/buy'
|
4
6
|
require 'mtgox/connection'
|
5
7
|
require 'mtgox/max_bid'
|
6
8
|
require 'mtgox/min_ask'
|
7
9
|
require 'mtgox/request'
|
10
|
+
require 'mtgox/sell'
|
11
|
+
require 'mtgox/ticker'
|
12
|
+
require 'mtgox/trade'
|
8
13
|
|
9
14
|
module MtGox
|
10
15
|
class Client
|
@@ -16,60 +21,65 @@ module MtGox
|
|
16
21
|
# Fetch the latest ticker data
|
17
22
|
#
|
18
23
|
# @authenticated false
|
19
|
-
# @return [
|
24
|
+
# @return [MtGox::Ticker]
|
20
25
|
# @example
|
21
|
-
# MtGox.ticker
|
26
|
+
# MtGox.ticker
|
22
27
|
def ticker
|
23
|
-
get('/code/data/ticker.php')['ticker']
|
28
|
+
ticker = get('/code/data/ticker.php')['ticker']
|
29
|
+
Ticker.instance.buy = ticker['buy'].to_f
|
30
|
+
Ticker.instance.high = ticker['high'].to_f
|
31
|
+
Ticker.instance.price = ticker['last'].to_f
|
32
|
+
Ticker.instance.low = ticker['low'].to_f
|
33
|
+
Ticker.instance.sell = ticker['sell'].to_f
|
34
|
+
Ticker.instance.volume = ticker['vol'].to_f
|
35
|
+
Ticker.instance
|
24
36
|
end
|
25
37
|
|
26
38
|
# Fetch both bids and asks in one call, for network efficiency
|
27
39
|
#
|
28
40
|
# @authenticated false
|
29
|
-
# @return [
|
41
|
+
# @return [Hash] with keys :asks and :asks, which contain arrays as described in {MtGox::Client#asks} and {MtGox::Clients#bids}
|
30
42
|
# @example
|
31
|
-
#
|
32
|
-
# offers.asks[0, 3]
|
33
|
-
# offers.bids[0, 3]
|
43
|
+
# MtGox.offers
|
34
44
|
def offers
|
35
45
|
offers = get('/code/data/getDepth.php')
|
36
|
-
|
46
|
+
asks = offers['asks'].sort_by do |ask|
|
37
47
|
ask[0].to_f
|
38
48
|
end.map! do |ask|
|
39
49
|
Ask.new(*ask)
|
40
50
|
end
|
41
|
-
|
51
|
+
bids = offers['bids'].sort_by do |bid|
|
42
52
|
-bid[0].to_f
|
43
53
|
end.map! do |bid|
|
44
54
|
Bid.new(*bid)
|
45
55
|
end
|
46
|
-
|
56
|
+
{:asks => asks, :bids => bids}
|
47
57
|
end
|
48
58
|
|
49
59
|
# Fetch open asks
|
50
60
|
#
|
51
61
|
# @authenticated false
|
52
|
-
# @return [Array<Ask>]
|
62
|
+
# @return [Array<MtGox::Ask>] an array of open asks, sorted in price ascending order
|
53
63
|
# @example
|
54
|
-
# MtGox.asks
|
64
|
+
# MtGox.asks
|
55
65
|
def asks
|
56
|
-
offers[
|
66
|
+
offers[:asks]
|
57
67
|
end
|
58
68
|
|
59
69
|
# Fetch open bids
|
60
70
|
#
|
61
71
|
# @authenticated false
|
62
|
-
# @return [Array<Bid>]
|
72
|
+
# @return [Array<MtGox::Bid>] an array of open bids, sorted in price descending order
|
63
73
|
# @example
|
64
|
-
# MtGox.bids
|
74
|
+
# MtGox.bids
|
65
75
|
def bids
|
66
|
-
offers[
|
76
|
+
offers[:bids]
|
67
77
|
end
|
68
78
|
|
69
79
|
# Fetch the lowest priced ask
|
70
80
|
#
|
71
81
|
# @authenticated false
|
72
|
-
# @return [MinAsk]
|
82
|
+
# @return [MtGox::MinAsk]
|
73
83
|
# @example
|
74
84
|
# MtGox.min_ask
|
75
85
|
def min_ask
|
@@ -82,7 +92,7 @@ module MtGox
|
|
82
92
|
# Fetch the highest priced bid
|
83
93
|
#
|
84
94
|
# @authenticated false
|
85
|
-
# @return [MinBid]
|
95
|
+
# @return [MtGox::MinBid]
|
86
96
|
# @example
|
87
97
|
# MtGox.max_bid
|
88
98
|
def max_bid
|
@@ -95,33 +105,31 @@ module MtGox
|
|
95
105
|
# Fetch recent trades
|
96
106
|
#
|
97
107
|
# @authenticated false
|
98
|
-
# @return [Array<
|
108
|
+
# @return [Array<MtGox::Trade>] an array of trades, sorted in chronological order
|
99
109
|
# @example
|
100
|
-
# MtGox.trades
|
110
|
+
# MtGox.trades
|
101
111
|
def trades
|
102
|
-
get('/code/data/getTrades.php').
|
103
|
-
trade
|
104
|
-
trade['date'] = Time.at(trade['date'])
|
105
|
-
trade['price'] = trade['price'].to_f
|
112
|
+
get('/code/data/getTrades.php').sort_by{|trade| trade['date']}.map do |trade|
|
113
|
+
Trade.new(trade)
|
106
114
|
end
|
107
115
|
end
|
108
116
|
|
109
|
-
# Fetch your balance
|
117
|
+
# Fetch your current balance
|
110
118
|
#
|
111
119
|
# @authenticated true
|
112
|
-
# @return [
|
120
|
+
# @return [Array<MtGox::Balance>]
|
113
121
|
# @example
|
114
|
-
# MtGox.balance
|
122
|
+
# MtGox.balance
|
115
123
|
def balance
|
116
|
-
post('/code/getFunds.php', pass_params)
|
124
|
+
parse_balance(post('/code/getFunds.php', pass_params))
|
117
125
|
end
|
118
126
|
|
119
127
|
# Fetch your open orders, both buys and sells, for network efficiency
|
120
128
|
#
|
121
129
|
# @authenticated true
|
122
|
-
# @return [
|
130
|
+
# @return [Hash] with keys :buys and :sells, which contain arrays as described in {MtGox::Client#buys} and {MtGox::Clients#sells}
|
123
131
|
# @example
|
124
|
-
# MtGox.orders
|
132
|
+
# MtGox.orders
|
125
133
|
def orders
|
126
134
|
parse_orders(post('/code/getOrders.php', pass_params)['orders'])
|
127
135
|
end
|
@@ -129,25 +137,21 @@ module MtGox
|
|
129
137
|
# Fetch your open buys
|
130
138
|
#
|
131
139
|
# @authenticated true
|
132
|
-
# @return [Array<
|
140
|
+
# @return [Array<MtGox::Buy>] an array of your open bids, sorted by date
|
133
141
|
# @example
|
134
|
-
# MtGox.buys
|
142
|
+
# MtGox.buys
|
135
143
|
def buys
|
136
|
-
orders
|
137
|
-
o['type'] == ORDER_TYPES[:buy]
|
138
|
-
end
|
144
|
+
orders[:buys]
|
139
145
|
end
|
140
146
|
|
141
147
|
# Fetch your open sells
|
142
148
|
#
|
143
149
|
# @authenticated true
|
144
|
-
# @return [Array<
|
150
|
+
# @return [Array<MtGox::Sell>] an array of your open asks, sorted by date
|
145
151
|
# @example
|
146
|
-
# MtGox.sells
|
152
|
+
# MtGox.sells
|
147
153
|
def sells
|
148
|
-
orders
|
149
|
-
o['type'] == ORDER_TYPES[:sell]
|
150
|
-
end
|
154
|
+
orders[:sells]
|
151
155
|
end
|
152
156
|
|
153
157
|
# Place a limit order to buy BTC
|
@@ -155,7 +159,7 @@ module MtGox
|
|
155
159
|
# @authenticated true
|
156
160
|
# @param amount [Numeric] the number of bitcoins to purchase
|
157
161
|
# @param price [Numeric] the bid price in US dollars
|
158
|
-
# @return [
|
162
|
+
# @return [Hash] with keys :buys and :sells, which contain arrays as described in {MtGox::Client#buys} and {MtGox::Clients#sells}
|
159
163
|
# @example
|
160
164
|
# # Buy one bitcoin for $0.011
|
161
165
|
# MtGox.buy! 1.0, 0.011
|
@@ -168,7 +172,7 @@ module MtGox
|
|
168
172
|
# @authenticated true
|
169
173
|
# @param amount [Numeric] the number of bitcoins to sell
|
170
174
|
# @param price [Numeric] the ask price in US dollars
|
171
|
-
# @return [
|
175
|
+
# @return [Hash] with keys :buys and :sells, which contain arrays as described in {MtGox::Client#buys} and {MtGox::Clients#sells}
|
172
176
|
# @example
|
173
177
|
# # Sell one bitcoin for $100
|
174
178
|
# MtGox.sell! 1.0, 100.0
|
@@ -181,29 +185,30 @@ module MtGox
|
|
181
185
|
# @authenticated true
|
182
186
|
# @overload cancel(oid)
|
183
187
|
# @param oid [String] an order ID
|
184
|
-
# @return
|
188
|
+
# @return [Hash] with keys :buys and :sells, which contain arrays as described in {MtGox::Client#buys} and {MtGox::Clients#sells}
|
185
189
|
# @example
|
186
190
|
# my_order = MtGox.orders.first
|
187
191
|
# MtGox.cancel my_order.oid
|
188
192
|
# MtGox.cancel 1234567890
|
189
193
|
# @overload cancel(order)
|
190
194
|
# @param order [Hash] a hash-like object, with keys `oid` - the order ID of the transaction to cancel and `type` - the type of order to cancel (`1` for sell or `2` for buy)
|
191
|
-
# @return
|
195
|
+
# @return [Hash] with keys :buys and :sells, which contain arrays as described in {MtGox::Client#buys} and {MtGox::Clients#sells}
|
192
196
|
# @example
|
193
197
|
# my_order = MtGox.orders.first
|
194
198
|
# MtGox.cancel my_order
|
195
|
-
# MtGox.cancel {
|
199
|
+
# MtGox.cancel {'oid' => '1234567890', 'type' => 2}
|
196
200
|
def cancel(args)
|
197
201
|
if args.is_a?(Hash)
|
198
202
|
order = args.delete_if{|k, v| !['oid', 'type'].include?(k.to_s)}
|
199
|
-
post('/code/cancelOrder.php', pass_params.merge(order))
|
203
|
+
parse_orders(post('/code/cancelOrder.php', pass_params.merge(order))['orders'])
|
200
204
|
else
|
201
|
-
|
205
|
+
orders = post('/code/getOrders.php', pass_params)['orders']
|
206
|
+
order = orders.find{|order| order['oid'] == args.to_s}
|
202
207
|
if order
|
203
208
|
order = order.delete_if{|k, v| !['oid', 'type'].include?(k.to_s)}
|
204
|
-
post('/code/cancelOrder.php', pass_params.merge(order))
|
209
|
+
parse_orders(post('/code/cancelOrder.php', pass_params.merge(order))['orders'])
|
205
210
|
else
|
206
|
-
raise Faraday::Error::ResourceNotFound, {:status => 404, :headers => {}, :body =>
|
211
|
+
raise Faraday::Error::ResourceNotFound, {:status => 404, :headers => {}, :body => 'Order not found.'}
|
207
212
|
end
|
208
213
|
end
|
209
214
|
end
|
@@ -213,22 +218,35 @@ module MtGox
|
|
213
218
|
# @authenticated true
|
214
219
|
# @param amount [Numeric] the number of bitcoins to withdraw
|
215
220
|
# @param btca [String] the bitcoin address to send to
|
216
|
-
# @return [Array<
|
221
|
+
# @return [Array<MtGox::Balance>]
|
217
222
|
# @example
|
218
223
|
# # Withdraw 1 BTC from your account
|
219
|
-
# MtGox.withdraw! 1.0,
|
224
|
+
# MtGox.withdraw! 1.0, '1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L'
|
220
225
|
def withdraw!(amount, btca)
|
221
|
-
post('/code/withdraw.php', pass_params.merge({:group1 =>
|
226
|
+
parse_balance(post('/code/withdraw.php', pass_params.merge({:group1 => 'BTC', :amount => amount, :btca => btca})))
|
222
227
|
end
|
223
228
|
|
224
229
|
private
|
225
230
|
|
231
|
+
def parse_balance(balance)
|
232
|
+
balances = []
|
233
|
+
balances << Balance.new('BTC', balance['btcs'])
|
234
|
+
balances << Balance.new('USD', balance['usds'])
|
235
|
+
balances
|
236
|
+
end
|
237
|
+
|
226
238
|
def parse_orders(orders)
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
239
|
+
buys = []
|
240
|
+
sells = []
|
241
|
+
orders.sort_by{|order| order['date']}.each do |order|
|
242
|
+
case order['type']
|
243
|
+
when ORDER_TYPES[:sell]
|
244
|
+
sells << Sell.new(order)
|
245
|
+
when ORDER_TYPES[:buy]
|
246
|
+
buys << Buy.new(order)
|
247
|
+
end
|
231
248
|
end
|
249
|
+
{:buys => buys, :sells => sells}
|
232
250
|
end
|
233
251
|
|
234
252
|
def pass_params
|
data/lib/mtgox/connection.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'faraday/request/url_encoded'
|
3
3
|
require 'faraday/response/raise_error'
|
4
|
-
require 'faraday/response/rashify'
|
5
4
|
require 'faraday/response/parse_json'
|
6
5
|
require 'faraday/response/raise_mtgox_error'
|
7
6
|
require 'faraday_middleware'
|
@@ -24,7 +23,6 @@ module MtGox
|
|
24
23
|
Faraday.new(options) do |connection|
|
25
24
|
connection.use Faraday::Request::UrlEncoded
|
26
25
|
connection.use Faraday::Response::RaiseError
|
27
|
-
connection.use Faraday::Response::Rashify
|
28
26
|
connection.use Faraday::Response::ParseJson
|
29
27
|
connection.use Faraday::Response::RaiseMtGoxError
|
30
28
|
connection.adapter(Faraday.default_adapter)
|
data/lib/mtgox/max_bid.rb
CHANGED
@@ -1,32 +1,10 @@
|
|
1
1
|
require 'mtgox/bid'
|
2
|
+
require 'mtgox/price_ticker'
|
2
3
|
require 'singleton'
|
3
4
|
|
4
5
|
module MtGox
|
5
6
|
class MaxBid < Bid
|
6
7
|
include Singleton
|
7
|
-
|
8
|
-
|
9
|
-
def price=(price)
|
10
|
-
@previous_price = @price
|
11
|
-
@price = price
|
12
|
-
end
|
13
|
-
|
14
|
-
def up?
|
15
|
-
price.to_f > previous_price.to_f
|
16
|
-
end
|
17
|
-
|
18
|
-
def down?
|
19
|
-
price.to_f < previous_price.to_f
|
20
|
-
end
|
21
|
-
|
22
|
-
def changed?
|
23
|
-
price.to_f != previous_price.to_f
|
24
|
-
end
|
25
|
-
|
26
|
-
def unchanged?
|
27
|
-
!changed?
|
28
|
-
end
|
29
|
-
alias :unch? :unchanged?
|
30
|
-
|
8
|
+
include PriceTicker
|
31
9
|
end
|
32
10
|
end
|
data/lib/mtgox/min_ask.rb
CHANGED
@@ -1,32 +1,10 @@
|
|
1
1
|
require 'mtgox/ask'
|
2
|
+
require 'mtgox/price_ticker'
|
2
3
|
require 'singleton'
|
3
4
|
|
4
5
|
module MtGox
|
5
6
|
class MinAsk < Ask
|
6
7
|
include Singleton
|
7
|
-
|
8
|
-
|
9
|
-
def price=(price)
|
10
|
-
@previous_price = @price
|
11
|
-
@price = price
|
12
|
-
end
|
13
|
-
|
14
|
-
def up?
|
15
|
-
price.to_f > previous_price.to_f
|
16
|
-
end
|
17
|
-
|
18
|
-
def down?
|
19
|
-
price.to_f < previous_price.to_f
|
20
|
-
end
|
21
|
-
|
22
|
-
def changed?
|
23
|
-
price.to_f != previous_price.to_f
|
24
|
-
end
|
25
|
-
|
26
|
-
def unchanged?
|
27
|
-
!changed?
|
28
|
-
end
|
29
|
-
alias :unch? :unchanged?
|
30
|
-
|
8
|
+
include PriceTicker
|
31
9
|
end
|
32
10
|
end
|
data/lib/mtgox/order.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'mtgox/offer'
|
2
|
+
|
3
|
+
module MtGox
|
4
|
+
class Order < Offer
|
5
|
+
attr_accessor :id, :date
|
6
|
+
|
7
|
+
def initialize(order={})
|
8
|
+
self.id = order['oid']
|
9
|
+
self.date = Time.at(order['date'].to_i)
|
10
|
+
self.amount = order['amount'].to_f
|
11
|
+
self.price = order['price'].to_f
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module MtGox
|
2
|
+
module PriceTicker
|
3
|
+
attr_reader :previous_price, :price
|
4
|
+
|
5
|
+
def price=(price)
|
6
|
+
@previous_price = @price
|
7
|
+
@price = price
|
8
|
+
end
|
9
|
+
|
10
|
+
def up?
|
11
|
+
price.to_f > previous_price.to_f
|
12
|
+
end
|
13
|
+
|
14
|
+
def down?
|
15
|
+
price.to_f < previous_price.to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
def changed?
|
19
|
+
price.to_f != previous_price.to_f
|
20
|
+
end
|
21
|
+
|
22
|
+
def unchanged?
|
23
|
+
!changed?
|
24
|
+
end
|
25
|
+
alias :unch? :unchanged?
|
26
|
+
end
|
27
|
+
end
|
data/lib/mtgox/sell.rb
ADDED
data/lib/mtgox/ticker.rb
ADDED
data/lib/mtgox/trade.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mtgox/order'
|
2
|
+
|
3
|
+
module MtGox
|
4
|
+
class Trade < Order
|
5
|
+
|
6
|
+
def initialize(trade={})
|
7
|
+
self.id = trade['tid'].to_i
|
8
|
+
self.date = Time.at(trade['date'].to_i)
|
9
|
+
self.amount = trade['amount'].to_f
|
10
|
+
self.price = trade['price'].to_f
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/mtgox/version.rb
CHANGED
data/mtgox.gemspec
CHANGED
@@ -25,7 +25,5 @@ Gem::Specification.new do |gem|
|
|
25
25
|
|
26
26
|
gem.add_runtime_dependency 'faraday', '~> 0.6.1'
|
27
27
|
gem.add_runtime_dependency 'faraday_middleware', '~> 0.6.3'
|
28
|
-
gem.add_runtime_dependency 'hashie', '~> 1.0.0'
|
29
28
|
gem.add_runtime_dependency 'multi_json', '~> 1.0.3'
|
30
|
-
gem.add_runtime_dependency 'rash', '~> 0.3.0'
|
31
29
|
end
|
data/spec/mtgox/client_spec.rb
CHANGED
@@ -17,8 +17,14 @@ describe MtGox::Client do
|
|
17
17
|
|
18
18
|
it "should fetch the ticker" do
|
19
19
|
ticker = @client.ticker
|
20
|
-
a_get('/code/data/ticker.php').
|
21
|
-
|
20
|
+
a_get('/code/data/ticker.php').
|
21
|
+
should have_been_made
|
22
|
+
ticker.buy.should == 26.4
|
23
|
+
ticker.sell.should == 26.6099
|
24
|
+
ticker.high.should == 28.678
|
25
|
+
ticker.low.should == 18.4
|
26
|
+
ticker.price.should == 26.5
|
27
|
+
ticker.volume.should == 80531.0
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
@@ -31,7 +37,8 @@ describe MtGox::Client do
|
|
31
37
|
describe '#asks' do
|
32
38
|
it "should fetch open asks" do
|
33
39
|
asks = @client.asks
|
34
|
-
a_get('/code/data/getDepth.php').
|
40
|
+
a_get('/code/data/getDepth.php').
|
41
|
+
should have_been_made
|
35
42
|
asks.last.price.should == 23.75
|
36
43
|
asks.last.eprice.should == 23.905385002516354
|
37
44
|
asks.last.amount.should == 50
|
@@ -47,7 +54,8 @@ describe MtGox::Client do
|
|
47
54
|
describe "#bids" do
|
48
55
|
it "should fetch open bids" do
|
49
56
|
bids = @client.bids
|
50
|
-
a_get('/code/data/getDepth.php').
|
57
|
+
a_get('/code/data/getDepth.php').
|
58
|
+
should have_been_made
|
51
59
|
bids.last.price.should == 14.62101
|
52
60
|
bids.last.eprice.should == 14.525973435000001
|
53
61
|
bids.last.amount.should == 5
|
@@ -62,20 +70,22 @@ describe MtGox::Client do
|
|
62
70
|
describe "#offers" do
|
63
71
|
it "should fetch both bids and asks, with only one call" do
|
64
72
|
offers = @client.offers
|
65
|
-
a_get('/code/data/getDepth.php').
|
66
|
-
|
67
|
-
offers
|
68
|
-
offers
|
69
|
-
offers.
|
70
|
-
offers
|
71
|
-
offers
|
73
|
+
a_get('/code/data/getDepth.php').
|
74
|
+
should have_been_made.once
|
75
|
+
offers[:asks].last.price.should == 23.75
|
76
|
+
offers[:asks].last.eprice.should == 23.905385002516354
|
77
|
+
offers[:asks].last.amount.should == 50
|
78
|
+
offers[:bids].last.price.should == 14.62101
|
79
|
+
offers[:bids].last.eprice.should == 14.525973435000001
|
80
|
+
offers[:bids].last.amount.should == 5
|
72
81
|
end
|
73
82
|
end
|
74
83
|
|
75
84
|
describe '#min_ask' do
|
76
85
|
it "should fetch the lowest priced ask" do
|
77
86
|
min_ask = @client.min_ask
|
78
|
-
a_get('/code/data/getDepth.php').
|
87
|
+
a_get('/code/data/getDepth.php').
|
88
|
+
should have_been_made.once
|
79
89
|
min_ask.price.should == 17.00009
|
80
90
|
min_ask.eprice.should == 17.11131353799698
|
81
91
|
min_ask.amount.should == 36.22894353
|
@@ -85,7 +95,8 @@ describe MtGox::Client do
|
|
85
95
|
describe '#max_bid' do
|
86
96
|
it "should fetch the highest priced bid" do
|
87
97
|
max_bid = @client.max_bid
|
88
|
-
a_get('/code/data/getDepth.php').
|
98
|
+
a_get('/code/data/getDepth.php').
|
99
|
+
should have_been_made.once
|
89
100
|
max_bid.price.should == 17.0
|
90
101
|
max_bid.eprice.should == 16.8895
|
91
102
|
max_bid.amount.should == 82.53875035
|
@@ -102,11 +113,12 @@ describe MtGox::Client do
|
|
102
113
|
|
103
114
|
it "should fetch trades" do
|
104
115
|
trades = @client.trades
|
105
|
-
a_get('/code/data/getTrades.php').
|
116
|
+
a_get('/code/data/getTrades.php').
|
117
|
+
should have_been_made
|
106
118
|
trades.last.date.should == Time.utc(2011, 6, 27, 18, 28, 8)
|
107
119
|
trades.last.price.should == 17.00009
|
108
120
|
trades.last.amount.should == 0.5
|
109
|
-
trades.last.
|
121
|
+
trades.last.id.should == 1309199288687054
|
110
122
|
end
|
111
123
|
|
112
124
|
it "should be sorted in chronological order" do
|
@@ -127,8 +139,10 @@ describe MtGox::Client do
|
|
127
139
|
a_post("/code/getFunds.php").
|
128
140
|
with(:body => {"name" => "my_name", "pass" => "my_password"}).
|
129
141
|
should have_been_made
|
130
|
-
balance.
|
131
|
-
balance.
|
142
|
+
balance.first.currency.should == "BTC"
|
143
|
+
balance.first.amount.should == 22.0
|
144
|
+
balance.last.currency.should == "USD"
|
145
|
+
balance.last.amount.should == 3.7
|
132
146
|
end
|
133
147
|
end
|
134
148
|
|
@@ -156,8 +170,8 @@ describe MtGox::Client do
|
|
156
170
|
a_post("/code/getOrders.php").
|
157
171
|
with(:body => {"name" => "my_name", "pass" => "my_password"}).
|
158
172
|
should have_been_made
|
159
|
-
sells.last.price.should ==
|
160
|
-
sells.last.date.should == Time.utc(2011, 6, 27, 18, 20,
|
173
|
+
sells.last.price.should == 99.0
|
174
|
+
sells.last.date.should == Time.utc(2011, 6, 27, 18, 20, 20)
|
161
175
|
end
|
162
176
|
end
|
163
177
|
|
@@ -167,8 +181,10 @@ describe MtGox::Client do
|
|
167
181
|
a_post("/code/getOrders.php").
|
168
182
|
with(:body => {"name" => "my_name", "pass" => "my_password"}).
|
169
183
|
should have_been_made
|
170
|
-
orders.last.price.should ==
|
171
|
-
orders.last.date.should == Time.utc(2011, 6, 27, 18, 20,
|
184
|
+
orders[:buys].last.price.should == 7.0
|
185
|
+
orders[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
|
186
|
+
orders[:sells].last.price.should == 99.0
|
187
|
+
orders[:sells].last.date.should == Time.utc(2011, 6, 27, 18, 20, 20)
|
172
188
|
end
|
173
189
|
end
|
174
190
|
end
|
@@ -181,10 +197,14 @@ describe MtGox::Client do
|
|
181
197
|
end
|
182
198
|
|
183
199
|
it "should place a bid" do
|
184
|
-
@client.buy!(0.88, 0.89)
|
200
|
+
buy = @client.buy!(0.88, 0.89)
|
185
201
|
a_post("/code/buyBTC.php").
|
186
202
|
with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "0.89"}).
|
187
203
|
should have_been_made
|
204
|
+
buy[:buys].last.price.should == 2.0
|
205
|
+
buy[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 26, 21)
|
206
|
+
buy[:sells].last.price.should == 99.0
|
207
|
+
buy[:sells].last.date.should == Time.utc(2011, 6, 27, 18, 20, 20)
|
188
208
|
end
|
189
209
|
end
|
190
210
|
|
@@ -196,10 +216,14 @@ describe MtGox::Client do
|
|
196
216
|
end
|
197
217
|
|
198
218
|
it "should place an ask" do
|
199
|
-
@client.sell!(0.88, 89.0)
|
219
|
+
sell = @client.sell!(0.88, 89.0)
|
200
220
|
a_post("/code/sellBTC.php").
|
201
221
|
with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "89.0"}).
|
202
222
|
should have_been_made
|
223
|
+
sell[:buys].last.price.should == 2.0
|
224
|
+
sell[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 26, 21)
|
225
|
+
sell[:sells].last.price.should == 200
|
226
|
+
sell[:sells].last.date.should == Time.utc(2011, 6, 27, 18, 27, 54)
|
203
227
|
end
|
204
228
|
end
|
205
229
|
|
@@ -215,13 +239,17 @@ describe MtGox::Client do
|
|
215
239
|
|
216
240
|
context "with a valid oid passed" do
|
217
241
|
it "should cancel an order" do
|
218
|
-
@client.cancel("bddd042c-e837-4a88-a92e-3b7c05e483df")
|
242
|
+
cancel = @client.cancel("bddd042c-e837-4a88-a92e-3b7c05e483df")
|
219
243
|
a_post("/code/getOrders.php").
|
220
244
|
with(:body => {"name" => "my_name", "pass" => "my_password"}).
|
221
245
|
should have_been_made.once
|
222
246
|
a_post('/code/cancelOrder.php').
|
223
247
|
with(:body => {"name" => "my_name", "pass" => "my_password", "oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"}).
|
224
248
|
should have_been_made
|
249
|
+
cancel[:buys].last.price.should == 7.0
|
250
|
+
cancel[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
|
251
|
+
cancel[:sells].last.price.should == 99.0
|
252
|
+
cancel[:sells].last.date.should == Time.utc(2011, 6, 27, 18, 20, 20)
|
225
253
|
end
|
226
254
|
end
|
227
255
|
|
@@ -235,10 +263,14 @@ describe MtGox::Client do
|
|
235
263
|
|
236
264
|
context "with an order passed" do
|
237
265
|
it "should cancel an order" do
|
238
|
-
@client.cancel({'oid' => "bddd042c-e837-4a88-a92e-3b7c05e483df", 'type' => 2})
|
266
|
+
cancel = @client.cancel({'oid' => "bddd042c-e837-4a88-a92e-3b7c05e483df", 'type' => 2})
|
239
267
|
a_post('/code/cancelOrder.php').
|
240
268
|
with(:body => {"name" => "my_name", "pass" => "my_password", "oid" => "bddd042c-e837-4a88-a92e-3b7c05e483df", "type" => "2"}).
|
241
269
|
should have_been_made
|
270
|
+
cancel[:buys].last.price.should == 7.0
|
271
|
+
cancel[:buys].last.date.should == Time.utc(2011, 6, 27, 18, 20, 38)
|
272
|
+
cancel[:sells].last.price.should == 99.0
|
273
|
+
cancel[:sells].last.date.should == Time.utc(2011, 6, 27, 18, 20, 20)
|
242
274
|
end
|
243
275
|
end
|
244
276
|
end
|
@@ -251,10 +283,14 @@ describe MtGox::Client do
|
|
251
283
|
end
|
252
284
|
|
253
285
|
it "should withdraw funds" do
|
254
|
-
@client.withdraw!(1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L")
|
286
|
+
withdraw = @client.withdraw!(1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L")
|
255
287
|
a_post("/code/withdraw.php").
|
256
288
|
with(:body => {"name" => "my_name", "pass" => "my_password", "group1" => "BTC", "amount" => "1.0", "btca" => "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"}).
|
257
289
|
should have_been_made
|
290
|
+
withdraw.first.currency.should == "BTC"
|
291
|
+
withdraw.first.amount.should == 9.0
|
292
|
+
withdraw.last.currency.should == "USD"
|
293
|
+
withdraw.last.amount.should == 64.59
|
258
294
|
end
|
259
295
|
end
|
260
296
|
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.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-14 00:00:00.000000000 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ZenTest
|
17
|
-
requirement: &
|
17
|
+
requirement: &70132543720480 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '4.5'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70132543720480
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: maruku
|
28
|
-
requirement: &
|
28
|
+
requirement: &70132543701720 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0.6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70132543701720
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rake
|
39
|
-
requirement: &
|
39
|
+
requirement: &70132543700940 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0.9'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70132543700940
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &70132543698220 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '2.6'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70132543698220
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: simplecov
|
61
|
-
requirement: &
|
61
|
+
requirement: &70132543697720 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0.4'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70132543697720
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: webmock
|
72
|
-
requirement: &
|
72
|
+
requirement: &70132543697000 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '1.6'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70132543697000
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: yard
|
83
|
-
requirement: &
|
83
|
+
requirement: &70132543696260 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0.7'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70132543696260
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: faraday
|
94
|
-
requirement: &
|
94
|
+
requirement: &70132543695520 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ~>
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: 0.6.1
|
100
100
|
type: :runtime
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *70132543695520
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: faraday_middleware
|
105
|
-
requirement: &
|
105
|
+
requirement: &70132543694360 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
@@ -110,21 +110,10 @@ dependencies:
|
|
110
110
|
version: 0.6.3
|
111
111
|
type: :runtime
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
114
|
-
- !ruby/object:Gem::Dependency
|
115
|
-
name: hashie
|
116
|
-
requirement: &70226142926600 !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
|
-
requirements:
|
119
|
-
- - ~>
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
version: 1.0.0
|
122
|
-
type: :runtime
|
123
|
-
prerelease: false
|
124
|
-
version_requirements: *70226142926600
|
113
|
+
version_requirements: *70132543694360
|
125
114
|
- !ruby/object:Gem::Dependency
|
126
115
|
name: multi_json
|
127
|
-
requirement: &
|
116
|
+
requirement: &70132543693700 !ruby/object:Gem::Requirement
|
128
117
|
none: false
|
129
118
|
requirements:
|
130
119
|
- - ~>
|
@@ -132,18 +121,7 @@ dependencies:
|
|
132
121
|
version: 1.0.3
|
133
122
|
type: :runtime
|
134
123
|
prerelease: false
|
135
|
-
version_requirements: *
|
136
|
-
- !ruby/object:Gem::Dependency
|
137
|
-
name: rash
|
138
|
-
requirement: &70226142925380 !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
|
-
requirements:
|
141
|
-
- - ~>
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
version: 0.3.0
|
144
|
-
type: :runtime
|
145
|
-
prerelease: false
|
146
|
-
version_requirements: *70226142925380
|
124
|
+
version_requirements: *70132543693700
|
147
125
|
description: Ruby wrapper for the Mt. Gox Trade API. Mt. Gox allows you to trade US
|
148
126
|
Dollars (USD) for Bitcoins (BTC) or Bitcoins for US Dollars.
|
149
127
|
email: sferik@gmail.com
|
@@ -164,7 +142,9 @@ files:
|
|
164
142
|
- lib/faraday/response/raise_mtgox_error.rb
|
165
143
|
- lib/mtgox.rb
|
166
144
|
- lib/mtgox/ask.rb
|
145
|
+
- lib/mtgox/balance.rb
|
167
146
|
- lib/mtgox/bid.rb
|
147
|
+
- lib/mtgox/buy.rb
|
168
148
|
- lib/mtgox/client.rb
|
169
149
|
- lib/mtgox/configuration.rb
|
170
150
|
- lib/mtgox/connection.rb
|
@@ -172,7 +152,12 @@ files:
|
|
172
152
|
- lib/mtgox/max_bid.rb
|
173
153
|
- lib/mtgox/min_ask.rb
|
174
154
|
- lib/mtgox/offer.rb
|
155
|
+
- lib/mtgox/order.rb
|
156
|
+
- lib/mtgox/price_ticker.rb
|
175
157
|
- lib/mtgox/request.rb
|
158
|
+
- lib/mtgox/sell.rb
|
159
|
+
- lib/mtgox/ticker.rb
|
160
|
+
- lib/mtgox/trade.rb
|
176
161
|
- lib/mtgox/version.rb
|
177
162
|
- mtgox.gemspec
|
178
163
|
- spec/faraday/response_spec.rb
|