mtgox 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -1
- data/README.md +11 -4
- data/Rakefile +4 -1
- data/lib/mtgox.rb +7 -0
- data/lib/mtgox/client.rb +144 -9
- data/lib/mtgox/request.rb +11 -1
- data/lib/mtgox/version.rb +1 -1
- data/spec/fixtures/buy.json +1 -0
- data/spec/fixtures/cancel.json +1 -0
- data/spec/fixtures/funds.json +1 -0
- data/spec/fixtures/orders.json +1 -0
- data/spec/fixtures/sell.json +1 -0
- data/spec/helper.rb +9 -0
- data/spec/mtgox/client_spec.rb +143 -16
- data/spec/mtgox_spec.rb +13 -0
- metadata +25 -20
data/.travis.yml
ADDED
data/.yardopts
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,13 @@ Installation
|
|
7
7
|
------------
|
8
8
|
gem install mtgox
|
9
9
|
|
10
|
+
Alias
|
11
|
+
-----
|
12
|
+
After installing the gem, you can get the current price for 1 BTC in USD by
|
13
|
+
typing `btc` in your bash shell simply by setting the following alias:
|
14
|
+
|
15
|
+
alias btc='ruby -r rubygems -r mtgox -e "puts MtGox.ticker.last"'
|
16
|
+
|
10
17
|
Documentation
|
11
18
|
-------------
|
12
19
|
[http://rdoc.info/gems/mtgox](http://rdoc.info/gems/mtgox)
|
@@ -55,16 +62,16 @@ Usage Examples
|
|
55
62
|
end
|
56
63
|
|
57
64
|
# Get your current balance
|
58
|
-
puts MtGox.balance
|
65
|
+
puts MtGox.balance
|
59
66
|
|
60
67
|
# Place an order to buy 1 BTC for 20 USD (returns a list of your open orders)
|
61
|
-
puts MtGox.buy 1.0, 20.0
|
68
|
+
puts MtGox.buy! 1.0, 20.0
|
62
69
|
|
63
70
|
# Place an order to sell 1 BTC for 20 USD (returns a list of your open orders)
|
64
|
-
puts MtGox.sell 1.0, 20.0
|
71
|
+
puts MtGox.sell! 1.0, 20.0
|
65
72
|
|
66
73
|
# Cancel order #1234567890
|
67
|
-
puts MtGox.cancel 1234567890
|
74
|
+
puts MtGox.cancel 1234567890
|
68
75
|
|
69
76
|
# Send 1 BTC to the author of this gem
|
70
77
|
puts MtGox.send 1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L" [TODO]
|
data/Rakefile
CHANGED
@@ -13,6 +13,9 @@ require 'yard'
|
|
13
13
|
namespace :doc do
|
14
14
|
YARD::Rake::YardocTask.new do |task|
|
15
15
|
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
16
|
-
task.options = [
|
16
|
+
task.options = [
|
17
|
+
'--tag', 'authenticated:Requires Authentication',
|
18
|
+
'--markup', 'markdown',
|
19
|
+
]
|
17
20
|
end
|
18
21
|
end
|
data/lib/mtgox.rb
CHANGED
data/lib/mtgox/client.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'faraday/error'
|
3
|
+
require 'rash'
|
1
4
|
require 'mtgox/connection'
|
2
5
|
require 'mtgox/request'
|
3
6
|
|
@@ -6,40 +9,172 @@ module MtGox
|
|
6
9
|
include MtGox::Connection
|
7
10
|
include MtGox::Request
|
8
11
|
|
12
|
+
ORDER_TYPES = {:sell => 1, :buy => 2}
|
13
|
+
|
9
14
|
# Fetch the latest ticker data
|
10
15
|
#
|
11
|
-
# @
|
16
|
+
# @authenticated false
|
17
|
+
# @return [Hashie::Rash] with keys `buy` - current highest bid price, `sell` - current lowest ask price, `high` - highest price trade for the day, `low` - lowest price trade for the day, `last` - price of most recent trade, and `vol`
|
12
18
|
# @example
|
13
|
-
# MtGox.ticker
|
19
|
+
# MtGox.ticker #=> <#Hashie::Rash buy=19.29 high=19.96 last=19.36 low=19.01 sell=19.375 vol=29470>
|
14
20
|
def ticker
|
15
21
|
get('/code/data/ticker.php')['ticker']
|
16
22
|
end
|
17
23
|
|
18
24
|
# Fetch open asks
|
19
25
|
#
|
20
|
-
# @
|
26
|
+
# @authenticated false
|
27
|
+
# @return [Array<Array<Numeric>>] in the form `[price, quantity]`, sorted in price ascending order
|
21
28
|
# @example
|
22
|
-
# MtGox.asks
|
29
|
+
# MtGox.asks[0, 3] #=> [[19.3898, 3.9], [19.4, 48.264], [19.409, 1]]
|
23
30
|
def asks
|
24
31
|
get('/code/data/getDepth.php')['asks']
|
25
32
|
end
|
26
33
|
|
27
34
|
# Fetch open bids
|
28
35
|
#
|
29
|
-
# @
|
36
|
+
# @authenticated false
|
37
|
+
# @return [Array<Array<Numeric>>] in the form `[price, quantity]`, sorted in price descending order
|
30
38
|
# @example
|
31
|
-
# MtGox.bids
|
39
|
+
# MtGox.bids[0, 3] #=> [[19.3898, 77.42], [19.3, 3.02], [19.29, 82.378]]
|
32
40
|
def bids
|
33
41
|
get('/code/data/getDepth.php')['bids']
|
34
42
|
end
|
35
43
|
|
44
|
+
# Fetch both bids and asks in one call, for network efficiency
|
45
|
+
#
|
46
|
+
# @authenticated false
|
47
|
+
# @return [Hashie::Rash] a hash with keys :asks and :bids, which contain arrays as described in #asks and #bids.
|
48
|
+
# @example
|
49
|
+
# offers = MtGox.offers
|
50
|
+
# offers.asks[0, 3] #=> [[19.3898, 3.9], [19.4, 48.264], [19.409, 1]]
|
51
|
+
# offers.bids[0, 3] #=> [[19.3898, 77.42], [19.3, 3.02], [19.29, 82.378]]
|
52
|
+
def offers
|
53
|
+
get('/code/data/getDepth.php')
|
54
|
+
end
|
55
|
+
|
36
56
|
# Fetch recent trades
|
37
57
|
#
|
38
|
-
# @
|
58
|
+
# @authenticated false
|
59
|
+
# @return [Array<Hashie::Rash>] an array of trades, sorted in chronological order. Each trade is a `Hashie::Rash` with keys `amount` - number of bitcoins traded, `price` - price they were traded at in US dollars, `date` - time and date of the trade (a `Time` object), and `tid` - the trade ID.
|
39
60
|
# @example
|
40
|
-
# MtGox.trades
|
61
|
+
# MtGox.trades[0, 3] #=> [<#Hashie::Rash amount=41 date=2011-06-14 11:26:32 -0700 price=18.5 tid="183747">, <#Hashie::Rash amount=5 date=2011-06-14 11:26:44 -0700 price=18.5 tid="183748">, <#Hashie::Rash amount=5 date=2011-06-14 11:27:00 -0700 price=18.42 tid="183749">]
|
41
62
|
def trades
|
42
|
-
get('/code/data/getTrades.php').each
|
63
|
+
get('/code/data/getTrades.php').each do |t|
|
64
|
+
t['date'] = Time.at(t['date'])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Fetch your balance
|
69
|
+
#
|
70
|
+
# @authenticated true
|
71
|
+
# @return [Hashie::Rash] with keys `btcs` - amount of bitcoins in your account and `usds` - amount of US dollars in your account
|
72
|
+
# @example
|
73
|
+
# MtGox.balance #=> <#Hashie::Rash btcs=3.7 usds=12>
|
74
|
+
def balance
|
75
|
+
post('/code/getFunds.php', pass_params)
|
43
76
|
end
|
77
|
+
|
78
|
+
# Fetch your open buys
|
79
|
+
#
|
80
|
+
# @authenticated true
|
81
|
+
# @return [Array<Hashie::Rash>] an array of your open bids, sorted in price ascending order with the keys `amount`, `dark`, `date`, `oid`, `price`, `status`, and `type`
|
82
|
+
# @example
|
83
|
+
# MtGox.buys[0, 3] #=> [<#Hashie::Rash amount=0.73 dark="0" date="1307949196" oid="929284" price=2 status=:active type=2>, <#Hashie::Rash amount=0.36 dark="0" date="1307949201" oid="929288" price=4 status=:active type=2>, <#Hashie::Rash amount=0.24 dark="0" date="1307949212" oid="929292" price=6 status=:active type=2>]
|
84
|
+
def buys
|
85
|
+
orders.select do |o|
|
86
|
+
o['type'] == ORDER_TYPES[:buy]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Fetch your open sells
|
91
|
+
#
|
92
|
+
# @authenticated true
|
93
|
+
# @return [Array<Hashie::Rash>] an array of your open asks, sorted in price ascending order with the keys `amount`, `dark`, `date`, `oid`, `price`, `status`, and `type`
|
94
|
+
# @example
|
95
|
+
# MtGox.sells[0, 3] #=> [<#Hashie::Rash amount=0.1 dark="0" date="1307949384" oid="663465" price=24.92 status=nil type=1>, <#Hashie::Rash amount=0.12 dark="0" date="1307949391" oid="663468" price=25.65 status=nil type=1>, <#Hashie::Rash amount=0.15 dark="0" date="1307949396" oid="663470" price=26.38 status=nil type=1>]
|
96
|
+
def sells
|
97
|
+
orders.select do |o|
|
98
|
+
o['type'] == ORDER_TYPES[:sell]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Fetch your open orders, both buys and sells, for network efficiency
|
103
|
+
#
|
104
|
+
# @authenticated true
|
105
|
+
# @return [<Hashie::Rash>] with keys `buy` and `sell`, which contain arrays as described in {MtGox::Client#buys} and {MtGox::Client#sells}
|
106
|
+
# @example
|
107
|
+
# MtGox.orders[0, 3] #=> [<#Hashie::Rash amount=0.73 dark="0" date="1307949196" oid="929284" price=2 status=:active type=2>, <#Hashie::Rash amount=0.36 dark="0" date="1307949201" oid="929288" price=4 status=:active type=2>, <#Hashie::Rash amount=0.24 dark="0" date="1307949212" oid="929292" price=6 status=:active type=2>]
|
108
|
+
def orders
|
109
|
+
hash = post('/code/getOrders.php', pass_params)['orders']
|
110
|
+
end
|
111
|
+
|
112
|
+
# Place an order to buy
|
113
|
+
#
|
114
|
+
# @todo Return something useful
|
115
|
+
# @authenticated true
|
116
|
+
# @param quantity [Numeric] the number of bitcoins to purchase
|
117
|
+
# @param price [Numeric] the bid price in US dollars
|
118
|
+
# @return [Array<Hashie::Rash>]
|
119
|
+
# @example
|
120
|
+
# # Buy one BTC for $25
|
121
|
+
# MtGox.buy! 1.0, 25.0
|
122
|
+
def buy!(quantity, price)
|
123
|
+
post('/code/buyBTC.php', pass_params.merge({:amount => quantity, :price => price}))
|
124
|
+
end
|
125
|
+
|
126
|
+
# Place an order to sell
|
127
|
+
#
|
128
|
+
# @todo Return something useful
|
129
|
+
# @authenticated true
|
130
|
+
# @param quantity [Numeric] the number of bitcoins to sell
|
131
|
+
# @param price [Numeric] the ask price in US dollars
|
132
|
+
# @return [Array<Hashie::Rash>]
|
133
|
+
# @example
|
134
|
+
# # Sell 0.7 BTC for $26
|
135
|
+
# MtGox.sell! 0.7, 26.0
|
136
|
+
def sell!(quantity, price)
|
137
|
+
post('/code/sellBTC.php', pass_params.merge({:amount => quantity, :price => price}))
|
138
|
+
end
|
139
|
+
|
140
|
+
# Cancel an open order
|
141
|
+
#
|
142
|
+
# @todo Return something useful
|
143
|
+
# @authenticated true
|
144
|
+
# @overload cancel(oid)
|
145
|
+
# @param oid [String] an order ID
|
146
|
+
# @return Array<Hashie::Rash>
|
147
|
+
# @example
|
148
|
+
# my_order = MtGox.orders.first
|
149
|
+
# MtGox.cancel my_order.oid
|
150
|
+
# MtGox.cancel 1234567890
|
151
|
+
# @overload cancel(order)
|
152
|
+
# @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)
|
153
|
+
# @return Array<Hashie::Rash>
|
154
|
+
# @example
|
155
|
+
# my_order = MtGox.orders.first
|
156
|
+
# MtGox.cancel my_order
|
157
|
+
# MtGox.cancel {"oid" => "1234567890", "type" => 2}
|
158
|
+
def cancel(args)
|
159
|
+
if args.is_a?(Hash)
|
160
|
+
order = args.select{|k, v| ['oid', 'type'].include?(k)}
|
161
|
+
post('/code/cancelOrder.php', pass_params.merge(order))
|
162
|
+
else
|
163
|
+
order = orders.select{|o| o['oid'] == args.to_s}.first
|
164
|
+
if order
|
165
|
+
order.select!{|k, v| ['oid', 'type'].include?(k)}
|
166
|
+
post('/code/cancelOrder.php', pass_params.merge(order))
|
167
|
+
else
|
168
|
+
raise Faraday::Error::ResourceNotFound, {:status => 404, :headers => {}, :body => "Order not found."}
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
def pass_params
|
176
|
+
{:name => MtGox.name, :pass => MtGox.pass}
|
177
|
+
end
|
178
|
+
|
44
179
|
end
|
45
180
|
end
|
data/lib/mtgox/request.rb
CHANGED
@@ -4,11 +4,21 @@ module MtGox
|
|
4
4
|
request(:get, path, options)
|
5
5
|
end
|
6
6
|
|
7
|
+
def post(path, options={})
|
8
|
+
request(:post, path, options)
|
9
|
+
end
|
10
|
+
|
7
11
|
private
|
8
12
|
|
9
13
|
def request(method, path, options)
|
10
14
|
response = connection.send(method) do |request|
|
11
|
-
|
15
|
+
case method
|
16
|
+
when :get
|
17
|
+
request.url(path, options)
|
18
|
+
when :post
|
19
|
+
request.path = path
|
20
|
+
request.body = options unless options.empty?
|
21
|
+
end
|
12
22
|
end
|
13
23
|
response.body
|
14
24
|
end
|
data/lib/mtgox/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"status":"<br>Your entire order can't be filled at that price. What remains is stored in your open orders.","usds":15.9,"btcs":0,"ticker":{"high":19.96,"low":19,"vol":32508,"buy":19.04,"sell":19.1},"orders":[{"oid":"982174","type":2,"amount":0.88,"price":0.89,"status":"1","dark":"0","date":"1308251182"}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"usds":15.9,"btcs":0,"orders":[{"oid":"929288","type":2,"amount":0.36,"price":4,"status":"1","dark":"0","date":"1307949201"},{"oid":"929292","type":2,"amount":0.24,"price":6,"status":"1","dark":"0","date":"1307949212"}],"ticker":{"high":19.96,"low":18.85,"vol":34831,"buy":18.8501,"sell":18.86}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"usds":3.7,"btcs":22}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"orders":[{"oid":"929284","type":2,"amount":0.73,"price":2,"status":"1","dark":"0","date":"1307949196"},{"oid":"929288","type":2,"amount":0.36,"price":4,"status":"1","dark":"0","date":"1307949201"},{"oid":"929292","type":2,"amount":0.24,"price":6,"status":"1","dark":"0","date":"1307949212"},{"oid":"929297","type":2,"amount":0.18,"price":8,"status":"1","dark":"0","date":"1307949220"},{"oid":"929301","type":2,"amount":0.15,"price":10,"status":"1","dark":"0","date":"1307949227"},{"oid":"929302","type":2,"amount":0.12,"price":12,"status":"1","dark":"0","date":"1307949230"},{"oid":"929308","type":2,"amount":0.1,"price":14,"status":"1","dark":"0","date":"1307949234"},{"oid":"663465","type":1,"amount":0.1,"price":24.92,"status":"2","dark":"0","date":"1307949384"},{"oid":"663468","type":1,"amount":0.12,"price":25.65,"status":"2","dark":"0","date":"1307949391"},{"oid":"663470","type":1,"amount":0.15,"price":26.38,"status":"2","dark":"0","date":"1307949396"},{"oid":"663471","type":1,"amount":0.18,"price":27.11,"status":"2","dark":"0","date":"1307949399"},{"oid":"663478","type":1,"amount":0.24,"price":27.84,"status":"2","dark":"0","date":"1307949407"},{"oid":"663479","type":1,"amount":0.36,"price":28.57,"status":"2","dark":"0","date":"1307949411"},{"oid":"663482","type":1,"amount":0.73,"price":29.3,"status":"2","dark":"0","date":"1307949416"}],"usds":15.9,"btcs":0}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"status":"<br>You don't have that much BTC. What remains is stored in your open orders.<br>Your entire order can't be filled at that price. What remains is stored in your open orders.","usds":15.9,"btcs":0,"ticker":{"high":19.96,"low":19,"vol":32982,"buy":19.06,"sell":19.1},"orders":[{"oid":"703257","type":1,"amount":1.76,"price":89,"status":"2","dark":"0","date":"1308252814"}]}
|
data/spec/helper.rb
CHANGED
@@ -14,6 +14,15 @@ def stub_get(path)
|
|
14
14
|
stub_request(:get, 'https://mtgox.com' + path)
|
15
15
|
end
|
16
16
|
|
17
|
+
def a_post(path)
|
18
|
+
a_request(:post, 'https://mtgox.com' + path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_post(path)
|
22
|
+
stub_request(:post, 'https://mtgox.com' + path)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
17
26
|
def fixture_path
|
18
27
|
File.expand_path('../fixtures', __FILE__)
|
19
28
|
end
|
data/spec/mtgox/client_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'helper'
|
|
3
3
|
describe MtGox::Client do
|
4
4
|
before do
|
5
5
|
@client = MtGox::Client.new
|
6
|
+
MtGox.configure {|c| c.name="my_name"; c.pass="my_password"}
|
6
7
|
end
|
7
8
|
|
8
9
|
describe '#ticker' do
|
@@ -18,30 +19,49 @@ describe MtGox::Client do
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
describe '
|
22
|
-
before do
|
22
|
+
describe 'depth methods' do
|
23
|
+
before :each do
|
23
24
|
stub_get('/code/data/getDepth.php').
|
24
25
|
to_return(:status => 200, :body => fixture('depth.json'))
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
describe '#asks' do
|
29
|
+
it "should fetch open asks" do
|
30
|
+
asks = @client.asks
|
31
|
+
a_get('/code/data/getDepth.php').should have_been_made
|
32
|
+
asks.last.should == [45, 593.28]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be sorted in price-ascending order" do
|
36
|
+
asks = @client.asks
|
37
|
+
asks.sort_by {|x| x[0]}.should == asks
|
38
|
+
end
|
39
|
+
|
31
40
|
end
|
32
|
-
end
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
describe "#bids" do
|
43
|
+
it "should fetch open bids" do
|
44
|
+
bids = @client.bids
|
45
|
+
a_get('/code/data/getDepth.php').should have_been_made
|
46
|
+
bids.last.should == [19.1, 1]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be sorted in price-descending order" do
|
50
|
+
bids = @client.bids
|
51
|
+
bids.sort_by {|x| x[0]}.reverse.should == bids
|
52
|
+
end
|
53
|
+
|
38
54
|
end
|
39
55
|
|
40
|
-
|
41
|
-
bids
|
42
|
-
|
43
|
-
|
56
|
+
describe "#offers" do
|
57
|
+
it "should fetch both bids and asks, making only 1 network request" do
|
58
|
+
offers = @client.offers
|
59
|
+
a_get('/code/data/getDepth.php').should have_been_made.once
|
60
|
+
offers.asks.last.should == [45, 593.28]
|
61
|
+
offers.bids.last.should == [19.1, 1]
|
62
|
+
end
|
44
63
|
end
|
64
|
+
|
45
65
|
end
|
46
66
|
|
47
67
|
describe '#trades' do
|
@@ -53,10 +73,117 @@ describe MtGox::Client do
|
|
53
73
|
it "should fetch trades" do
|
54
74
|
trades = @client.trades
|
55
75
|
a_get('/code/data/getTrades.php').should have_been_made
|
56
|
-
trades.last.date.should == Time.
|
76
|
+
trades.last.date.should == Time.utc(2011, 6, 8, 9, 51, 57)
|
57
77
|
trades.last.price.should == 26.6099
|
58
78
|
trades.last.amount.should == 1.37
|
59
79
|
trades.last.tid.should == "129606"
|
60
80
|
end
|
81
|
+
|
82
|
+
it "should be sorted in chronological order" do
|
83
|
+
trades = @client.trades
|
84
|
+
trades.sort_by(&:date).should == trades
|
85
|
+
end
|
61
86
|
end
|
87
|
+
|
88
|
+
describe '#balance' do
|
89
|
+
before do
|
90
|
+
stub_post('/code/getFunds.php').
|
91
|
+
to_return(:status => 200, :body => fixture('funds.json'))
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should fetch balance" do
|
95
|
+
balance = @client.balance
|
96
|
+
a_post("/code/getFunds.php").should have_been_made
|
97
|
+
balance.usds.should == 3.7
|
98
|
+
balance.btcs.should == 22.0
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "order methods" do
|
103
|
+
before :each do
|
104
|
+
stub_post('/code/getOrders.php').
|
105
|
+
to_return(:status => 200, :body => fixture('orders.json'))
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#buys" do
|
109
|
+
it "should fetch orders" do
|
110
|
+
buys = @client.buys
|
111
|
+
a_post("/code/getOrders.php").should have_been_made
|
112
|
+
buys.last.price.should == 14
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#sells" do
|
117
|
+
it "should fetch sells" do
|
118
|
+
sells = @client.sells
|
119
|
+
a_post("/code/getOrders.php").should have_been_made
|
120
|
+
sells.last.price.should == 29.3
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#buy!" do
|
126
|
+
before do
|
127
|
+
stub_post('/code/buyBTC.php').
|
128
|
+
to_return(:status => 200, :body => fixture('buy.json'))
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should place a bid" do
|
132
|
+
@client.buy!(0.88, 0.89)
|
133
|
+
a_post("/code/buyBTC.php").
|
134
|
+
with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "0.89"}).
|
135
|
+
should have_been_made
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#sell!" do
|
140
|
+
before do
|
141
|
+
stub_post('/code/sellBTC.php').
|
142
|
+
to_return(:status => 200, :body => fixture('sell.json'))
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should place an ask" do
|
146
|
+
@client.sell!(0.88, 89.0)
|
147
|
+
a_post("/code/sellBTC.php").
|
148
|
+
with(:body => {"name" => "my_name", "pass" => "my_password", "amount" => "0.88", "price" => "89.0"}).
|
149
|
+
should have_been_made
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#cancel" do
|
154
|
+
before do
|
155
|
+
stub_post('/code/getOrders.php').
|
156
|
+
to_return(:status => 200, :body => fixture('orders.json'))
|
157
|
+
stub_post('/code/cancelOrder.php').
|
158
|
+
to_return(:status => 200, :body => fixture('cancel.json'))
|
159
|
+
end
|
160
|
+
|
161
|
+
context "with a valid oid passed" do
|
162
|
+
it "should cancel an order" do
|
163
|
+
@client.cancel(929284)
|
164
|
+
a_post("/code/getOrders.php").should have_been_made.once
|
165
|
+
a_post('/code/cancelOrder.php').
|
166
|
+
with(:body => {"name" => "my_name", "pass" => "my_password", "oid" => "929284", "type" => "2"}).
|
167
|
+
should have_been_made
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "with an invalid oid passed" do
|
172
|
+
it "should raise an error" do
|
173
|
+
lambda do
|
174
|
+
@client.cancel(1234567890)
|
175
|
+
end.should raise_error(Faraday::Error::ResourceNotFound)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "with an order passed" do
|
180
|
+
it "should cancel an order" do
|
181
|
+
@client.cancel({'oid' => "929284", 'type' => 2})
|
182
|
+
a_post('/code/cancelOrder.php').
|
183
|
+
with(:body => {"name" => "my_name", "pass" => "my_password", "oid" => "929284", "type" => "2"}).
|
184
|
+
should have_been_made
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
62
189
|
end
|
data/spec/mtgox_spec.rb
CHANGED
@@ -6,4 +6,17 @@ describe MtGox do
|
|
6
6
|
MtGox.new.should be_a MtGox::Client
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
describe ".configure" do
|
11
|
+
it "should set 'name' and 'pass'" do
|
12
|
+
MtGox.configure do |c|
|
13
|
+
c.name="username"
|
14
|
+
c.pass="password"
|
15
|
+
end
|
16
|
+
|
17
|
+
MtGox.name.should == "username"
|
18
|
+
MtGox.pass.should == "password"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
9
22
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mtgox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Erik Michaels-Ober
|
@@ -10,11 +10,12 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-18 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: ZenTest
|
18
|
+
prerelease: false
|
18
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
20
|
none: false
|
20
21
|
requirements:
|
@@ -22,10 +23,10 @@ dependencies:
|
|
22
23
|
- !ruby/object:Gem::Version
|
23
24
|
version: "4.5"
|
24
25
|
type: :development
|
25
|
-
prerelease: false
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: maruku
|
29
|
+
prerelease: false
|
29
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
31
|
none: false
|
31
32
|
requirements:
|
@@ -33,10 +34,10 @@ dependencies:
|
|
33
34
|
- !ruby/object:Gem::Version
|
34
35
|
version: "0.6"
|
35
36
|
type: :development
|
36
|
-
prerelease: false
|
37
37
|
version_requirements: *id002
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rake
|
40
|
+
prerelease: false
|
40
41
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
42
|
none: false
|
42
43
|
requirements:
|
@@ -44,10 +45,10 @@ dependencies:
|
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: "0.9"
|
46
47
|
type: :development
|
47
|
-
prerelease: false
|
48
48
|
version_requirements: *id003
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rspec
|
51
|
+
prerelease: false
|
51
52
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
53
|
none: false
|
53
54
|
requirements:
|
@@ -55,10 +56,10 @@ dependencies:
|
|
55
56
|
- !ruby/object:Gem::Version
|
56
57
|
version: "2.6"
|
57
58
|
type: :development
|
58
|
-
prerelease: false
|
59
59
|
version_requirements: *id004
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: simplecov
|
62
|
+
prerelease: false
|
62
63
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
64
|
none: false
|
64
65
|
requirements:
|
@@ -66,10 +67,10 @@ dependencies:
|
|
66
67
|
- !ruby/object:Gem::Version
|
67
68
|
version: "0.4"
|
68
69
|
type: :development
|
69
|
-
prerelease: false
|
70
70
|
version_requirements: *id005
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: webmock
|
73
|
+
prerelease: false
|
73
74
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
75
|
none: false
|
75
76
|
requirements:
|
@@ -77,10 +78,10 @@ dependencies:
|
|
77
78
|
- !ruby/object:Gem::Version
|
78
79
|
version: "1.6"
|
79
80
|
type: :development
|
80
|
-
prerelease: false
|
81
81
|
version_requirements: *id006
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: yard
|
84
|
+
prerelease: false
|
84
85
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
86
|
none: false
|
86
87
|
requirements:
|
@@ -88,10 +89,10 @@ dependencies:
|
|
88
89
|
- !ruby/object:Gem::Version
|
89
90
|
version: "0.7"
|
90
91
|
type: :development
|
91
|
-
prerelease: false
|
92
92
|
version_requirements: *id007
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: faraday
|
95
|
+
prerelease: false
|
95
96
|
requirement: &id008 !ruby/object:Gem::Requirement
|
96
97
|
none: false
|
97
98
|
requirements:
|
@@ -99,10 +100,10 @@ dependencies:
|
|
99
100
|
- !ruby/object:Gem::Version
|
100
101
|
version: 0.6.1
|
101
102
|
type: :runtime
|
102
|
-
prerelease: false
|
103
103
|
version_requirements: *id008
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: faraday_middleware
|
106
|
+
prerelease: false
|
106
107
|
requirement: &id009 !ruby/object:Gem::Requirement
|
107
108
|
none: false
|
108
109
|
requirements:
|
@@ -110,10 +111,10 @@ dependencies:
|
|
110
111
|
- !ruby/object:Gem::Version
|
111
112
|
version: 0.6.3
|
112
113
|
type: :runtime
|
113
|
-
prerelease: false
|
114
114
|
version_requirements: *id009
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: hashie
|
117
|
+
prerelease: false
|
117
118
|
requirement: &id010 !ruby/object:Gem::Requirement
|
118
119
|
none: false
|
119
120
|
requirements:
|
@@ -121,10 +122,10 @@ dependencies:
|
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: 1.0.0
|
123
124
|
type: :runtime
|
124
|
-
prerelease: false
|
125
125
|
version_requirements: *id010
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: multi_json
|
128
|
+
prerelease: false
|
128
129
|
requirement: &id011 !ruby/object:Gem::Requirement
|
129
130
|
none: false
|
130
131
|
requirements:
|
@@ -132,10 +133,10 @@ dependencies:
|
|
132
133
|
- !ruby/object:Gem::Version
|
133
134
|
version: 1.0.3
|
134
135
|
type: :runtime
|
135
|
-
prerelease: false
|
136
136
|
version_requirements: *id011
|
137
137
|
- !ruby/object:Gem::Dependency
|
138
138
|
name: rash
|
139
|
+
prerelease: false
|
139
140
|
requirement: &id012 !ruby/object:Gem::Requirement
|
140
141
|
none: false
|
141
142
|
requirements:
|
@@ -143,7 +144,6 @@ dependencies:
|
|
143
144
|
- !ruby/object:Gem::Version
|
144
145
|
version: 0.3.0
|
145
146
|
type: :runtime
|
146
|
-
prerelease: false
|
147
147
|
version_requirements: *id012
|
148
148
|
description: Ruby wrapper for the Mt. Gox Trade API. Mt. Gox allows you to trade US Dollars (USD) for Bitcoins (BTC) or Bitcoins for US Dollars.
|
149
149
|
email: sferik@gmail.com
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- .gemtest
|
159
159
|
- .gitignore
|
160
160
|
- .rspec
|
161
|
+
- .travis.yml
|
161
162
|
- .yardopts
|
162
163
|
- Gemfile
|
163
164
|
- LICENSE.md
|
@@ -169,7 +170,12 @@ files:
|
|
169
170
|
- lib/mtgox/request.rb
|
170
171
|
- lib/mtgox/version.rb
|
171
172
|
- mtgox.gemspec
|
173
|
+
- spec/fixtures/buy.json
|
174
|
+
- spec/fixtures/cancel.json
|
172
175
|
- spec/fixtures/depth.json
|
176
|
+
- spec/fixtures/funds.json
|
177
|
+
- spec/fixtures/orders.json
|
178
|
+
- spec/fixtures/sell.json
|
173
179
|
- spec/fixtures/ticker.json
|
174
180
|
- spec/fixtures/trades.json
|
175
181
|
- spec/helper.rb
|
@@ -189,18 +195,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
195
|
requirements:
|
190
196
|
- - ">="
|
191
197
|
- !ruby/object:Gem::Version
|
192
|
-
hash: 2606027603205718995
|
193
|
-
segments:
|
194
|
-
- 0
|
195
198
|
version: "0"
|
196
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
200
|
none: false
|
198
201
|
requirements:
|
199
202
|
- - ">="
|
200
203
|
- !ruby/object:Gem::Version
|
201
|
-
hash: 2606027603205718995
|
202
|
-
segments:
|
203
|
-
- 0
|
204
204
|
version: "0"
|
205
205
|
requirements: []
|
206
206
|
|
@@ -210,7 +210,12 @@ signing_key:
|
|
210
210
|
specification_version: 3
|
211
211
|
summary: Ruby wrapper for the Mt. Gox Trade API
|
212
212
|
test_files:
|
213
|
+
- spec/fixtures/buy.json
|
214
|
+
- spec/fixtures/cancel.json
|
213
215
|
- spec/fixtures/depth.json
|
216
|
+
- spec/fixtures/funds.json
|
217
|
+
- spec/fixtures/orders.json
|
218
|
+
- spec/fixtures/sell.json
|
214
219
|
- spec/fixtures/ticker.json
|
215
220
|
- spec/fixtures/trades.json
|
216
221
|
- spec/helper.rb
|