bitex_bot 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -3
  3. data/Gemfile +3 -1
  4. data/bitex_bot.gemspec +5 -2
  5. data/lib/bitex_bot/database.rb +2 -2
  6. data/lib/bitex_bot/models/api_wrappers/api_wrapper.rb +47 -35
  7. data/lib/bitex_bot/models/api_wrappers/bitex/bitex_api_wrapper.rb +178 -0
  8. data/lib/bitex_bot/models/api_wrappers/bitstamp/bitstamp_api_wrapper.rb +62 -45
  9. data/lib/bitex_bot/models/api_wrappers/itbit/itbit_api_wrapper.rb +52 -28
  10. data/lib/bitex_bot/models/api_wrappers/kraken/kraken_api_wrapper.rb +61 -28
  11. data/lib/bitex_bot/models/api_wrappers/kraken/kraken_order.rb +12 -6
  12. data/lib/bitex_bot/models/buy_closing_flow.rb +3 -2
  13. data/lib/bitex_bot/models/buy_opening_flow.rb +31 -6
  14. data/lib/bitex_bot/models/closing_flow.rb +37 -22
  15. data/lib/bitex_bot/models/open_buy.rb +1 -3
  16. data/lib/bitex_bot/models/open_sell.rb +1 -3
  17. data/lib/bitex_bot/models/opening_flow.rb +42 -28
  18. data/lib/bitex_bot/models/order_book_simulator.rb +14 -13
  19. data/lib/bitex_bot/models/sell_closing_flow.rb +3 -2
  20. data/lib/bitex_bot/models/sell_opening_flow.rb +29 -4
  21. data/lib/bitex_bot/robot.rb +28 -43
  22. data/lib/bitex_bot/settings.rb +2 -0
  23. data/lib/bitex_bot/version.rb +1 -1
  24. data/settings.rb.sample +23 -5
  25. data/spec/bitex_bot/settings_spec.rb +13 -6
  26. data/spec/factories/bitex_ask.rb +14 -0
  27. data/spec/factories/bitex_bid.rb +14 -0
  28. data/spec/factories/bitex_buy.rb +7 -7
  29. data/spec/factories/bitex_sell.rb +7 -7
  30. data/spec/factories/buy_opening_flow.rb +10 -10
  31. data/spec/factories/open_buy.rb +8 -8
  32. data/spec/factories/open_sell.rb +8 -8
  33. data/spec/factories/sell_opening_flow.rb +10 -10
  34. data/spec/fixtures/bitstamp/balance.yml +63 -0
  35. data/spec/fixtures/bitstamp/order_book.yml +60 -0
  36. data/spec/fixtures/bitstamp/orders/all.yml +62 -0
  37. data/spec/fixtures/bitstamp/orders/failure_sell.yml +60 -0
  38. data/spec/fixtures/bitstamp/orders/successful_buy.yml +62 -0
  39. data/spec/fixtures/bitstamp/transactions.yml +244 -0
  40. data/spec/fixtures/bitstamp/user_transactions.yml +223 -0
  41. data/spec/models/api_wrappers/bitex_api_wrapper_spec.rb +147 -0
  42. data/spec/models/api_wrappers/bitstamp_api_wrapper_spec.rb +134 -140
  43. data/spec/models/api_wrappers/itbit_api_wrapper_spec.rb +9 -3
  44. data/spec/models/api_wrappers/kraken_api_wrapper_spec.rb +142 -73
  45. data/spec/models/bitex_api_spec.rb +4 -4
  46. data/spec/models/buy_closing_flow_spec.rb +19 -24
  47. data/spec/models/buy_opening_flow_spec.rb +102 -83
  48. data/spec/models/order_book_simulator_spec.rb +5 -0
  49. data/spec/models/robot_spec.rb +7 -4
  50. data/spec/models/sell_closing_flow_spec.rb +21 -25
  51. data/spec/models/sell_opening_flow_spec.rb +100 -80
  52. data/spec/spec_helper.rb +3 -1
  53. data/spec/support/bitex_stubs.rb +80 -40
  54. data/spec/support/bitstamp/bitstamp_api_wrapper_stubs.rb +2 -2
  55. data/spec/support/bitstamp/bitstamp_stubs.rb +3 -3
  56. data/spec/support/vcr.rb +8 -0
  57. data/spec/support/webmock.rb +8 -0
  58. metadata +77 -10
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BitexBot::SellOpeningFlow do
4
- before(:each) { Bitex.api_key = 'valid_key' }
4
+ before(:each) { BitexBot::Robot.setup }
5
5
 
6
6
  let(:store) { BitexBot::Store.create }
7
7
 
@@ -13,13 +13,17 @@ describe BitexBot::SellOpeningFlow do
13
13
 
14
14
  describe 'when creating a selling flow' do
15
15
  it 'sells 2 bitcoin' do
16
- stub_bitex_orders
17
- BitexBot::Settings.stub(time_to_live: 3,
18
- selling: double(quantity_to_sell_per_order: 2, profit: 0))
19
-
20
- flow = BitexBot::SellOpeningFlow.create_for_market(1000,
21
- bitstamp_api_wrapper_order_book.asks, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
22
- store)
16
+ stub_bitex_active_orders
17
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: 2, profit: 0))
18
+
19
+ flow = BitexBot::SellOpeningFlow.create_for_market(
20
+ 1000,
21
+ bitstamp_api_wrapper_order_book.asks,
22
+ bitstamp_api_wrapper_transactions_stub,
23
+ 0.5,
24
+ 0.25,
25
+ store
26
+ )
23
27
 
24
28
  flow.order_id.should == 12345
25
29
  flow.value_to_use.should == 2
@@ -37,21 +41,17 @@ describe BitexBot::SellOpeningFlow do
37
41
  let(:transactions) { bitstamp_api_wrapper_transactions_stub }
38
42
 
39
43
  it 'sells 4 bitcoin' do
40
- BitexBot::Settings.stub(
41
- time_to_live: 3,
42
- selling: double(quantity_to_sell_per_order: amount_to_sell, profit: 0)
44
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: amount_to_sell, profit: 0))
45
+ stub_bitex_active_orders
46
+
47
+ flow = BitexBot::SellOpeningFlow.create_for_market(
48
+ btc_balance,
49
+ orderbook,
50
+ transactions,
51
+ maker_fee,
52
+ taker_fee,
53
+ store
43
54
  )
44
- stub_bitex_orders
45
-
46
- flow =
47
- BitexBot::SellOpeningFlow.create_for_market(
48
- btc_balance,
49
- orderbook,
50
- transactions,
51
- maker_fee,
52
- taker_fee,
53
- store
54
- )
55
55
 
56
56
  flow.order_id.should eq order_id
57
57
  flow.value_to_use.should eq amount_to_sell
@@ -66,17 +66,16 @@ describe BitexBot::SellOpeningFlow do
66
66
  time_to_live: 3,
67
67
  selling: double(quantity_to_sell_per_order: amount_to_sell, profit: 0)
68
68
  )
69
- stub_bitex_orders
70
-
71
- flow =
72
- BitexBot::SellOpeningFlow.create_for_market(
73
- btc_balance,
74
- orderbook,
75
- transactions,
76
- maker_fee,
77
- taker_fee,
78
- store
79
- )
69
+ stub_bitex_active_orders
70
+
71
+ flow = BitexBot::SellOpeningFlow.create_for_market(
72
+ btc_balance,
73
+ orderbook,
74
+ transactions,
75
+ maker_fee,
76
+ taker_fee,
77
+ store
78
+ )
80
79
 
81
80
  flow.order_id.should eq order_id
82
81
  flow.value_to_use.should eq amount_to_sell
@@ -84,13 +83,17 @@ describe BitexBot::SellOpeningFlow do
84
83
  end
85
84
 
86
85
  it 'raises the price to charge on bitex to take a profit' do
