From 33f94b3ef935272efcbd2e7bd1459cfc903c005f Mon Sep 17 00:00:00 2001 From: Frederic Fortier Date: Sun, 7 Jan 2018 02:32:12 -0500 Subject: [PATCH] BLD: for issue #144, skipped cash verification when there are open orders. --- catalyst/examples/mean_reversion_simple.py | 4 ++-- catalyst/exchange/exchange_algorithm.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/catalyst/examples/mean_reversion_simple.py b/catalyst/examples/mean_reversion_simple.py index 1ba812a2..f5b89d73 100644 --- a/catalyst/examples/mean_reversion_simple.py +++ b/catalyst/examples/mean_reversion_simple.py @@ -37,8 +37,8 @@ def initialize(context): context.base_price = None context.current_day = None - context.RSI_OVERSOLD = 45 - context.RSI_OVERBOUGHT = 55 + context.RSI_OVERSOLD = 50 + context.RSI_OVERBOUGHT = 60 context.CANDLE_SIZE = '5T' context.start_time = time.time() diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index 87bff941..1f4063f4 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -582,10 +582,18 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): if base_currency is None: base_currency = exchange.base_currency + # Don't check the cash if there are open orders. This could + # results in false positives. + orders = [] + for asset in self.blotter.open_orders: + asset_orders = self.blotter.open_orders[asset] + 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=self.portfolio.cash, + cash=required_cash, ) total_cash += cash total_positions_value += positions_value