itbit 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +44 -34
- data/itbit.gemspec +8 -8
- data/lib/itbit.rb +1 -1
- data/lib/itbit/api.rb +6 -2
- data/lib/itbit/market.rb +9 -11
- data/lib/itbit/version.rb +1 -1
- data/spec/fixtures/trades.json +1 -1
- data/spec/market_spec.rb +7 -7
- data/spec/support/request_stubs.rb +9 -12
- metadata +34 -54
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 93a2a11e017a8d9050ed59d9d3f8ffa16625a8a4
|
4
|
+
data.tar.gz: ff55f359fe89998a745b49cfc2da16cb06dbad85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96c4782330c4119eae9a266538d84bd71b57a7dcdc78d6a7a721a5d34d6c033298c5110078ed8b3407da41d36b7c61b63e93730668607a95eb0ddbf32e40c2b5
|
7
|
+
data.tar.gz: b30c3fbcb307ae0628ea9b0600d37423f1e77352498349957bcb8bc55454fe10d27df704a598b51b23d9aa77ec9a188c86fb29ea1e531cf521a24d1cd8a541f4
|
data/Gemfile.lock
CHANGED
@@ -1,55 +1,65 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
itbit (0.0.
|
4
|
+
itbit (0.0.6)
|
5
5
|
activesupport
|
6
6
|
rest-client
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (4.
|
12
|
-
i18n (~> 0.
|
11
|
+
activesupport (4.2.6)
|
12
|
+
i18n (~> 0.7)
|
13
13
|
json (~> 1.7, >= 1.7.7)
|
14
14
|
minitest (~> 5.1)
|
15
|
-
thread_safe (~> 0.
|
15
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
16
16
|
tzinfo (~> 1.1)
|
17
|
-
addressable (2.
|
18
|
-
crack (0.4.
|
17
|
+
addressable (2.4.0)
|
18
|
+
crack (0.4.3)
|
19
19
|
safe_yaml (~> 1.0.0)
|
20
20
|
diff-lcs (1.2.5)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
domain_name (0.5.20160310)
|
22
|
+
unf (>= 0.0.5, < 1.0.0)
|
23
|
+
hashdiff (0.3.0)
|
24
|
+
http-cookie (1.0.2)
|
25
|
+
domain_name (~> 0.5)
|
26
|
+
i18n (0.7.0)
|
27
|
+
json (1.8.3)
|
28
|
+
mime-types (2.99.1)
|
29
|
+
minitest (5.8.4)
|
30
|
+
netrc (0.11.0)
|
31
|
+
rake (11.1.2)
|
32
|
+
rest-client (1.8.0)
|
33
|
+
http-cookie (>= 1.0.2, < 2.0)
|
34
|
+
mime-types (>= 1.16, < 3.0)
|
35
|
+
netrc (~> 0.7)
|
36
|
+
rspec (3.4.0)
|
37
|
+
rspec-core (~> 3.4.0)
|
38
|
+
rspec-expectations (~> 3.4.0)
|
39
|
+
rspec-mocks (~> 3.4.0)
|
40
|
+
rspec-core (3.4.4)
|
41
|
+
rspec-support (~> 3.4.0)
|
42
|
+
rspec-expectations (3.4.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.4.0)
|
45
|
+
rspec-mocks (3.4.1)
|
38
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
timecop (0.7.1)
|
48
|
-
tzinfo (1.2.1)
|
47
|
+
rspec-support (~> 3.4.0)
|
48
|
+
rspec-support (3.4.1)
|
49
|
+
safe_yaml (1.0.4)
|
50
|
+
shoulda-matchers (3.1.1)
|
51
|
+
activesupport (>= 4.0.0)
|
52
|
+
thread_safe (0.3.5)
|
53
|
+
timecop (0.8.1)
|
54
|
+
tzinfo (1.2.2)
|
49
55
|
thread_safe (~> 0.1)
|
50
|
-
|
56
|
+
unf (0.1.4)
|
57
|
+
unf_ext
|
58
|
+
unf_ext (0.0.7.2)
|
59
|
+
webmock (1.24.2)
|
51
60
|
addressable (>= 2.3.6)
|
52
61
|
crack (>= 0.3.2)
|
62
|
+
hashdiff
|
53
63
|
|
54
64
|
PLATFORMS
|
55
65
|
ruby
|
data/itbit.gemspec
CHANGED
@@ -19,15 +19,15 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "activesupport"
|
23
|
-
spec.add_dependency "rest-client"
|
22
|
+
spec.add_dependency "activesupport", "~> 4.2"
|
23
|
+
spec.add_dependency "rest-client", "~> 1.8"
|
24
24
|
|
25
25
|
spec.required_ruby_version = '>= 1.9.3'
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
-
spec.add_development_dependency "rake"
|
28
|
-
spec.add_development_dependency "rspec"
|
29
|
-
spec.add_development_dependency "rspec-mocks"
|
30
|
-
spec.add_development_dependency "timecop"
|
31
|
-
spec.add_development_dependency "webmock"
|
32
|
-
spec.add_development_dependency "shoulda-matchers"
|
27
|
+
spec.add_development_dependency "rake", "~> 0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 0"
|
29
|
+
spec.add_development_dependency "rspec-mocks", "~> 0"
|
30
|
+
spec.add_development_dependency "timecop", "~> 0"
|
31
|
+
spec.add_development_dependency "webmock", "~> 0"
|
32
|
+
spec.add_development_dependency "shoulda-matchers", "~> 0"
|
33
33
|
end
|
data/lib/itbit.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
require 'active_support'
|
1
2
|
require 'active_support/core_ext'
|
2
3
|
require 'json'
|
3
4
|
require 'rest_client'
|
4
5
|
require 'bigdecimal'
|
5
|
-
require 'active_support'
|
6
6
|
require 'digest/sha2'
|
7
7
|
require 'base64'
|
8
8
|
Dir[File.expand_path("../itbit/*.rb", __FILE__)].each {|f| require f}
|
data/lib/itbit/api.rb
CHANGED
@@ -17,8 +17,12 @@ module Itbit
|
|
17
17
|
x_auth_nonce: nonce,
|
18
18
|
content_type: 'application/json'
|
19
19
|
}
|
20
|
-
response = RestClient::Request
|
21
|
-
|
20
|
+
response = RestClient::Request.execute(
|
21
|
+
:method => verb,
|
22
|
+
:url => url,
|
23
|
+
:payload => payload,
|
24
|
+
:headers => headers,
|
25
|
+
:ssl_version => 'SSLv23')
|
22
26
|
JSON.parse(response.to_str) if response.to_str.presence
|
23
27
|
end
|
24
28
|
|
data/lib/itbit/market.rb
CHANGED
@@ -7,10 +7,7 @@ module Itbit
|
|
7
7
|
# The symbol ticker conveniently formatted as a ruby Hash with
|
8
8
|
# symbolized keys.
|
9
9
|
def self.ticker
|
10
|
-
|
11
|
-
rest_cl = RestClient::Request.execute :method => :get, :url => url, :ssl_version => 'SSLv23'
|
12
|
-
raw_ticker = JSON.parse(rest_cl)
|
13
|
-
raw_ticker.reduce({}) do |ticker, pair|
|
10
|
+
public_request("/markets/#{symbol.upcase}/ticker").reduce({}) do |ticker, pair|
|
14
11
|
key = pair.first.underscore.to_sym
|
15
12
|
value = case key
|
16
13
|
when :pair then pair[1].underscore.to_sym
|
@@ -25,7 +22,7 @@ module Itbit
|
|
25
22
|
# The symbol order book as a Hash with two keys: bids and asks.
|
26
23
|
# Each of them is a list of list consisting of [price, quantity]
|
27
24
|
def self.orders
|
28
|
-
order_book =
|
25
|
+
order_book = public_request("/markets/#{symbol.upcase}/order_book").symbolize_keys
|
29
26
|
order_book.each do |key, value|
|
30
27
|
order_book[key] = value.collect { |tuple| tuple.collect(&:to_d) }
|
31
28
|
end
|
@@ -34,16 +31,17 @@ module Itbit
|
|
34
31
|
# The symbol trades since tid (transaction id) as a list of hashes
|
35
32
|
# that look like {date: unix_timestamp, price: 123.5, amount: 1.97, tid: 98375}
|
36
33
|
def self.trades(tid = 0)
|
37
|
-
trades =
|
38
|
-
trades.collect do |t|
|
39
|
-
|
40
|
-
.
|
34
|
+
trades = public_request("/markets/#{symbol.upcase}/trades", since: tid)
|
35
|
+
trades['recentTrades'].collect do |t|
|
36
|
+
{ price: t['price'].to_d, amount: t['amount'].to_d,
|
37
|
+
tid: t['matchNumber'], date: DateTime.parse(t['timestamp']).to_i
|
38
|
+
}.with_indifferent_access
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
42
|
# @visibility private
|
45
|
-
def self.
|
46
|
-
url = "
|
43
|
+
def self.public_request(path, options = { })
|
44
|
+
url = "#{Api.api_url}#{path}"
|
47
45
|
url << "?#{options.to_query}" if options.any?
|
48
46
|
rest_cl = RestClient::Request.execute :method => :get, :url => url, :ssl_version => 'SSLv23'
|
49
47
|
JSON.parse(rest_cl)
|
data/lib/itbit/version.rb
CHANGED
data/spec/fixtures/trades.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
{"recentTrades":[{"timestamp":"2016-04-09T00:18:46.3800000Z","matchNumber":601855,"price":"418.14000000","amount":"0.01900000"},{"timestamp":"2016-04-09T00:18:37.7730000Z","matchNumber":601854,"price":"418.14000000","amount":"0.01540000"},{"timestamp":"2016-04-09T00:18:18.9430000Z","matchNumber":601853,"price":"418.31000000","amount":"0.01000000"},{"timestamp":"2016-04-09T00:17:56.3330000Z","matchNumber":601851,"price":"418.33000000","amount":"3.29100000"}],"count":4}
|
data/spec/market_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe Itbit::MarketData do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "gets the order book" do
|
34
|
-
|
34
|
+
stub_get("/markets/#{symbol.upcase}/order_book", 'order_book')
|
35
35
|
market_data.orders.should == {
|
36
36
|
bids: [[639.21,1.95],[637.0,0.47],[630.0,1.58]],
|
37
37
|
asks: [[642.4,0.4],[643.3,0.95],[644.3,0.25]]
|
@@ -39,14 +39,14 @@ describe Itbit::MarketData do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "gets the trades" do
|
42
|
-
|
42
|
+
stub_get("/markets/#{symbol.upcase}/trades", 'trades', since: 0)
|
43
43
|
trades = market_data.trades
|
44
|
-
trades.size.should ==
|
44
|
+
trades.size.should == 4
|
45
45
|
trades.first.tap do |t|
|
46
|
-
t[:date].should ==
|
47
|
-
t[:price].should ==
|
48
|
-
t[:amount].should ==
|
49
|
-
t[:tid].should ==
|
46
|
+
t[:date].should == 1460161126
|
47
|
+
t[:price].should == 418.14
|
48
|
+
t[:amount].should == 0.019
|
49
|
+
t[:tid].should == 601855
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -6,24 +6,21 @@ module RequestStubs
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def stub_old(path, fixture, options = { })
|
10
|
-
stub_api(:get, "https://www.itbit.com/api/v2#{path}", fixture, options)
|
11
|
-
end
|
12
|
-
|
13
9
|
def stub_api(method, url, fixture, options)
|
14
10
|
response_body = if fixture
|
15
11
|
File.read(File.expand_path("../../fixtures/#{fixture}.json", __FILE__))
|
16
12
|
else
|
17
13
|
''
|
18
14
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
request = stub_request(method, url)
|
16
|
+
|
17
|
+
unless options.empty?
|
18
|
+
request = if method == :get
|
19
|
+
request.with(query: options)
|
20
|
+
else
|
21
|
+
request.with(body: options.to_json)
|
22
|
+
end
|
25
23
|
end
|
26
|
-
|
27
|
-
.with(with).to_return(status: 200, body: response_body)
|
24
|
+
request.to_return(status: 200, body: response_body)
|
28
25
|
end
|
29
26
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nubis
|
@@ -10,154 +9,137 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2016-04-09 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: activesupport
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
20
|
+
version: '4.2'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
27
|
+
version: '4.2'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: rest-client
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - "~>"
|
37
33
|
- !ruby/object:Gem::Version
|
38
|
-
version: '
|
34
|
+
version: '1.8'
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - "~>"
|
45
40
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
41
|
+
version: '1.8'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: bundler
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- - ~>
|
46
|
+
- - "~>"
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '1.3'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- - ~>
|
53
|
+
- - "~>"
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '1.3'
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: rake
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- -
|
60
|
+
- - "~>"
|
69
61
|
- !ruby/object:Gem::Version
|
70
62
|
version: '0'
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- -
|
67
|
+
- - "~>"
|
77
68
|
- !ruby/object:Gem::Version
|
78
69
|
version: '0'
|
79
70
|
- !ruby/object:Gem::Dependency
|
80
71
|
name: rspec
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
73
|
requirements:
|
84
|
-
- -
|
74
|
+
- - "~>"
|
85
75
|
- !ruby/object:Gem::Version
|
86
76
|
version: '0'
|
87
77
|
type: :development
|
88
78
|
prerelease: false
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
80
|
requirements:
|
92
|
-
- -
|
81
|
+
- - "~>"
|
93
82
|
- !ruby/object:Gem::Version
|
94
83
|
version: '0'
|
95
84
|
- !ruby/object:Gem::Dependency
|
96
85
|
name: rspec-mocks
|
97
86
|
requirement: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
87
|
requirements:
|
100
|
-
- -
|
88
|
+
- - "~>"
|
101
89
|
- !ruby/object:Gem::Version
|
102
90
|
version: '0'
|
103
91
|
type: :development
|
104
92
|
prerelease: false
|
105
93
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
94
|
requirements:
|
108
|
-
- -
|
95
|
+
- - "~>"
|
109
96
|
- !ruby/object:Gem::Version
|
110
97
|
version: '0'
|
111
98
|
- !ruby/object:Gem::Dependency
|
112
99
|
name: timecop
|
113
100
|
requirement: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
101
|
requirements:
|
116
|
-
- -
|
102
|
+
- - "~>"
|
117
103
|
- !ruby/object:Gem::Version
|
118
104
|
version: '0'
|
119
105
|
type: :development
|
120
106
|
prerelease: false
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
108
|
requirements:
|
124
|
-
- -
|
109
|
+
- - "~>"
|
125
110
|
- !ruby/object:Gem::Version
|
126
111
|
version: '0'
|
127
112
|
- !ruby/object:Gem::Dependency
|
128
113
|
name: webmock
|
129
114
|
requirement: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
115
|
requirements:
|
132
|
-
- -
|
116
|
+
- - "~>"
|
133
117
|
- !ruby/object:Gem::Version
|
134
118
|
version: '0'
|
135
119
|
type: :development
|
136
120
|
prerelease: false
|
137
121
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
122
|
requirements:
|
140
|
-
- -
|
123
|
+
- - "~>"
|
141
124
|
- !ruby/object:Gem::Version
|
142
125
|
version: '0'
|
143
126
|
- !ruby/object:Gem::Dependency
|
144
127
|
name: shoulda-matchers
|
145
128
|
requirement: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
129
|
requirements:
|
148
|
-
- -
|
130
|
+
- - "~>"
|
149
131
|
- !ruby/object:Gem::Version
|
150
132
|
version: '0'
|
151
133
|
type: :development
|
152
134
|
prerelease: false
|
153
135
|
version_requirements: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
136
|
requirements:
|
156
|
-
- -
|
137
|
+
- - "~>"
|
157
138
|
- !ruby/object:Gem::Version
|
158
139
|
version: '0'
|
159
|
-
description:
|
160
|
-
|
140
|
+
description: |-
|
141
|
+
API client library for itbit.com. Fetch public market
|
142
|
+
data and build trading robots
|
161
143
|
email:
|
162
144
|
- nb@bitex.la
|
163
145
|
- tr@bitex.la
|
@@ -165,8 +147,8 @@ executables: []
|
|
165
147
|
extensions: []
|
166
148
|
extra_rdoc_files: []
|
167
149
|
files:
|
168
|
-
- .gitignore
|
169
|
-
- .rspec
|
150
|
+
- ".gitignore"
|
151
|
+
- ".rspec"
|
170
152
|
- Gemfile
|
171
153
|
- Gemfile.lock
|
172
154
|
- LICENSE.txt
|
@@ -200,27 +182,26 @@ files:
|
|
200
182
|
homepage: http://github.com/bitex-la/itbit
|
201
183
|
licenses:
|
202
184
|
- MIT
|
185
|
+
metadata: {}
|
203
186
|
post_install_message:
|
204
187
|
rdoc_options: []
|
205
188
|
require_paths:
|
206
189
|
- lib
|
207
190
|
required_ruby_version: !ruby/object:Gem::Requirement
|
208
|
-
none: false
|
209
191
|
requirements:
|
210
|
-
- -
|
192
|
+
- - ">="
|
211
193
|
- !ruby/object:Gem::Version
|
212
194
|
version: 1.9.3
|
213
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
-
none: false
|
215
196
|
requirements:
|
216
|
-
- -
|
197
|
+
- - ">="
|
217
198
|
- !ruby/object:Gem::Version
|
218
199
|
version: '0'
|
219
200
|
requirements: []
|
220
201
|
rubyforge_project:
|
221
|
-
rubygems_version:
|
202
|
+
rubygems_version: 2.4.5
|
222
203
|
signing_key:
|
223
|
-
specification_version:
|
204
|
+
specification_version: 4
|
224
205
|
summary: API client library for itbit.com
|
225
206
|
test_files:
|
226
207
|
- spec/fixtures/market_ticker_xbteur.json
|
@@ -240,4 +221,3 @@ test_files:
|
|
240
221
|
- spec/support/request_stubs.rb
|
241
222
|
- spec/trade_spec.rb
|
242
223
|
- spec/wallet_spec.rb
|
243
|
-
has_rdoc:
|