87
- stub_bitex_orders
88
- BitexBot::Settings.stub(time_to_live: 3,
89
- selling: double(quantity_to_sell_per_order: 4, profit: 50.to_d))
90
-
91
- flow = BitexBot::SellOpeningFlow.create_for_market(1000,
92
- bitstamp_api_wrapper_order_book.asks, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
93
- store)
86
+ stub_bitex_active_orders
87
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: 4, profit: 50.to_d))
88
+
89
+ flow = BitexBot::SellOpeningFlow.create_for_market(
90
+ 1000,
91
+ bitstamp_api_wrapper_order_book.asks,
92
+ bitstamp_api_wrapper_transactions_stub,
93
+ 0.5,
94
+ 0.25,
95
+ store
96
+ )
94
97
 
95
98
  flow.order_id.should == 12345
96
99
  flow.value_to_use.should == 4
@@ -101,13 +104,17 @@ describe BitexBot::SellOpeningFlow do
101
104
 
102
105
  it 'fails when there is a problem placing the ask on bitex' do
103
106
  Bitex::Ask.stub(:create!) { raise StandardError.new('Cannot Create') }
104
- BitexBot::Settings.stub(time_to_live: 3,
105
- selling: double(quantity_to_sell_per_order: 4, profit: 50))
107
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: 4, profit: 50))
106
108
 
107
109
  expect do
108
- flow = BitexBot::SellOpeningFlow.create_for_market(100000,
109
- bitstamp_api_wrapper_order_book.asks, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
110
- store)
110
+ flow = BitexBot::SellOpeningFlow.create_for_market(
111
+ 100_000,
112
+ bitstamp_api_wrapper_order_book.asks,
113
+ bitstamp_api_wrapper_transactions_stub,
114
+ 0.5,
115
+ 0.25,
116
+ store
117
+ )
111
118
 
112
119
  flow.should be_nil
113
120
  BitexBot::SellOpeningFlow.count.should == 0
@@ -115,14 +122,18 @@ describe BitexBot::SellOpeningFlow do
115
122
  end
116
123
 
117
124
  it 'fails when there are not enough USD to re-buy in the other exchange' do
118
- stub_bitex_orders
119
- BitexBot::Settings.stub(time_to_live: 3,
120
- selling: double(quantity_to_sell_per_order: 4, profit: 50))
125
+ stub_bitex_active_orders
126
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: 4, profit: 50))
121
127
 
122
128
  expect do
123
- flow = BitexBot::SellOpeningFlow.create_for_market(1,
124
- bitstamp_api_wrapper_order_book.asks, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
125
- store)
129
+ flow = BitexBot::SellOpeningFlow.create_for_market(
130
+ 1,
131
+ bitstamp_api_wrapper_order_book.asks,
132
+ bitstamp_api_wrapper_transactions_stub,
133
+ 0.5,
134
+ 0.25,
135
+ store
136
+ )
126
137
 
127
138
  flow.should be_nil
128
139
  BitexBot::SellOpeningFlow.count.should == 0
@@ -130,20 +141,25 @@ describe BitexBot::SellOpeningFlow do
130
141
  end
131
142
 
132
143
  it 'Prioritizes profit from store' do
133
- stub_bitex_orders
134
- BitexBot::Settings.stub(time_to_live: 3,
135
- selling: double(quantity_to_sell_per_order: 2, profit: 0))
144
+ stub_bitex_active_orders
145
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: 2, profit: 0))
136
146
 
137
147
  store = BitexBot::Store.new(selling_profit: 0.5)
138
- flow = BitexBot::SellOpeningFlow.create_for_market(1000,
139
- bitstamp_api_wrapper_order_book.asks, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
140
- store)
148
+ flow = BitexBot::SellOpeningFlow.create_for_market(
149
+ 1000,
150
+ bitstamp_api_wrapper_order_book.asks,
151
+ bitstamp_api_wrapper_transactions_stub,
152
+ 0.5,
153
+ 0.25,
154
+ store
155
+ )
141
156
 
142
157
  flow.price.round(14).should == '20.25112781954887'.to_d
143
158
  end
144
159
  end
145
160
 
146
161
  describe 'when fetching open positions' do
162
+ before(:each) { BitexBot::Robot.setup }
147
163
  let(:flow) { create(:sell_opening_flow) }
148
164
 
149
165
  it 'only gets sells' do
