bitex 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +89 -0
  6. data/Rakefile +1 -0
  7. data/bitex.gemspec +33 -0
  8. data/lib/bitex.rb +11 -0
  9. data/lib/bitex/api.rb +57 -0
  10. data/lib/bitex/buy.rb +25 -0
  11. data/lib/bitex/market.rb +67 -0
  12. data/lib/bitex/match.rb +24 -0
  13. data/lib/bitex/order.rb +185 -0
  14. data/lib/bitex/profile.rb +10 -0
  15. data/lib/bitex/sell.rb +25 -0
  16. data/lib/bitex/specie_deposit.rb +27 -0
  17. data/lib/bitex/specie_withdrawal.rb +56 -0
  18. data/lib/bitex/transaction.rb +14 -0
  19. data/lib/bitex/usd_deposit.rb +65 -0
  20. data/lib/bitex/usd_withdrawal.rb +56 -0
  21. data/lib/bitex/version.rb +3 -0
  22. data/spec/ask_spec.rb +24 -0
  23. data/spec/bid_spec.rb +24 -0
  24. data/spec/buy_spec.rb +11 -0
  25. data/spec/fixtures/aggregated_data.json +1 -0
  26. data/spec/fixtures/asks_cancel.json +1 -0
  27. data/spec/fixtures/asks_create.json +1 -0
  28. data/spec/fixtures/bids_cancel.json +1 -0
  29. data/spec/fixtures/bids_create.json +1 -0
  30. data/spec/fixtures/market_ticker.json +1 -0
  31. data/spec/fixtures/order_book.json +1 -0
  32. data/spec/fixtures/orders.json +1 -0
  33. data/spec/fixtures/profile.json +1 -0
  34. data/spec/fixtures/transactions.json +1 -0
  35. data/spec/fixtures/user_transactions.json +1 -0
  36. data/spec/market_spec.rb +46 -0
  37. data/spec/order_spec.rb +23 -0
  38. data/spec/profile_spec.rb +23 -0
  39. data/spec/sell_spec.rb +11 -0
  40. data/spec/spec_helper.rb +28 -0
  41. data/spec/specie_deposit_spec.rb +16 -0
  42. data/spec/specie_withdrawal_spec.rb +37 -0
  43. data/spec/support/from_json_shared_examples.rb +52 -0
  44. data/spec/support/order_shared_examples.rb +45 -0
  45. data/spec/support/request_stubs.rb +17 -0
  46. data/spec/transaction_spec.rb +19 -0
  47. data/spec/usd_deposit_spec.rb +45 -0
  48. data/spec/usd_withdrawal_spec.rb +37 -0
  49. metadata +269 -0
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::Sell do
4
+ let(:as_json) do
5
+ [3,12345678,946685400,1,100.50000000,201.0000000,0.05000000,2.00000000]
6
+ end
7
+
8
+ it_behaves_like 'API class'
9
+ it_behaves_like 'API class with a specie'
10
+ it_behaves_like 'JSON deserializable match'
11
+ end
@@ -0,0 +1,28 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'bitex'
5
+ require 'webmock/rspec'
6
+ require 'shoulda/matchers'
7
+ require 'timecop'
8
+
9
+ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.include RequestStubs
13
+
14
+ config.mock_with :rspec do |mocks|
15
+ mocks.yield_receiver_to_any_instance_implementation_blocks = true
16
+ mocks.syntax = [:expect, :should]
17
+ end
18
+ config.expect_with :rspec do |c|
19
+ c.syntax = [:expect, :should]
20
+ end
21
+
22
+ config.after(:each) do
23
+ Timecop.return
24
+ end
25
+
26
+ config.order = "random"
27
+ end
28
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::SpecieDeposit do
4
+ let(:as_json) do
5
+ [5,12345678,946685400,1,100.50000000]
6
+ end
7
+
8
+ it_behaves_like 'API class'
9
+ it_behaves_like 'API class with a specie'
10
+
11
+ it "sets quantity as BigDecimal" do
12
+ thing = Bitex::SpecieDeposit.from_json(as_json).quantity
13
+ thing.should be_a BigDecimal
14
+ thing.should == 100.5
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::SpecieWithdrawal do
4
+ let(:as_json) do
5
+ [6,12345678,946685400,1,100.00000000,1,0]
6
+ end
7
+
8
+ it_behaves_like 'API class'
9
+ it_behaves_like 'API class with a specie'
10
+
11
+ it "sets quantity as BigDecimal" do
12
+ thing = Bitex::SpecieWithdrawal.from_json(as_json).quantity
13
+ thing.should be_a BigDecimal
14
+ thing.should == 100.0
15
+ end
16
+
17
+ { 1 => :received,
18
+ 2 => :pending,
19
+ 3 => :done,
20
+ 4 => :cancelled,
21
+ }.each do |code, symbol|
22
+ it "sets status #{code} to #{symbol}" do
23
+ as_json[5] = code
24
+ Bitex::SpecieWithdrawal.from_json(as_json).status.should == symbol
25
+ end
26
+ end
27
+
28
+ { 0 => :not_cancelled,
29
+ 1 => :insufficient_funds,
30
+ 2 => :destination_invalid,
31
+ }.each do |code, symbol|
32
+ it "sets reason #{code} to #{symbol}" do
33
+ as_json[6] = code
34
+ Bitex::SpecieWithdrawal.from_json(as_json).reason.should == symbol
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ shared_examples_for 'API class' do
2
+ it 'stores the unique id' do
3
+ as_json[1] = 12345678
4
+ subject.class.from_json(as_json).id.should == 12345678
5
+ end
6
+
7
+ it 'makes creation times into Time' do
8
+ subject.class.from_json(as_json).created_at.should be_a Time
9
+ end
10
+ end
11
+
12
+ shared_examples_for 'API class with a specie' do
13
+ it 'makes specie 1 into btc' do
14
+ as_json[3] = 1
15
+ subject.class.from_json(as_json).specie.should == :btc
16
+ end
17
+
18
+ it 'makes specie 2 into ltc' do
19
+ as_json[3] = 2
20
+ subject.class.from_json(as_json).specie.should == :ltc
21
+ end
22
+ end
23
+
24
+ shared_examples_for 'JSON deserializable match' do
25
+ { quantity: 100.5, amount: 201, fee: 0.05, price: 2.0 }.each do |field, value|
26
+ it "sets #{field} as BigDecimal" do
27
+ thing = subject.class.from_json(as_json).send(field)
28
+ thing.should be_a BigDecimal
29
+ thing.should == value
30
+ end
31
+ end
32
+ end
33
+
34
+ shared_examples_for 'JSON deserializable order' do
35
+ it "sets price as BigDecimal" do
36
+ thing = subject.class.from_json(as_json).price
37
+ thing.should be_a BigDecimal
38
+ thing.should == 1000.0
39
+ end
40
+
41
+ { 1 => :received,
42
+ 2 => :executing,
43
+ 3 => :cancelling,
44
+ 4 => :cancelled,
45
+ 5 => :completed,
46
+ }.each do |code, symbol|
47
+ it "sets status #{code} to #{symbol}" do
48
+ as_json[7] = code
49
+ subject.class.from_json(as_json).status.should == symbol
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ shared_examples_for 'Order' do |api_path|
2
+ it 'lists all' do
3
+ stub_private(:get, "/private/orders", 'orders')
4
+ order, empty = subject.class.all
5
+ order.should be_a subject.class
6
+ empty.should be_nil
7
+ end
8
+
9
+ it 'lists all active' do
10
+ stub_private(:get, "/private/orders/active", 'orders')
11
+ order, empty = subject.class.active
12
+ order.should be_a subject.class
13
+ empty.should be_nil
14
+ end
15
+
16
+ it 'gets one' do
17
+ stub_private(:get, "/private/orders", 'orders')
18
+ order = subject.class.find(12345678)
19
+ order.should be_a subject.class
20
+ order.id.should == 12345678
21
+ end
22
+
23
+ it 'places for btc' do
24
+ stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
25
+ {amount: 100.50, price: 1000.00, specie: 1})
26
+ order = subject.class.create!(:btc, 100.50, 1000.00)
27
+ order.should be_a subject.class
28
+ end
29
+
30
+ it 'places for ltc' do
31
+ stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
32
+ {amount: 100.50, price: 1000.00, specie: 2})
33
+ order = subject.class.create!(:ltc, 100.50, 1000.00)
34
+ order.should be_a subject.class
35
+ end
36
+
37
+ it 'cancels one' do
38
+ stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
39
+ {amount: 100.50, price: 1000.00, specie: 1})
40
+ order = subject.class.create!(:btc, 100.50, 1000.00)
41
+ stub_private(:post, "/private/#{api_path}/cancel", "#{api_path}_cancel")
42
+ order.cancel!
43
+ order.status.should == :cancelling
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ module RequestStubs
2
+ def stub_get(path, fixture)
3
+ stub_api(:get, path, fixture, {})
4
+ end
5
+
6
+ def stub_private(method, path, fixture, options = {})
7
+ stub_api(method, path, fixture, options.merge({api_key: 'valid_api_key'}))
8
+ end
9
+
10
+ def stub_api(method, path, fixture, options)
11
+ fixture_path = File.expand_path("../../fixtures/#{fixture}.json", __FILE__)
12
+ with = method == :get ? {query: options} : {body: options.to_query}
13
+ stub_request(method, "https://bitex.la/api-v1/rest#{path}")
14
+ .with(with)
15
+ .to_return(status: 200, body: File.read(fixture_path))
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::Transaction do
4
+ before(:each) do
5
+ Bitex.api_key = 'valid_api_key'
6
+ end
7
+
8
+ it 'gets all transactions' do
9
+ stub_private(:get, "/private/transactions", 'user_transactions')
10
+ buy, sell, specie_deposit, specie_withdrawal, usd_deposit, usd_withdrawal =
11
+ Bitex::Transaction.all
12
+ buy.should be_a Bitex::Buy
13
+ sell.should be_a Bitex::Sell
14
+ specie_deposit.should be_a Bitex::SpecieDeposit
15
+ specie_withdrawal.should be_a Bitex::SpecieWithdrawal
16
+ usd_deposit.should be_a Bitex::UsdDeposit
17
+ usd_withdrawal.should be_a Bitex::UsdWithdrawal
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::UsdDeposit do
4
+ let(:as_json) do
5
+ [7,12345678,946685400,100.00000000,1,1,0]
6
+ end
7
+
8
+ it_behaves_like 'API class'
9
+
10
+ it "sets amount as BigDecimal" do
11
+ thing = Bitex::UsdDeposit.from_json(as_json).amount
12
+ thing.should be_a BigDecimal
13
+ thing.should == 100.0
14
+ end
15
+
16
+ { 1 => :astropay,
17
+ 2 => :other,
18
+ }.each do |code, symbol|
19
+ it "sets status #{code} to #{symbol}" do
20
+ as_json[4] = code
21
+ Bitex::UsdDeposit.from_json(as_json).deposit_method.should == symbol
22
+ end
23
+ end
24
+
25
+ { 1 => :pending,
26
+ 2 => :done,
27
+ 3 => :cancelled,
28
+ }.each do |code, symbol|
29
+ it "sets status #{code} to #{symbol}" do
30
+ as_json[5] = code
31
+ Bitex::UsdDeposit.from_json(as_json).status.should == symbol
32
+ end
33
+ end
34
+
35
+ { 0 => :not_cancelled,
36
+ 1 => :did_not_credit,
37
+ 2 => :sender_unknown,
38
+ 3 => :other,
39
+ }.each do |code, symbol|
40
+ it "sets reason #{code} to #{symbol}" do
41
+ as_json[6] = code
42
+ Bitex::UsdDeposit.from_json(as_json).reason.should == symbol
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::UsdWithdrawal do
4
+ let(:as_json) do
5
+ [8,12345678,946685400,100.00000000,1,0,]
6
+ end
7
+
8
+ it_behaves_like 'API class'
9
+
10
+ it "sets amount as BigDecimal" do
11
+ thing = Bitex::UsdWithdrawal.from_json(as_json).amount
12
+ thing.should be_a BigDecimal
13
+ thing.should == 100.0
14
+ end
15
+
16
+ { 1 => :received,
17
+ 2 => :pending,
18
+ 3 => :done,
19
+ 4 => :cancelled,
20
+ }.each do |code, symbol|
21
+ it "sets status #{code} to #{symbol}" do
22
+ as_json[4] = code
23
+ Bitex::UsdWithdrawal.from_json(as_json).status.should == symbol
24
+ end
25
+ end
26
+
27
+ { 0 => :not_cancelled,
28
+ 1 => :insufficient_funds,
29
+ 2 => :no_instructions,
30
+ 3 => :recipient_unknown,
31
+ }.each do |code, symbol|
32
+ it "sets reason #{code} to #{symbol}" do
33
+ as_json[5] = code
34
+ Bitex::UsdWithdrawal.from_json(as_json).reason.should == symbol
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,269 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nubis
9
+ - Eromirou
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-07-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: curb
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec-mocks
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: webmock
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: shoulda-matchers
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ description: ! "API client library for bitex.la. Fetch public market\n data
160
+ and build trading robots"
161
+ email:
162
+ - nb@bitex.la
163
+ - tr@bitex.la
164
+ executables: []
165
+ extensions: []
166
+ extra_rdoc_files: []
167
+ files:
168
+ - .gitignore
169
+ - .rspec
170
+ - Gemfile
171
+ - LICENSE.txt
172
+ - README.md
173
+ - Rakefile
174
+ - bitex.gemspec
175
+ - lib/bitex.rb
176
+ - lib/bitex/api.rb
177
+ - lib/bitex/buy.rb
178
+ - lib/bitex/market.rb
179
+ - lib/bitex/match.rb
180
+ - lib/bitex/order.rb
181
+ - lib/bitex/profile.rb
182
+ - lib/bitex/sell.rb
183
+ - lib/bitex/specie_deposit.rb
184
+ - lib/bitex/specie_withdrawal.rb
185
+ - lib/bitex/transaction.rb
186
+ - lib/bitex/usd_deposit.rb
187
+ - lib/bitex/usd_withdrawal.rb
188
+ - lib/bitex/version.rb
189
+ - spec/ask_spec.rb
190
+ - spec/bid_spec.rb
191
+ - spec/buy_spec.rb
192
+ - spec/fixtures/aggregated_data.json
193
+ - spec/fixtures/asks_cancel.json
194
+ - spec/fixtures/asks_create.json
195
+ - spec/fixtures/bids_cancel.json
196
+ - spec/fixtures/bids_create.json
197
+ - spec/fixtures/market_ticker.json
198
+ - spec/fixtures/order_book.json
199
+ - spec/fixtures/orders.json
200
+ - spec/fixtures/profile.json
201
+ - spec/fixtures/transactions.json
202
+ - spec/fixtures/user_transactions.json
203
+ - spec/market_spec.rb
204
+ - spec/order_spec.rb
205
+ - spec/profile_spec.rb
206
+ - spec/sell_spec.rb
207
+ - spec/spec_helper.rb
208
+ - spec/specie_deposit_spec.rb
209
+ - spec/specie_withdrawal_spec.rb
210
+ - spec/support/from_json_shared_examples.rb
211
+ - spec/support/order_shared_examples.rb
212
+ - spec/support/request_stubs.rb
213
+ - spec/transaction_spec.rb
214
+ - spec/usd_deposit_spec.rb
215
+ - spec/usd_withdrawal_spec.rb
216
+ homepage: http://bitex.la/developers
217
+ licenses:
218
+ - MIT
219
+ post_install_message:
220
+ rdoc_options: []
221
+ require_paths:
222
+ - lib
223
+ required_ruby_version: !ruby/object:Gem::Requirement
224
+ none: false
225
+ requirements:
226
+ - - ! '>='
227
+ - !ruby/object:Gem::Version
228
+ version: 1.9.3
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ none: false
231
+ requirements:
232
+ - - ! '>='
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ requirements: []
236
+ rubyforge_project:
237
+ rubygems_version: 1.8.23
238
+ signing_key:
239
+ specification_version: 3
240
+ summary: API client library for bitex.la
241
+ test_files:
242
+ - spec/ask_spec.rb
243
+ - spec/bid_spec.rb
244
+ - spec/buy_spec.rb
245
+ - spec/fixtures/aggregated_data.json
246
+ - spec/fixtures/asks_cancel.json
247
+ - spec/fixtures/asks_create.json
248
+ - spec/fixtures/bids_cancel.json
249
+ - spec/fixtures/bids_create.json
250
+ - spec/fixtures/market_ticker.json
251
+ - spec/fixtures/order_book.json
252
+ - spec/fixtures/orders.json
253
+ - spec/fixtures/profile.json
254
+ - spec/fixtures/transactions.json
255
+ - spec/fixtures/user_transactions.json
256
+ - spec/market_spec.rb
257
+ - spec/order_spec.rb
258
+ - spec/profile_spec.rb
259
+ - spec/sell_spec.rb
260
+ - spec/spec_helper.rb
261
+ - spec/specie_deposit_spec.rb
262
+ - spec/specie_withdrawal_spec.rb
263
+ - spec/support/from_json_shared_examples.rb
264
+ - spec/support/order_shared_examples.rb
265
+ - spec/support/request_stubs.rb
266
+ - spec/transaction_spec.rb
267
+ - spec/usd_deposit_spec.rb
268
+ - spec/usd_withdrawal_spec.rb
269
+ has_rdoc: