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::BuyOpeningFlow 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,19 +13,23 @@ describe BitexBot::BuyOpeningFlow do
13
13
 
14
14
  describe 'when creating a buying flow' do
15
15
  it 'spends 50 usd' do
16
- stub_bitex_orders
17
- BitexBot::Settings.stub(time_to_live: 3,
18
- buying: double(amount_to_spend_per_order: 50, profit: 0))
19
-
20
- flow = BitexBot::BuyOpeningFlow.create_for_market(100,
21
- bitstamp_api_wrapper_order_book.bids, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
22
- store)
16
+ stub_bitex_active_orders
17
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: 50, profit: 0))
18
+
19
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
20
+ 100,
21
+ bitstamp_api_wrapper_order_book.bids,
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 == 50
30
+ flow.suggested_closing_price.should == 20
26
31
  flow.price.should <= flow.suggested_closing_price
27
32
  flow.price.round(14).should == '19.85074626865672'.to_d
28
- flow.suggested_closing_price.should == 20
29
33
  end
30
34
 
31
35
  let(:order_id) { 12_345 }
@@ -39,49 +43,44 @@ describe BitexBot::BuyOpeningFlow do
39
43
  it 'spends 100 usd' do
40
44
  suggested_closing_price = 15.to_d
41
45
 
42
- BitexBot::Settings.stub(
43
- time_to_live: 3,
44
- buying: double(amount_to_spend_per_order: amount_to_spend, profit: 0)
46
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: amount_to_spend, profit: 0))
47
+ stub_bitex_active_orders
48
+
49
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
50
+ btc_balance,
51
+ order_book,
52
+ transactions,
53
+ maker_fee,
54
+ taker_fee,
55
+ store
45
56
  )
46
- stub_bitex_orders
47
-
48
- flow =
49
- BitexBot::BuyOpeningFlow.create_for_market(
50
- btc_balance,
51
- order_book,
52
- transactions,
53
- maker_fee,
54
- taker_fee,
55
- store
56
- )
57
57
 
58
58
  flow.order_id.should eq order_id
59
59
  flow.value_to_use.should eq amount_to_spend
60
- flow.price.should <= suggested_closing_price
61
60
  flow.suggested_closing_price.should eq suggested_closing_price
61
+ flow.price.should <= suggested_closing_price
62
62
  end
63
63
 
64
64
  let(:other_fx_rate) { 10.to_d }
65
65
 
66
66
  it 'spends 100 usd with other fx_rate' do
67
- suggested_closing_price = 25.to_d
67
+ suggested_closing_price = 15.to_d
68
68
 
69
69
  BitexBot::Settings.stub(
70
70
  buying_foreign_exchange_rate: other_fx_rate,
71
71
  time_to_live: 3,
72
72
  buying: double(amount_to_spend_per_order: amount_to_spend, profit: 0)
73
73
  )
74
- stub_bitex_orders
75
-
76
- flow =
77
- BitexBot::BuyOpeningFlow.create_for_market(
78
- btc_balance,
79
- order_book,
80
- transactions,
81
- maker_fee,
82
- taker_fee,
83
- store
84
- )
74
+ stub_bitex_active_orders
75
+
76
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
77
+ btc_balance,
78
+ order_book,
79
+ transactions,
80
+ maker_fee,
81
+ taker_fee,
82
+ store
83
+ )
85
84
 
86
85
  flow.order_id.should eq order_id
87
86
  flow.value_to_use.should eq amount_to_spend
@@ -90,13 +89,17 @@ describe BitexBot::BuyOpeningFlow do
90
89
  end
91
90
 
92
91
  it 'lowers the price to pay on bitex to take a profit' do
93
- stub_bitex_orders
94
- BitexBot::Settings.stub(time_to_live: 3,
95
- buying: double(amount_to_spend_per_order: 100, profit: 50.to_d))
96
-
97
- flow = BitexBot::BuyOpeningFlow.create_for_market(100000,
98
- bitstamp_api_wrapper_order_book.bids, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
99
- store)
92
+ stub_bitex_active_orders
93
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: 100, profit: 50.to_d))
94
+
95
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
96
+ 100_000,
97
+ bitstamp_api_wrapper_order_book.bids,
98
+ bitstamp_api_wrapper_transactions_stub,
99
+ 0.5,
100
+ 0.25,
101
+ store
102
+ )
100
103
 
101
104
  flow.order_id.should == 12345
102
105
  flow.value_to_use.should == 100
@@ -108,13 +111,17 @@ describe BitexBot::BuyOpeningFlow do
108
111
  it 'fails when there is a problem placing the bid on bitex' do
109
112
  Bitex::Bid.stub(:create!) { raise StandardError.new('Cannot Create') }
110
113
 
111
- BitexBot::Settings.stub(time_to_live: 3,
112
- buying: double(amount_to_spend_per_order: 100, profit: 0))
114
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: 100, profit: 0))
113
115
 
114
116
  expect do
115
- flow = BitexBot::BuyOpeningFlow.create_for_market(100000,
116
- bitstamp_api_wrapper_order_book.bids, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
117
- store)
117
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
118
+ 100_000,
119
+ bitstamp_api_wrapper_order_book.bids,
120
+ bitstamp_api_wrapper_transactions_stub,
121
+ 0.5,
122
+ 0.25,
123
+ store
124
+ )
118
125
 
119
126
  flow.should be_nil
120
127
  BitexBot::BuyOpeningFlow.count.should == 0
@@ -122,14 +129,18 @@ describe BitexBot::BuyOpeningFlow do
122
129
  end
123
130
 
124
131
  it 'fails when there are not enough bitcoin to sell in the other exchange' do
125
- stub_bitex_orders
126
- BitexBot::Settings.stub(time_to_live: 3,
127
- buying: double(amount_to_spend_per_order: 100, profit: 0))
132
+ stub_bitex_active_orders
133
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: 100, profit: 0))
128
134
 
129
135
  expect do
130
- flow = BitexBot::BuyOpeningFlow.create_for_market(1,
131
- bitstamp_api_wrapper_order_book.bids, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
132
- store)
136
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
137
+ 1,
138
+ bitstamp_api_wrapper_order_book.bids,
139
+ bitstamp_api_wrapper_transactions_stub,
140
+ 0.5,
141
+ 0.25,
142
+ store
143
+ )
133
144
 
134
145
  flow.should be_nil
135
146
  BitexBot::BuyOpeningFlow.count.should == 0
@@ -138,13 +149,17 @@ describe BitexBot::BuyOpeningFlow do
138
149
 
139
150
  it 'prioritizes profit from store' do
140
151
  store = BitexBot::Store.new(buying_profit: 0.5)
141
- stub_bitex_orders
142
- BitexBot::Settings.stub(time_to_live: 3,
143
- buying: double(amount_to_spend_per_order: 50, profit: 0))
144
-
145
- flow = BitexBot::BuyOpeningFlow.create_for_market(100,
146
- bitstamp_api_wrapper_order_book.bids, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
147
- store)
152
+ stub_bitex_active_orders
153
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: 50, profit: 0))
154
+
155
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
156
+ 100,
157
+ bitstamp_api_wrapper_order_book.bids,
158
+ bitstamp_api_wrapper_transactions_stub,
159
+ 0.5,
160
+ 0.25,
161
+ store
162
+ )
148
163
 
149
164
  flow.price.round(13).should == '19.7514925373134'.to_d
150
165
  end
@@ -186,32 +201,32 @@ describe BitexBot::BuyOpeningFlow do
186
201
  end
187
202
 
188
203
  it 'does not register buys from another order book' do
189
- flow.order_id.should == 12345
190
204
  Bitex::Trade.stub(all: [build(:bitex_buy, id: 23456, order_book: :btc_ars)])
191
205
 
192
- expect do
193
- BitexBot::BuyOpeningFlow.sync_open_positions.should be_empty
194
- end.not_to change { BitexBot::OpenBuy.count }
206
+ flow.order_id.should == 12345
207
+ expect { BitexBot::BuyOpeningFlow.sync_open_positions.should be_empty }.not_to change { BitexBot::OpenBuy.count }
195
208
  BitexBot::OpenBuy.count.should == 0
196
209
  end
197
210
 
198
211
  it 'does not register buys from unknown bids' do
199
212
  stub_bitex_transactions
200
213
 
201
- expect do
202
- BitexBot::BuyOpeningFlow.sync_open_positions.should be_empty
203
- end.not_to change { BitexBot::OpenBuy.count }
214
+ expect { BitexBot::BuyOpeningFlow.sync_open_positions.should be_empty }.not_to change { BitexBot::OpenBuy.count }
204
215
  end
205
216
  end
206
217
 
207
218
  it 'cancels the associated bitex bid' do
208
- stub_bitex_orders
209
- BitexBot::Settings.stub(time_to_live: 3,
210
- buying: double(amount_to_spend_per_order: 50, profit: 0))
211
-
212
- flow = BitexBot::BuyOpeningFlow.create_for_market(100,
213
- bitstamp_api_wrapper_order_book.bids, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
214
- store)
219
+ stub_bitex_active_orders
220
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: 50, profit: 0))
221
+
222
+ flow = BitexBot::BuyOpeningFlow.create_for_market(
223
+ 100,
224
+ bitstamp_api_wrapper_order_book.bids,
225
+ bitstamp_api_wrapper_transactions_stub,
226
+ 0.5,
227
+ 0.25,
228
+ store
229
+ )
215
230
 
216
231
  flow.finalise!
217
232
  flow.should be_settling
@@ -220,15 +235,19 @@ describe BitexBot::BuyOpeningFlow do
220
235
  end
221
236
 
222
237
  it 'order has expected order book' do
223
- stub_bitex_orders
224
- BitexBot::Settings.stub(time_to_live: 3,
225
- buying: double(amount_to_spend_per_order: 50, profit: 0))
226
-
227
- flow = subject.class.create_for_market(100,
228
- bitstamp_api_wrapper_order_book.bids, bitstamp_api_wrapper_transactions_stub, 0.5, 0.25,
229
- store)
238
+ stub_bitex_active_orders
239
+ BitexBot::Settings.stub(time_to_live: 3, buying: double(amount_to_spend_per_order: 50, profit: 0))
240
+
241
+ flow = subject.class.create_for_market(
242
+ 100,
243
+ bitstamp_api_wrapper_order_book.bids,
244
+ bitstamp_api_wrapper_transactions_stub,
245
+ 0.5,
246
+ 0.25,
247
+ store
248
+ )
230
249
 
231
250
  order = subject.class.order_class.find(flow.order_id)
232
- order.order_book.should eq BitexBot::Settings.maker_settings.order_book
251
+ order.order_book.should eq BitexBot::Robot.maker.base_quote.to_sym
233
252
  end
234
253
  end
@@ -1,6 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BitexBot::OrderBookSimulator do
4
+ before(:each) do
5
+ BitexBot::Robot.taker = double(base: 'btc', quote: 'usd')
6
+ BitexBot::Robot.maker = double(base: 'btc', quote: 'usd')
7
+ end
8
+
4
9
  describe 'when buying on bitex to sell somewhere else' do
5
10
  def simulate(volatility, amount)
6
11
  BitexBot::OrderBookSimulator.run(volatility, bitstamp_api_wrapper_transactions_stub,
@@ -4,7 +4,10 @@ describe BitexBot::Robot do
4
4
  let(:taker_settings) do
5
5
  BitexBot::SettingsClass.new(
6
6
  bitstamp: {
7
- api_key: 'YOUR_API_KEY', secret: 'YOUR_API_SECRET', client_id: 'YOUR_BITSTAMP_USERNAME'
7
+ api_key: 'YOUR_API_KEY',
8
+ secret: 'YOUR_API_SECRET',
9
+ client_id: 'YOUR_BITSTAMP_USERNAME',
10
+ order_book: 'btcusd'
8
11
  }
9
12
  )
10
13
  end
@@ -35,7 +38,7 @@ describe BitexBot::Robot do
35
38
  ltc_reserved: 100.00000000, # LTC reserved in open orders
36
39
  ltc_available: 150.00000000 # LTC available for trading
37
40
  })