@@ -184,29 +200,29 @@ describe BitexBot::SellOpeningFlow do
184
200
  Bitex::Trade.stub(all: [build(:bitex_sell, id: 23456, order_book: :btc_ars)])
185
201
 
186
202
  flow.order_id.should == 12345
187
- expect do
188
- BitexBot::SellOpeningFlow.sync_open_positions.should be_empty
189
- end.not_to change { BitexBot::OpenSell.count }
203
+ expect { BitexBot::SellOpeningFlow.sync_open_positions.should be_empty }.not_to change { BitexBot::OpenSell.count }
190
204
  BitexBot::OpenSell.count.should == 0
191
205
  end
192
206
 
193
207
  it 'does not register buys from unknown bids' do
194
208
  stub_bitex_transactions
195
209
 
196
- expect do
197
- BitexBot::SellOpeningFlow.sync_open_positions.should be_empty
198
- end.not_to change { BitexBot::OpenSell.count }
210
+ expect { BitexBot::SellOpeningFlow.sync_open_positions.should be_empty }.not_to change { BitexBot::OpenSell.count }
199
211
  end
200
212
  end
201
213
 
202
214
  it 'cancels the associated bitex bid' do
203
- stub_bitex_orders
204
- BitexBot::Settings.stub(time_to_live: 3,
205
- selling: double(quantity_to_sell_per_order: 4, profit: 50))
206
-
207
- flow = BitexBot::SellOpeningFlow.create_for_market(1000,
208
- bitstamp_api_wrapper_order_book.asks, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
209
- store)
215
+ stub_bitex_active_orders
216
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: 4, profit: 50))
217
+
218
+ flow = BitexBot::SellOpeningFlow.create_for_market(
219
+ 1000,
220
+ bitstamp_api_wrapper_order_book.asks,
221
+ bitstamp_api_wrapper_transactions_stub,
222
+ 0.5,
223
+ 0.25,
224
+ store
225
+ )
210
226
 
211
227
  flow.finalise!
212
228
  flow.should be_settling
@@ -215,15 +231,19 @@ describe BitexBot::SellOpeningFlow do
215
231
  end
216
232
 
217
233
  it 'order has expected order book' do
218
- stub_bitex_orders
219
- BitexBot::Settings.stub(time_to_live: 3,
220
- selling: double(quantity_to_sell_per_order: 2, profit: 0))
221
-
222
- flow = subject.class.create_for_market(1000,
223
- bitstamp_api_wrapper_order_book.asks, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
224
- store)
225
-
226
- order = subject.class.order_class.find(flow.order_id)
227
- order.order_book.should eq BitexBot::Settings.maker_settings.order_book
234
+ stub_bitex_active_orders
235
+ BitexBot::Settings.stub(time_to_live: 3, selling: double(quantity_to_sell_per_order: 2, profit: 0))
236
+
237
+ flow = described_class.create_for_market(
238
+ 1000,
239
+ bitstamp_api_wrapper_order_book.asks,
240
+ bitstamp_api_wrapper_transactions_stub,
241
+ 0.5,
242
+ 0.25,
243
+ store
244
+ )
245
+
246
+ order = described_class.order_class.find(flow.order_id)
247
+ order.order_book.should eq BitexBot::Robot.maker.base_quote.to_sym
228
248
  end
229
249
  end
data/spec/spec_helper.rb CHANGED
@@ -7,13 +7,15 @@ BitexBot::Settings.load_test
7
7
  require 'byebug'
8
8
  require 'database_cleaner'
9
9
  require 'factory_bot'
10
+ require 'faker'
11
+ require 'rspec/its'
10
12
  require 'shoulda/matchers'
11
13
  require 'timecop'
12
14
  require 'webmock/rspec'
13
15
 
14
16
  require 'bitex_bot'
15
17
  FactoryBot.find_definitions
16
- Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |file| require file }
18
+ Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
17
19
 
18
20
  # Automatically do rake db:test:prepare
19
21
  ActiveRecord::Migration.maintain_test_schema!
@@ -4,61 +4,101 @@ module BitexStubs
4
4
  mattr_accessor(:active_bids) { {} }
5
5
  mattr_accessor(:active_asks) { {} }
6
6
 
