BUG: trying to mitigate a date adjustment issue which occurs sometimes sometimes in live trading especially with Bitrrex at certain frequencies.

This commit is contained in:
Frederic Fortier
2017-12-12 13:34:18 -05:00
parent 021e1fd8c8
commit f2e4637f29
9 changed files with 112 additions and 52 deletions
+13 -5
View File
@@ -498,13 +498,18 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase):
exchange_positions = \
[positions[asset] for asset in assets]
exchange = self.exchanges[exchange_name] # Type: Exchange
cash, positions_value = \
exchange.calculate_totals(exchange_positions)
check_cash = (not self.simulate_orders)
total_cash += cash
exchange = self.exchanges[exchange_name] # Type: Exchange
cash, positions_value = exchange.calculate_totals(
positions=exchange_positions,
check_cash=check_cash,
)
total_positions_value += positions_value
if cash is not None:
total_cash += cash
for position in exchange_positions:
tracker.update_position(
asset=position.asset,
@@ -512,7 +517,10 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase):
last_sale_price=position.last_sale_price
)
if total_cash < self.portfolio.cash:
if cash is None:
total_cash = self.portfolio.cash
elif total_cash < self.portfolio.cash:
raise ValueError('Cash on exchanges is lower than the algo.')
return total_cash, total_positions_value