guten-mtgox 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +41 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/.yardopts +4 -0
- data/Gemfile +24 -0
- data/LICENSE.md +20 -0
- data/README.md +69 -0
- data/Rakefile +21 -0
- data/lib/mtgox.rb +49 -0
- data/lib/mtgox/ask.rb +20 -0
- data/lib/mtgox/base.rb +28 -0
- data/lib/mtgox/client.rb +64 -0
- data/lib/mtgox/configuration.rb +39 -0
- data/lib/mtgox/connection.rb +30 -0
- data/lib/mtgox/depth.rb +13 -0
- data/lib/mtgox/me.rb +30 -0
- data/lib/mtgox/order.rb +25 -0
- data/lib/mtgox/request.rb +46 -0
- data/lib/mtgox/response/raise_mtgox_error.rb +13 -0
- data/lib/mtgox/ticker.rb +49 -0
- data/lib/mtgox/trade.rb +29 -0
- data/lib/mtgox/version.rb +3 -0
- data/mtgox.gemspec +19 -0
- data/mtgox.watchr +22 -0
- data/response/raise_mtgox_error_spec.rb +14 -0
- data/spec/fixtures/add.json +1 -0
- data/spec/fixtures/depth.json +20439 -0
- data/spec/fixtures/id_key.json +1 -0
- data/spec/fixtures/info.json +73 -0
- data/spec/fixtures/orders.json +23 -0
- data/spec/fixtures/ticker.json +1 -0
- data/spec/fixtures/trades.json +34454 -0
- data/spec/mtgox/base_spec.rb +18 -0
- data/spec/mtgox/client_spec.rb +111 -0
- data/spec/mtgox/me_spec.rb +71 -0
- data/spec/mtgox_spec.rb +21 -0
- data/spec/spec_helper.rb +70 -0
- metadata +163 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class MyBase < MtGox::Base
|
4
|
+
attr_accessor :foo, :bar
|
5
|
+
end
|
6
|
+
|
7
|
+
describe MtGox::Base do
|
8
|
+
before :each do
|
9
|
+
@base = MyBase.new(foo: 1, bar: 2)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#inspect" do
|
13
|
+
it "works" do
|
14
|
+
@base.inspect.should =~ /#<.* @foo=1, @bar=2>/
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class MtGox::Client
|
4
|
+
public :currency_name
|
5
|
+
end
|
6
|
+
|
7
|
+
describe MtGox::Client do
|
8
|
+
before do
|
9
|
+
@client = MtGox::Client.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "currency_name" do
|
13
|
+
it "works" do
|
14
|
+
@client.currency_name(:usd).should == "BTCUSD"
|
15
|
+
@client.currency_name(:eur).should == "BTCEUR"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#ticker" do
|
20
|
+
it "should fetch the ticker" do
|
21
|
+
stub_get("/api/1/BTCUSD/public/ticker?raw")
|
22
|
+
.to_return(:status => 200, :body => fixture("ticker.json"))
|
23
|
+
|
24
|
+
t = @client.ticker
|
25
|
+
|
26
|
+
t.buy.should == 4.75992
|
27
|
+
t.sell.should == 4.79907
|
28
|
+
t.high.should == 4.84592
|
29
|
+
t.low.should == 4.64116
|
30
|
+
t.avg.should == 4.77215
|
31
|
+
t.vol.should == 50178.69717970
|
32
|
+
t.vwap.should == 4.76327
|
33
|
+
t.last_local.should == 4.75992
|
34
|
+
t.last.should == 4.75992
|
35
|
+
t.last_orig.should == 4.75992
|
36
|
+
t.last_all.should == 4.75992
|
37
|
+
end
|
38
|
+
|
39
|
+
it "supports multi currency" do
|
40
|
+
stub_get("/api/1/BTCEUR/public/ticker?raw")
|
41
|
+
.to_return(:status => 200, :body => "{}")
|
42
|
+
|
43
|
+
@client.ticker :eur
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#depth" do
|
49
|
+
it "works" do
|
50
|
+
stub_get("/api/1/BTCUSD/public/depth?raw")
|
51
|
+
.to_return(:status => 200, :body => fixture("depth.json"))
|
52
|
+
|
53
|
+
d = @client.depth
|
54
|
+
|
55
|
+
a = d.asks[0]
|
56
|
+
a.price.should == 14.92195
|
57
|
+
a.amount.should == 59.99108959
|
58
|
+
a.price_int.should == 1492195
|
59
|
+
a.amount_int.should == 5999108959
|
60
|
+
a.stamp.should == "1332955218813546"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "gets fulldepth with :full => true" do
|
64
|
+
stub_get("/api/1/BTCUSD/public/fulldepth?raw")
|
65
|
+
.to_return(:status => 200, :body => "[]")
|
66
|
+
|
67
|
+
d = @client.depth(:full => true)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "supports multi currency" do
|
71
|
+
stub_get("/api/1/BTCEUR/public/depth?raw")
|
72
|
+
.to_return(:status => 200, :body => "[]")
|
73
|
+
|
74
|
+
@client.depth :eur
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#trades" do
|
79
|
+
it "works" do
|
80
|
+
stub_get("/api/1/BTCUSD/public/trades?raw")
|
81
|
+
.to_return(:status => 200, :body => fixture("trades.json"))
|
82
|
+
|
83
|
+
ts = @client.trades
|
84
|
+
|
85
|
+
t = ts[0]
|
86
|
+
t.date.should == Time.at(1332899401)
|
87
|
+
t.price.should == 4.75206
|
88
|
+
t.amount.should == 0.2
|
89
|
+
t.price_int.should == 475206
|
90
|
+
t.amount_int.should == 20000000
|
91
|
+
t.tid.should == 1332899401871343
|
92
|
+
t.price_currency.should == "USD"
|
93
|
+
t.item.should == "BTC"
|
94
|
+
t.trade_type.should == "ask"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "request with :since" do
|
98
|
+
stub_get("/api/1/BTCUSD/public/trades?raw&since=0")
|
99
|
+
.to_return(:status => 200, :body => "[]")
|
100
|
+
|
101
|
+
@client.trades :since => 0
|
102
|
+
end
|
103
|
+
|
104
|
+
it "supports multi currency" do
|
105
|
+
stub_get("/api/1/BTCEUR/public/trades?raw")
|
106
|
+
.to_return(:status => 200, :body => "[]")
|
107
|
+
|
108
|
+
@client.trades :eur
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MtGox::Me do
|
4
|
+
before :all do
|
5
|
+
@me = MtGox::Me.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#info" do
|
9
|
+
it "works" do
|
10
|
+
stub_post("/api/1/generic/private/info?raw")
|
11
|
+
.with(:body => test_body, :headers => test_headers)
|
12
|
+
.to_return(:status => 200, :body => fixture("info.json"))
|
13
|
+
|
14
|
+
@me.info
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#id_key" do
|
19
|
+
it "works" do
|
20
|
+
stub_post("/api/1/generic/private/idkey")
|
21
|
+
.with(:body => test_body, :headers => test_headers)
|
22
|
+
.to_return(:status => 200, :body => fixture("id_key.json"))
|
23
|
+
|
24
|
+
id_key = @me.id_key
|
25
|
+
id_key.should == "id_key"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#orders" do
|
30
|
+
it "works" do
|
31
|
+
stub_post("/api/1/generic/private/orders?raw")
|
32
|
+
.with(:body => test_body, :headers => test_headers)
|
33
|
+
.to_return(:status => 200, :body => fixture("orders.json"))
|
34
|
+
|
35
|
+
o = @me.orders[0]
|
36
|
+
|
37
|
+
o.oid.should == 1
|
38
|
+
o.currency.should == "USD"
|
39
|
+
o.item.should == "BTC"
|
40
|
+
o.type.should == "bid"
|
41
|
+
o.amount.should == 1.65000000
|
42
|
+
o.price.should == 1.65000
|
43
|
+
o.status.should == "open"
|
44
|
+
o.date.should == Time.at(1332896128)
|
45
|
+
o.priority.should == 1332896128221516
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#trades" do
|
50
|
+
it "works" do
|
51
|
+
stub_post("/api/1/generic/private/trades?raw")
|
52
|
+
.with(:body => test_body, :headers => test_headers)
|
53
|
+
.to_return(:status => 200, :body => fixture("trades.json"))
|
54
|
+
|
55
|
+
t = @me.trades[0]
|
56
|
+
t.should be_an_instance_of MtGox::Trade
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#add" do
|
61
|
+
it "works" do
|
62
|
+
body = test_body("type"=>"bid", "amount_int"=>"10000", "price_int"=>"100000")
|
63
|
+
stub_post("/api/1/BTCUSD/private/order/add")
|
64
|
+
.with(:body => body, :headers => test_headers(body))
|
65
|
+
.to_return(:status => 200, :body => fixture("add.json"))
|
66
|
+
|
67
|
+
|
68
|
+
@me.add("bid", 1*10000, 1*100000)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/mtgox_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MtGox do
|
4
|
+
describe ".new" do
|
5
|
+
it "should return a MtGox::Client" do
|
6
|
+
MtGox.new.should be_a MtGox::Client
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".configure" do
|
11
|
+
it "should set 'key' and 'secret'" do
|
12
|
+
MtGox.configure do |config|
|
13
|
+
config.key = "key"
|
14
|
+
config.secret = "secret"
|
15
|
+
end
|
16
|
+
|
17
|
+
MtGox.key.should == "key"
|
18
|
+
MtGox.secret.should == "secret"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
unless ENV["CI"]
|
2
|
+
require "simplecov"
|
3
|
+
SimpleCov.start
|
4
|
+
end
|
5
|
+
require "bundler/setup"
|
6
|
+
require "pd"
|
7
|
+
require "base64"
|
8
|
+
require "mtgox"
|
9
|
+
require "webmock/rspec"
|
10
|
+
|
11
|
+
module MtGox
|
12
|
+
module Request
|
13
|
+
private
|
14
|
+
def add_nonce(options)
|
15
|
+
options.merge!({:nonce => 1321745961249676})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
MtGox.configure do |c|
|
21
|
+
c.key = "key"
|
22
|
+
c.secret = "secret"
|
23
|
+
end
|
24
|
+
|
25
|
+
def a_get(path)
|
26
|
+
a_request(:get, "https://mtgox.com" + path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_get(path)
|
30
|
+
stub_request(:get, "https://mtgox.com" + path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def a_post(path)
|
34
|
+
a_request(:post, "https://mtgox.com" + path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def stub_post(path)
|
38
|
+
stub_request(:post, "https://mtgox.com#{path}")
|
39
|
+
end
|
40
|
+
|
41
|
+
def fixture_path
|
42
|
+
File.expand_path("../fixtures", __FILE__)
|
43
|
+
end
|
44
|
+
|
45
|
+
def fixture(file)
|
46
|
+
File.new(fixture_path + "/" + file)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_headers(body=test_body)
|
50
|
+
signed_headers(body).merge!(
|
51
|
+
{
|
52
|
+
"Accept" => "application/json",
|
53
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
54
|
+
"User-Agent" => "mtgox gem #{MtGox::VERSION}",
|
55
|
+
}
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def signed_headers(body)
|
60
|
+
signature = Base64.strict_encode64(
|
61
|
+
OpenSSL::HMAC.digest "sha512",
|
62
|
+
Base64.decode64(MtGox.secret),
|
63
|
+
body
|
64
|
+
)
|
65
|
+
{"Rest-Key" => MtGox.key, "Rest-Sign" => signature}
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_body(options={})
|
69
|
+
options.merge!({:nonce => 1321745961249676}).collect{|k, v| "#{k}=#{v}"} * "&"
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guten-mtgox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guten
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pd
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: tagen
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: faraday
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.7'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: faraday_middleware
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.8'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: multi_json
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.0'
|
94
|
+
description: An improved version of mtgox-gem with HTTP API v1
|
95
|
+
email: ywzhaifei@gmail.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- .gemtest
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .travis.yml
|
104
|
+
- .yardopts
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.md
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/mtgox.rb
|
110
|
+
- lib/mtgox/ask.rb
|
111
|
+
- lib/mtgox/base.rb
|
112
|
+
- lib/mtgox/client.rb
|
113
|
+
- lib/mtgox/configuration.rb
|
114
|
+
- lib/mtgox/connection.rb
|
115
|
+
- lib/mtgox/depth.rb
|
116
|
+
- lib/mtgox/me.rb
|
117
|
+
- lib/mtgox/order.rb
|
118
|
+
- lib/mtgox/request.rb
|
119
|
+
- lib/mtgox/response/raise_mtgox_error.rb
|
120
|
+
- lib/mtgox/ticker.rb
|
121
|
+
- lib/mtgox/trade.rb
|
122
|
+
- lib/mtgox/version.rb
|
123
|
+
- mtgox.gemspec
|
124
|
+
- mtgox.watchr
|
125
|
+
- response/raise_mtgox_error_spec.rb
|
126
|
+
- spec/fixtures/add.json
|
127
|
+
- spec/fixtures/depth.json
|
128
|
+
- spec/fixtures/id_key.json
|
129
|
+
- spec/fixtures/info.json
|
130
|
+
- spec/fixtures/orders.json
|
131
|
+
- spec/fixtures/ticker.json
|
132
|
+
- spec/fixtures/trades.json
|
133
|
+
- spec/mtgox/base_spec.rb
|
134
|
+
- spec/mtgox/client_spec.rb
|
135
|
+
- spec/mtgox/me_spec.rb
|
136
|
+
- spec/mtgox_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
homepage: https://github.com/GutenYe/mtgox
|
139
|
+
licenses: []
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 1.9.2
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ! '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 1.8.21
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
161
|
+
summary: An improved version of mtgox-gem with HTTP API v1
|
162
|
+
test_files: []
|
163
|
+
has_rdoc:
|