7
- def stub_bitex_orders
8
- Bitex::Order.stub(:all) do
9
- BitexStubs.active_bids + BitexStubs.active_asks
10
- end
7
+ def stub_bitex_active_orders
8
+ Bitex::Order.stub(all: BitexStubs.active_bids.merge(BitexStubs.active_asks))
11
9
 
12
- Bitex::Bid.stub(:find) do |id|
13
- BitexStubs.bids[id]
14
- end
10
+ Bitex::Bid.stub(:find) { |id| BitexStubs.bids[id] }
15
11
 
16
- Bitex::Ask.stub(:find) do |id|
17
- BitexStubs.asks[id]
18
- end
12
+ Bitex::Ask.stub(:find) { |id| BitexStubs.asks[id] }
19
13
 
20
14
  Bitex::Bid.stub(:create!) do |order_book, to_spend, price|
21
- bid = Bitex::Bid.new
22
- bid.id = 12345
23
- bid.created_at = Time.now
24
- bid.price = price
25
- bid.amount = to_spend
26
- bid.remaining_amount = to_spend
27
- bid.status = :executing
28
- bid.order_book = order_book
29
- bid.stub(:cancel!) do
30
- bid.status = :cancelled
31
- BitexStubs.active_bids.delete(bid.id)
32
- bid
15
+ build(:bitex_bid, id: 12_345, order_book: order_book, status: :executing, amount: to_spend, remaining_amount: to_spend, price: price).tap do |bid|
16
+ bid.stub(:cancel!) do
17
+ bid.tap do
18
+ bid.status = :cancelled
19
+ BitexStubs.active_bids.delete(bid.id)
20
+ end
21
+ end
22
+ BitexStubs.bids[bid.id] = bid
23
+ BitexStubs.active_bids[bid.id] = bid
33
24
  end
34
- BitexStubs.bids[bid.id] = bid
35
- BitexStubs.active_bids[bid.id] = bid
36
- bid
37
25
  end
38
26
 
39
27
  Bitex::Ask.stub(:create!) do |order_book, to_sell, price|
40
- ask = Bitex::Ask.new
41
- ask.id = 12345
42
- ask.created_at = Time.now
43
- ask.price = price
44
- ask.quantity = to_sell
45
- ask.remaining_quantity = to_sell
46
- ask.status = :executing
47
- ask.order_book = order_book
48
- ask.stub(:cancel!) do
49
- ask.status = :cancelled
50
- BitexStubs.active_asks.delete(ask.id)
51
- ask
28
+ build(:bitex_ask, id: 12_345, order_book: order_book, quantity: to_sell, remaining_quantity: to_sell, price: price, status: :executing).tap do |ask|
29
+ ask.stub(:cancel!) do
30
+ ask.tap do
31
+ ask.status = :cancelled
32
+ BitexStubs.active_asks.delete(ask.id)
33
+ end
34
+ end
35
+ BitexStubs.asks[ask.id] = ask
36
+ BitexStubs.active_asks[ask.id] = ask
52
37
  end
53
- BitexStubs.asks[ask.id] = ask
54
- BitexStubs.active_asks[ask.id] = ask
55
- ask
56
38
  end
57
39
  end
58
40
 
59
41
  def stub_bitex_transactions(*extra_transactions)
60
42
  Bitex::Trade.stub(all: extra_transactions + [build(:bitex_buy), build(:bitex_sell)])
61
43
  end