38
- stub_bitex_orders
41
+ stub_bitex_active_orders
39
42
  stub_bitstamp_sell
40
43
  stub_bitstamp_buy
41
44
  stub_bitstamp_api_wrapper_balance
@@ -47,7 +50,7 @@ describe BitexBot::Robot do
47
50
  let(:bot) { BitexBot::Robot.new }
48
51
 
49
52
  it 'Starts out by creating opening flows that timeout' do
50
- stub_bitex_orders
53
+ stub_bitex_active_orders
51
54
  stub_bitstamp_api_wrapper_order_book
52
55
  bot.trade!
53
56
 
@@ -187,7 +190,7 @@ describe BitexBot::Robot do
187
190
  end
188
191
 
189
192
  it 'notifies exceptions and sleeps' do
190
- BitstampApiWrapper.stub(:balance) { raise StandardError.new('oh moova') }
193
+ BitstampApiWrapper.any_instance.stub(:balance) { raise StandardError.new('oh moova') }
191
194
 
192
195
  expect { bot.trade! }.to change { Mail::TestMailer.deliveries.count }.by(1)
193
196
  end
@@ -4,7 +4,10 @@ describe BitexBot::SellClosingFlow do
4
4
  let(:taker_settings) do
5
5
  BitexBot::SettingsClass.new(
6
6
  bitstamp: {
7
- api_key: 'YOUR_API_KEY', secret: 'YOUR_API_SECRET', client_id: 'YOUR_BITSTAMP_USERNAME'
7
+ api_key: 'YOUR_API_KEY',
8
+ secret: 'YOUR_API_SECRET',
9
+ client_id: 'YOUR_BITSTAMP_USERNAME',
10
+ order_book: 'btcusd'
8
11
  }
9
12
  )
10
13
  end
@@ -61,8 +64,8 @@ describe BitexBot::SellClosingFlow do
61
64
 
62
65
  describe 'when there are errors placing the closing order' do
63
66
  it 'keeps trying to place a closed position on bitstamp errors' do
64
- BitstampApiWrapper.stub(send_order: nil)
65
- BitstampApiWrapper.stub(find_lost: nil)
67
+ BitstampApiWrapper.any_instance.stub(send_order: nil)
68
+ BitstampApiWrapper.any_instance.stub(find_lost: nil)
66
69
 
67
70
  open = create :open_sell
68
71
  expect do
@@ -81,9 +84,9 @@ describe BitexBot::SellClosingFlow do
81
84
  end
82
85
 
83
86
  it 'retries until it finds the lost order' do
84
- BitstampApiWrapper.stub(send_order: nil)
85
- BitstampApiWrapper.stub(:orders) do
86
- [BitstampApiWrapper::Order.new(1, :buy, 290, 2, 1.minute.ago.to_i)]
87
+ BitstampApiWrapper.any_instance.stub(send_order: nil)
88
+ BitstampApiWrapper.any_instance.stub(:orders) do
89
+ [ApiWrapper::Order.new(1, :buy, 290, 2, 1.minute.ago.to_i)]
87
90
  end
88
91
 
89
92
  open = create(:open_sell)
@@ -126,7 +129,7 @@ describe BitexBot::SellClosingFlow do
126
129
  flow = BitexBot::SellClosingFlow.last
127
130
  stub_bitstamp_orders_into_transactions
128
131
 
129
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
132
+ flow.sync_closed_positions
130
133
 
131
134
  close = flow.close_positions.last
132
135
  close.amount.should == '583.905'.to_d
