mtgox 1.0.0 → 1.1.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.tar.gz.sig +0 -0
- data/README.md +4 -1
- data/lib/mtgox/client.rb +11 -0
- data/lib/mtgox/configuration.rb +8 -2
- data/lib/mtgox/order_result.rb +49 -0
- data/lib/mtgox/request.rb +1 -1
- data/lib/mtgox/version.rb +1 -1
- data/spec/fixtures/order_result.json +60 -0
- data/spec/helper.rb +1 -1
- data/spec/mtgox/client_spec.rb +37 -0
- data/spec/mtgox/order_result_spec.rb +34 -0
- data/spec/mtgox_spec.rb +8 -0
- metadata +7 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ To ensure the code you're installing hasn't been tampered with, it's
|
|
22
22
|
recommended that you verify the signature. To do this, you need to add my
|
23
23
|
public key as a trusted certificate (you only need to do this once):
|
24
24
|
|
25
|
-
gem cert --add <(curl -Ls https://
|
25
|
+
gem cert --add <(curl -Ls https://raw.github.com/sferik/mtgox/master/certs/sferik.pem)
|
26
26
|
|
27
27
|
Then, install the gem with the high security trust policy:
|
28
28
|
|
@@ -81,6 +81,9 @@ MtGox.cancel 1234567890
|
|
81
81
|
|
82
82
|
# Withdraw 1 BTC from your account
|
83
83
|
MtGox.withdraw! 1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"
|
84
|
+
|
85
|
+
# Switch to sending 'tonce' rather than 'nonce'
|
86
|
+
MtGox.nonce_type = :tonce
|
84
87
|
```
|
85
88
|
|
86
89
|
## Contributing
|
data/lib/mtgox/client.rb
CHANGED
@@ -13,6 +13,7 @@ require 'mtgox/trade'
|
|
13
13
|
require 'mtgox/value'
|
14
14
|
require 'mtgox/lag'
|
15
15
|
require 'mtgox/configuration'
|
16
|
+
require 'mtgox/order_result'
|
16
17
|
|
17
18
|
module MtGox
|
18
19
|
class Client
|
@@ -291,6 +292,16 @@ module MtGox
|
|
291
292
|
end
|
292
293
|
end
|
293
294
|
|
295
|
+
# Fetch information about a particular transaction
|
296
|
+
#
|
297
|
+
# @authenticated true
|
298
|
+
# @param offer_type [String] 'bid' or 'ask'
|
299
|
+
# @param order_id [String] the order id
|
300
|
+
# @return [OrderResult]
|
301
|
+
def order_result(offer_type, order_id)
|
302
|
+
OrderResult.new(post('/api/1/generic/order/result', {type: offer_type, order: order_id}))
|
303
|
+
end
|
304
|
+
|
294
305
|
private
|
295
306
|
|
296
307
|
def parse_balance(info)
|
data/lib/mtgox/configuration.rb
CHANGED
@@ -8,9 +8,11 @@ module MtGox
|
|
8
8
|
:commission,
|
9
9
|
:key,
|
10
10
|
:secret,
|
11
|
+
:nonce_type
|
11
12
|
]
|
12
13
|
|
13
14
|
DEFAULT_COMMISSION = BigDecimal('0.0065').freeze
|
15
|
+
DEFAULT_NONCE_TYPE = :nonce
|
14
16
|
|
15
17
|
attr_accessor *VALID_OPTIONS_KEYS
|
16
18
|
|
@@ -27,9 +29,13 @@ module MtGox
|
|
27
29
|
# Reset all configuration options to defaults
|
28
30
|
def reset
|
29
31
|
self.commission = DEFAULT_COMMISSION
|
30
|
-
self.key
|
31
|
-
self.secret
|
32
|
+
self.key = nil
|
33
|
+
self.secret = nil
|
32
34
|
self
|
33
35
|
end
|
36
|
+
|
37
|
+
def nonce_type
|
38
|
+
@nonce_type || DEFAULT_NONCE_TYPE
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module MtGox
|
2
|
+
class OrderResult
|
3
|
+
include Value
|
4
|
+
|
5
|
+
def initialize(json)
|
6
|
+
@json = json
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
@json["order_id"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def trades
|
14
|
+
@json["trades"].map{|t| Trade.new(coerce_trade(t)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def total_spent
|
18
|
+
to_decimal "total_spent", @json
|
19
|
+
end
|
20
|
+
|
21
|
+
def total_amount
|
22
|
+
to_decimal "total_amount", @json
|
23
|
+
end
|
24
|
+
|
25
|
+
def avg_cost
|
26
|
+
to_decimal "avg_cost", @json
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def to_decimal(key, json)
|
32
|
+
data = json.fetch(key)
|
33
|
+
decimalify(data["value_int"], currency_lookup[data["currency"]])
|
34
|
+
end
|
35
|
+
|
36
|
+
def currency_lookup
|
37
|
+
{ "USD" => :usd, "BTC" => :btc, "JPY" => :jpy }
|
38
|
+
end
|
39
|
+
|
40
|
+
def coerce_trade(hash)
|
41
|
+
{
|
42
|
+
"tid" => hash["trade_id"],
|
43
|
+
"date" => Time.parse(hash["date"] + " UTC"),
|
44
|
+
"amount" => to_decimal("amount", hash).to_s,
|
45
|
+
"price" => to_decimal("price", hash).to_s
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/mtgox/request.rb
CHANGED
data/lib/mtgox/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
{
|
2
|
+
"result":"success",
|
3
|
+
"return":
|
4
|
+
{
|
5
|
+
"order_id":"Zda8917a-63d3-4415-b827-758408013691",
|
6
|
+
"trades":[
|
7
|
+
{
|
8
|
+
"trade_id":"1375134017519310",
|
9
|
+
"primary":"Y",
|
10
|
+
"currency":"USD",
|
11
|
+
"type":"ask",
|
12
|
+
"properties":"limit",
|
13
|
+
"item":"BTC",
|
14
|
+
"amount":{
|
15
|
+
"value":"0.10000000",
|
16
|
+
"value_int":"10000000",
|
17
|
+
"display":"0.10000000 BTC",
|
18
|
+
"display_short":"0.10 BTC",
|
19
|
+
"currency":"BTC"
|
20
|
+
},
|
21
|
+
"price":{
|
22
|
+
"value":"100.83227",
|
23
|
+
"value_int":"10083227",
|
24
|
+
"display":"$100.83227",
|
25
|
+
"display_short":"$100.83",
|
26
|
+
"currency":"USD"
|
27
|
+
},
|
28
|
+
"spent":{
|
29
|
+
"value":"10.08323",
|
30
|
+
"value_int":"1008323",
|
31
|
+
"display":"$10.08323",
|
32
|
+
"display_short":"$10.08",
|
33
|
+
"currency":"USD"
|
34
|
+
},
|
35
|
+
"date":"2013-07-29 21:40:17"
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"total_amount":{
|
39
|
+
"value":"0.10000000",
|
40
|
+
"value_int":"10000000",
|
41
|
+
"display":"0.10000000 BTC",
|
42
|
+
"display_short":"0.10 BTC",
|
43
|
+
"currency":"BTC"
|
44
|
+
},
|
45
|
+
"total_spent":{
|
46
|
+
"value":"10.08323",
|
47
|
+
"value_int":"1008323",
|
48
|
+
"display":"$10.08323",
|
49
|
+
"display_short":"$10.08",
|
50
|
+
"currency":"USD"
|
51
|
+
},
|
52
|
+
"avg_cost":{
|
53
|
+
"value":"100.83230",
|
54
|
+
"value_int":"10083230",
|
55
|
+
"display":"$100.83230",
|
56
|
+
"display_short":"$100.83",
|
57
|
+
"currency":"USD"
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
data/spec/helper.rb
CHANGED
data/spec/mtgox/client_spec.rb
CHANGED
@@ -358,4 +358,41 @@ describe MtGox::Client do
|
|
358
358
|
}.to raise_error(MtGox::FilthyRichError)
|
359
359
|
end
|
360
360
|
end
|
361
|
+
|
362
|
+
describe "nonce_type" do
|
363
|
+
before do
|
364
|
+
stub_post('/api/1/generic/bitcoin/address').
|
365
|
+
to_return(body: fixture('address.json'))
|
366
|
+
end
|
367
|
+
|
368
|
+
it "uses nonce by default" do
|
369
|
+
address = @client.address
|
370
|
+
expect(a_post('/api/1/generic/bitcoin/address').with(nonce: 1321745961249676)).to have_been_made
|
371
|
+
end
|
372
|
+
|
373
|
+
it "is capable of using tonce" do
|
374
|
+
@client.nonce_type = :tonce
|
375
|
+
address = @client.address
|
376
|
+
expect(a_post('/api/1/generic/bitcoin/address').with(tonce: 1321745961249676)).to have_been_made
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
describe "#order_result" do
|
381
|
+
context "for a valid order id" do
|
382
|
+
let(:order_id) { "Zda8917a-63d3-4415-b827-758408013691" }
|
383
|
+
let(:body) { test_body({"type" => "bid", "order" => order_id}) }
|
384
|
+
|
385
|
+
before do
|
386
|
+
stub_post('/api/1/generic/order/result').
|
387
|
+
with(body: body, headers: test_headers(@client, body)).
|
388
|
+
to_return(body: fixture('order_result.json'))
|
389
|
+
end
|
390
|
+
|
391
|
+
it "returns an order result" do
|
392
|
+
order_result = @client.order_result("bid", order_id)
|
393
|
+
expect(a_post("/api/1/generic/order/result").with(body: body, headers: test_headers(@client, body))).to have_been_made
|
394
|
+
expect(order_result.id).to eq order_id
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
361
398
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe MtGox::OrderResult do
|
4
|
+
let(:json) { JSON.parse(File.read(fixture("order_result.json")))["return"] }
|
5
|
+
subject { described_class.new(json) }
|
6
|
+
|
7
|
+
describe '#total_spent' do
|
8
|
+
it "returns a decimal" do
|
9
|
+
expect(subject.total_spent).to eq BigDecimal.new('10.08323')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#total_amount' do
|
14
|
+
it "returns a decimal" do
|
15
|
+
expect(subject.total_amount).to eq BigDecimal.new('0.10')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#avg_cost' do
|
20
|
+
it "returns a decimal" do
|
21
|
+
expect(subject.avg_cost).to eq BigDecimal.new('100.83230')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#trades" do
|
26
|
+
it "returns an array of Trade objects" do
|
27
|
+
trade = subject.trades.first
|
28
|
+
expect(trade.id).to eq 1375134017519310
|
29
|
+
expect(trade.date).to eq Time.parse('2013-07-29 21:40:17 UTC')
|
30
|
+
expect(trade.amount).to eq BigDecimal.new("0.10000000")
|
31
|
+
expect(trade.price).to eq BigDecimal.new("100.83227")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/mtgox_spec.rb
CHANGED
@@ -17,6 +17,14 @@ describe MtGox do
|
|
17
17
|
expect(MtGox.key).to eq "key"
|
18
18
|
expect(MtGox.secret).to eq "secret"
|
19
19
|
end
|
20
|
+
|
21
|
+
it "allows setting nonce type" do
|
22
|
+
expect(MtGox.nonce_type).to eq(:nonce)
|
23
|
+
MtGox.configure do |config|
|
24
|
+
config.nonce_type = :tonce
|
25
|
+
end
|
26
|
+
expect(MtGox.nonce_type).to eq(:tonce)
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
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: 1.
|
4
|
+
version: 1.1.0
|
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-08-06 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/mtgox/min_ask.rb
|
128
128
|
- lib/mtgox/offer.rb
|
129
129
|
- lib/mtgox/order.rb
|
130
|
+
- lib/mtgox/order_result.rb
|
130
131
|
- lib/mtgox/price_ticker.rb
|
131
132
|
- lib/mtgox/request.rb
|
132
133
|
- lib/mtgox/response/parse_json.rb
|
@@ -146,6 +147,7 @@ files:
|
|
146
147
|
- spec/fixtures/info.json
|
147
148
|
- spec/fixtures/lag.json
|
148
149
|
- spec/fixtures/mysql_error
|
150
|
+
- spec/fixtures/order_result.json
|
149
151
|
- spec/fixtures/orders.json
|
150
152
|
- spec/fixtures/sell.json
|
151
153
|
- spec/fixtures/ticker.json
|
@@ -154,6 +156,7 @@ files:
|
|
154
156
|
- spec/fixtures/withdraw.json
|
155
157
|
- spec/helper.rb
|
156
158
|
- spec/mtgox/client_spec.rb
|
159
|
+
- spec/mtgox/order_result_spec.rb
|
157
160
|
- spec/mtgox_spec.rb
|
158
161
|
homepage: https://github.com/sferik/mtgox
|
159
162
|
licenses: []
|
@@ -190,6 +193,7 @@ test_files:
|
|
190
193
|
- spec/fixtures/info.json
|
191
194
|
- spec/fixtures/lag.json
|
192
195
|
- spec/fixtures/mysql_error
|
196
|
+
- spec/fixtures/order_result.json
|
193
197
|
- spec/fixtures/orders.json
|
194
198
|
- spec/fixtures/sell.json
|
195
199
|
- spec/fixtures/ticker.json
|
@@ -198,5 +202,6 @@ test_files:
|
|
198
202
|
- spec/fixtures/withdraw.json
|
199
203
|
- spec/helper.rb
|
200
204
|
- spec/mtgox/client_spec.rb
|
205
|
+
- spec/mtgox/order_result_spec.rb
|
201
206
|
- spec/mtgox_spec.rb
|
202
207
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|