44
+
45
+ # {
46
+ # usd_balance: 10000.0,
47
+ # usd_reserved: 2000.0,
48
+ # usd_available: 8000.0,
49
+ # btc_balance: 20.0,
50
+ # btc_reserved: 5.0,
51
+ # btc_available: 15.0,
52
+ # fee: 0.5,
53
+ # btc_deposit_address: "1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
54
+ # }
55
+ def stub_bitex_balance
56
+ Bitex::Profile.stub(:get) do
57
+ {
58
+ usd_balance: 10_000.to_d,
59
+ usd_reserved: 2_000.to_d,
60
+ usd_available: 8_000.to_d,
61
+ btc_balance: 20.to_d,
62
+ btc_reserved: 5.to_d,
63
+ btc_available: 15.to_d,
64
+ fee: 0.5.to_d,
65
+ btc_deposit_address: '1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
66
+ }
67
+ end
68
+ end
69
+
70
+ # <Bitex::Bid:0x007ff7efe1f228
71
+ # @id=12345678, @created_at=1999-12-31 21:10:00 -0300, @order_book=:btc_usd, @price=0.1e4, @status=:received,
72
+ # @reason=:not_cancelled, @issuer="User#1", @amount=0.1e3, @remaining_amount=0.1e3, @produced_quantity=0.1e2
73
+ # >
74
+ # <Bitex::Ask:0x007f94a2658f68
75
+ # @id=12345678, @created_at=1999-12-31 21:10:00 -0300, @order_book=:btc_usd, @price=0.1e4, @status=:received,
76
+ # @reason=:not_cancelled, @issuer="User#1", @quantity=0.1e3, @remaining_quantity=0.1e3, @produced_amount=0.1e2
77
+ # >
78
+ def stub_bitex_orders
79
+ Bitex::Order.stub(all: [build(:bitex_bid), build(:bitex_ask)])
80
+ end
81
+
82
+ def stub_bitex_order_book
83
+ Bitex::MarketData.stub(:order_book) do
84
+ {
85
+ bids: [[639.21, 1.95], [637.0, 0.47], [630.0, 1.58]],
86
+ asks: [[642.4, 0.4], [643.3, 0.95], [644.3, 0.25]]
87
+ }
88
+ end
89
+ end
90
+
91
+ # <Bitex::Buy:0x007ff9a2979390
92
+ # @id=12345678, @created_at=1999-12-31 21:10:00 -0300, @order_book=:btc_usd, @quantity=0.2e1, @amount=0.6e3, @fee=0.5e-1,
93
+ # @price=0.3e3, @bid_id=123
94
+ # >
95
+ # <Bitex::Sell:0x007ff9a2978710
96
+ # @id=12345678, @created_at=1999-12-31 21:10:00 -0300, @order_book=:btc_usd, @quantity=0.2e1, @amount=0.6e3, @fee=0.5e-1,
97
+ # @price=0.3e3, @ask_id=456i
98
+ # >
99
+ def stub_bitex_trades
100
+ Bitex::Trade.stub(all: [build(:bitex_buy), build(:bitex_sell)])
101
+ end
62
102
  end
63
103
 
64
104
  RSpec.configuration.include BitexStubs
@@ -1,6 +1,6 @@
1
1
  module BitstampApiWrapperStubs
2
2
  def stub_bitstamp_api_wrapper_order_book
3
- BitstampApiWrapper.stub(order_book: bitstamp_api_wrapper_order_book)
3
+ BitstampApiWrapper.any_instance.stub(order_book: bitstamp_api_wrapper_order_book)
4
4
  end
5
5
 
6
6
  def bitstamp_api_wrapper_order_book
@@ -16,7 +16,7 @@ module BitstampApiWrapperStubs
16
16
  end
17
17
 
18
18
  def stub_bitstamp_api_wrapper_balance(usd = nil, coin = nil, fee = nil)