@@ -147,7 +150,7 @@ describe BitexBot::SellClosingFlow do
147
150
  subject.class.close_open_positions
148
151
 
149
152
  stub_bitstamp_orders_into_transactions
150
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
153
+ flow.sync_closed_positions
151
154
  end
152
155
 
153
156
  it 'syncs the executed orders, calculates profit with other fx rate' do
@@ -161,13 +164,11 @@ describe BitexBot::SellClosingFlow do
161
164
  BitexBot::SellClosingFlow.close_open_positions
162
165
  flow = BitexBot::SellClosingFlow.last
163
166
 
164
- expect do
165
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
166
- end.not_to change{ BitexBot::CloseSell.count }
167
+ expect { flow.sync_closed_positions }.not_to change{ BitexBot::CloseSell.count }
167
168
  flow.should_not be_done
168
169
 
169
170
  # Immediately calling sync again does not try to cancel the ask.
170
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
171
+ flow.sync_closed_positions
171
172
  Bitstamp.orders.all.size.should == 1
172
173
 
173
174
  # Partially executes order, and 61 seconds after that
@@ -175,18 +176,15 @@ describe BitexBot::SellClosingFlow do
175
176
  stub_bitstamp_orders_into_transactions(ratio: 0.5)
176
177
  Timecop.travel 61.seconds.from_now
177
178
  Bitstamp.orders.all.size.should == 1
178
- expect do
179
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
180
- end.not_to change{ BitexBot::CloseSell.count }
179
+ expect { flow.sync_closed_positions }.not_to change{ BitexBot::CloseSell.count }
180
+
181
181
  Bitstamp.orders.all.size.should == 0
182
182
  flow.should_not be_done
183
183
 
184
184
  # Next time we try to sync_closed_positions the flow
185
185
  # detects the previous close_buy was cancelled correctly so
186
186
  # it syncs it's total amounts and tries to place a new one.
187
- expect do
188
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
189
- end.to change{ BitexBot::CloseSell.count }.by(1)
187
+ expect { flow.sync_closed_positions }.to change{ BitexBot::CloseSell.count }.by(1)
190
188
 
191
189
  flow.close_positions.first.tap do |close|
192
190
  close.amount.should == '291.9525'.to_d
@@ -197,7 +195,7 @@ describe BitexBot::SellClosingFlow do
197
195
  # this closing flow done.
198
196
  stub_bitstamp_orders_into_transactions
199
197
 
200
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
198
+ flow.sync_closed_positions
201
199
  flow.close_positions.last.tap do |close|
202
200
  close.amount.should == '291.953597'.to_d
203
201
  close.quantity.should == '1.0049'.to_d
@@ -213,15 +211,13 @@ describe BitexBot::SellClosingFlow do
213
211
 
214
212
  20.times do
215
213
  Timecop.travel 60.seconds.from_now
216
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
214
+ flow.sync_closed_positions
217
215
  end
218
216
 
219
217
  stub_bitstamp_orders_into_transactions(ratio: 0.999)
220
218
  Bitstamp.orders.all.first.cancel!
221
219
 
222
- expect do
223
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
224
- end.not_to change{ BitexBot::CloseSell.count }
220
+ expect { flow.sync_closed_positions }.not_to change{ BitexBot::CloseSell.count }
225
221
 
226
222
  flow.should be_done
227
223
  flow.crypto_profit.should == '-0.0224895'.to_d
@@ -236,12 +232,12 @@ describe BitexBot::SellClosingFlow do
236
232
 
237
233
  60.times do
238
234
  Timecop.travel 60.seconds.from_now
239
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
235
+ flow.sync_closed_positions
240
236
  end
241
237
 
242
238
  stub_bitstamp_orders_into_transactions
243
239
 
244
- flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
240
+ flow.sync_closed_positions
245
241
  flow.reload.should be_done
246
242
  flow.crypto_profit.should == '-0.1709'.to_d
247
243
  flow.fiat_profit.should == '20.08575'.to_d