mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-10 11:50:32 +08:00
BUG: revert previous changes #249
This commit is contained in:
@@ -662,20 +662,16 @@ class Exchange:
|
|||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
def _check_low_balance(self, currency, balances, amount, open_orders=None):
|
def _check_low_balance(self, currency, balances, amount):
|
||||||
free = balances[currency]['free'] if currency in balances else 0.0
|
free = balances[currency]['free'] if currency in balances else 0.0
|
||||||
|
|
||||||
if open_orders:
|
|
||||||
# TODO: make sure that this works
|
|
||||||
free += sum([order.amount for order in open_orders])
|
|
||||||
|
|
||||||
if free < amount:
|
if free < amount:
|
||||||
return free, True
|
return free, True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return free, False
|
return free, False
|
||||||
|
|
||||||
def sync_positions(self, positions, open_orders=None, cash=None,
|
def sync_positions(self, positions, cash=None,
|
||||||
check_balances=False):
|
check_balances=False):
|
||||||
"""
|
"""
|
||||||
Update the portfolio cash and position balances based on the
|
Update the portfolio cash and position balances based on the
|
||||||
|
|||||||
@@ -638,6 +638,15 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase):
|
|||||||
if asset_orders:
|
if asset_orders:
|
||||||
orders += asset_orders
|
orders += asset_orders
|
||||||
|
|
||||||
|
required_cash = self.portfolio.cash if not orders else None
|
||||||
|
cash, positions_value = exchange.sync_positions(
|
||||||
|
positions=exchange_positions,
|
||||||
|
check_balances=check_balances,
|
||||||
|
cash=required_cash,
|
||||||
|
)
|
||||||
|
total_cash += cash
|
||||||
|
total_positions_value += positions_value
|
||||||
|
|
||||||
# Applying modifications to the original positions
|
# Applying modifications to the original positions
|
||||||
for position in exchange_positions:
|
for position in exchange_positions:
|
||||||
tracker.update_position(
|
tracker.update_position(
|
||||||
@@ -647,16 +656,6 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase):
|
|||||||
last_sale_price=position.last_sale_price,
|
last_sale_price=position.last_sale_price,
|
||||||
)
|
)
|
||||||
|
|
||||||
required_cash = self.portfolio.cash if not orders else None
|
|
||||||
cash, positions_value = exchange.sync_positions(
|
|
||||||
positions=exchange_positions,
|
|
||||||
open_orders=orders,
|
|
||||||
check_balances=check_balances,
|
|
||||||
cash=required_cash,
|
|
||||||
)
|
|
||||||
total_cash += cash
|
|
||||||
total_positions_value += positions_value
|
|
||||||
|
|
||||||
if not check_balances:
|
if not check_balances:
|
||||||
total_cash = self.portfolio.cash
|
total_cash = self.portfolio.cash
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user