19
- BitstampApiWrapper.stub(:balance) do
19
+ BitstampApiWrapper.any_instance.stub(:balance) do
20
20
  ApiWrapper::BalanceSummary.new(
21
21
  ApiWrapper::Balance.new((coin || 10).to_d, 0.to_d, (coin || 10).to_d),
22
22
  ApiWrapper::Balance.new((usd || 100).to_d, 0.to_d, (usd || 100).to_d),
@@ -33,7 +33,7 @@ module BitstampStubs
33
33
  transactions = orders.collect do |o|
34
34
  usd = o.amount * o.price
35
35
  usd, btc = o.type == 0 ? [-usd, o.amount] : [usd, -o.amount]
36
- double(usd: (usd * ratio).to_s, btc: (btc * ratio).to_s,
36
+ Bitstamp::UserTransaction.new(usd: (usd * ratio).to_s, btc: (btc * ratio).to_s,
37
37
  btc_usd: o.price.to_s, order_id: o.id, fee: '0.5', type: 2,
38
38
  datetime: DateTime.now.to_s)
39
39
  end
@@ -50,7 +50,7 @@ module BitstampStubs
50
50
  Bitstamp.orders.stub(all: orders)
51
51
  Bitstamp.orders.stub(:sell) do |args|
52
52
  remote_id = Bitstamp.orders.all.size + 1 if remote_id.nil?
53
- ask = double(amount: args[:amount], price: args[:price], type: 1, id: remote_id,
53
+ ask = Bitstamp::Order.new(amount: args[:amount], price: args[:price], type: 1, id: remote_id,
54
54
  datetime: DateTime.now.to_s)
55
55
  ask.stub(:cancel!) do
56
56
  orders = Bitstamp.orders.all.reject { |o| o.id.to_s == ask.id.to_s && o.type == 1 }
@@ -67,7 +67,7 @@ module BitstampStubs
67
67
  Bitstamp.orders.stub(all: orders)
68
68
  Bitstamp.orders.stub(:buy) do |args|
69
69
  remote_id = Bitstamp.orders.all.size + 1 if remote_id.nil?
70
- bid = double(amount: args[:amount], price: args[:price], type: 0, id: remote_id,
70
+ bid = Bitstamp::Order.new(amount: args[:amount], price: args[:price], type: 0, id: remote_id,
71
71
  datetime: DateTime.now.to_s)
72
72
  bid.stub(:cancel!) do
73
73
  orders = Bitstamp.orders.all.reject { |o| o.id.to_s == bid.id.to_s && o.type == 0 }
@@ -0,0 +1,8 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.allow_http_connections_when_no_cassette = true
5
+ c.hook_into :webmock
6
+ c.cassette_library_dir = 'spec/fixtures'
7
+ c.configure_rspec_metadata!
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'webmock/rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:each) do
5
+ WebMock.reset!
6
+ WebMock.disable_net_connect!(allow_localhost: true)
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitex_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nubis
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-14 00:00:00.000000000 Z
12
+ date: 2019-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4.2'
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '4.2'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: hashie
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -99,16 +99,16 @@ dependencies:
99
99
  name: itbit
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: 0.0.6
104
+ version: '0'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '='
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: 0.0.6
111
+ version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: kraken_client
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +193,20 @@ dependencies:
193
193
  - - ">="
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
+ - !ruby/object:Gem::Dependency
197
+ name: faker
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
196
210
  - !ruby/object:Gem::Dependency
197
211
  name: rspec
198
212
  requirement: !ruby/object:Gem::Requirement
@@ -207,6 +221,20 @@ dependencies:
207
221
  - - ">="
208
222
  - !ruby/object:Gem::Version
209
223
  version: '0'
224
+ - !ruby/object:Gem::Dependency
225
+ name: rspec-its
226
+ requirement: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ type: :development
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
210
238
  - !ruby/object:Gem::Dependency
211
239
  name: rspec-mocks
212
240
  requirement: !ruby/object:Gem::Requirement
@@ -277,6 +305,20 @@ dependencies:
277
305
  - - ">="
278
306
  - !ruby/object:Gem::Version
279
307
  version: '0'
308
+ - !ruby/object:Gem::Dependency
309
+ name: vcr
310
+ requirement: !ruby/object:Gem::Requirement
311
+ requirements:
312
+ - - ">="
313
+ - !ruby/object:Gem::Version
314
+ version: '0'
315
+ type: :development
316
+ prerelease: false
317
+ version_requirements: !ruby/object:Gem::Requirement
318
+ requirements:
319
+ - - ">="
320
+ - !ruby/object:Gem::Version
321
+ version: '0'
280
322
  - !ruby/object:Gem::Dependency
281
323
  name: webmock
282
324
  requirement: !ruby/object:Gem::Requirement
@@ -315,6 +357,7 @@ files:
315
357
  - lib/bitex_bot.rb
316
358
  - lib/bitex_bot/database.rb
317
359
  - lib/bitex_bot/models/api_wrappers/api_wrapper.rb
360
+ - lib/bitex_bot/models/api_wrappers/bitex/bitex_api_wrapper.rb
318
361
  - lib/bitex_bot/models/api_wrappers/bitstamp/bitstamp_api_wrapper.rb
319
362
  - lib/bitex_bot/models/api_wrappers/itbit/itbit_api_wrapper.rb
320
363
  - lib/bitex_bot/models/api_wrappers/kraken/kraken_api_wrapper.rb
@@ -336,12 +379,22 @@ files:
336
379
  - lib/bitex_bot/version.rb
337
380
  - settings.rb.sample
338
381
  - spec/bitex_bot/settings_spec.rb
382
+ - spec/factories/bitex_ask.rb
383
+ - spec/factories/bitex_bid.rb
339
384
  - spec/factories/bitex_buy.rb
340
385
  - spec/factories/bitex_sell.rb
341
386
  - spec/factories/buy_opening_flow.rb
342
387
  - spec/factories/open_buy.rb
343
388
  - spec/factories/open_sell.rb
344
389
  - spec/factories/sell_opening_flow.rb
390
+ - spec/fixtures/bitstamp/balance.yml
391
+ - spec/fixtures/bitstamp/order_book.yml
392
+ - spec/fixtures/bitstamp/orders/all.yml
393
+ - spec/fixtures/bitstamp/orders/failure_sell.yml
394
+ - spec/fixtures/bitstamp/orders/successful_buy.yml
395
+ - spec/fixtures/bitstamp/transactions.yml
396
+ - spec/fixtures/bitstamp/user_transactions.yml
397
+ - spec/models/api_wrappers/bitex_api_wrapper_spec.rb
345
398
  - spec/models/api_wrappers/bitstamp_api_wrapper_spec.rb
346
399
  - spec/models/api_wrappers/itbit_api_wrapper_spec.rb
347
400
  - spec/models/api_wrappers/kraken_api_wrapper_spec.rb
@@ -356,6 +409,8 @@ files:
356
409
  - spec/support/bitex_stubs.rb
357
410
  - spec/support/bitstamp/bitstamp_api_wrapper_stubs.rb
358
411
  - spec/support/bitstamp/bitstamp_stubs.rb
412
+ - spec/support/vcr.rb
413
+ - spec/support/webmock.rb
359
414
  homepage: ''
360
415
  licenses:
361
416
  - MIT
@@ -382,12 +437,22 @@ specification_version: 4
382
437
  summary: A trading robot to do arbitrage between bitex.la and other exchanges!
383
438
  test_files:
384
439
  - spec/bitex_bot/settings_spec.rb
440
+ - spec/factories/bitex_ask.rb
441
+ - spec/factories/bitex_bid.rb
385
442
  - spec/factories/bitex_buy.rb
386
443
  - spec/factories/bitex_sell.rb
387
444
  - spec/factories/buy_opening_flow.rb
388
445
  - spec/factories/open_buy.rb
389
446
  - spec/factories/open_sell.rb
390
447
  - spec/factories/sell_opening_flow.rb
448
+ - spec/fixtures/bitstamp/balance.yml
449
+ - spec/fixtures/bitstamp/order_book.yml
450
+ - spec/fixtures/bitstamp/orders/all.yml
451
+ - spec/fixtures/bitstamp/orders/failure_sell.yml
452
+ - spec/fixtures/bitstamp/orders/successful_buy.yml
453
+ - spec/fixtures/bitstamp/transactions.yml
454
+ - spec/fixtures/bitstamp/user_transactions.yml
455
+ - spec/models/api_wrappers/bitex_api_wrapper_spec.rb
391
456
  - spec/models/api_wrappers/bitstamp_api_wrapper_spec.rb
392
457
  - spec/models/api_wrappers/itbit_api_wrapper_spec.rb
393
458
  - spec/models/api_wrappers/kraken_api_wrapper_spec.rb
@@ -402,3 +467,5 @@ test_files:
402
467
  - spec/support/bitex_stubs.rb
403
468
  - spec/support/bitstamp/bitstamp_api_wrapper_stubs.rb
404
469
  - spec/support/bitstamp/bitstamp_stubs.rb
470
+ - spec/support/vcr.rb
471
+ - spec/support/webmock.rb