From e56e1f8e21188df373182a8afcec5cdad97d0cfa Mon Sep 17 00:00:00 2001 From: Frederic Fortier Date: Thu, 8 Feb 2018 17:26:48 -0500 Subject: [PATCH] BUG: fixed an issue with open orders --- catalyst/examples/buy_low_sell_high.py | 6 +++--- catalyst/exchange/exchange_algorithm.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/catalyst/examples/buy_low_sell_high.py b/catalyst/examples/buy_low_sell_high.py index 7dc95b5b..075e2f71 100644 --- a/catalyst/examples/buy_low_sell_high.py +++ b/catalyst/examples/buy_low_sell_high.py @@ -60,7 +60,7 @@ def _handle_data(context, data): rsi=rsi, ) - orders = get_open_orders(context.asset) + orders = context.blotter.open_orders if orders: log.info('skipping bar until all open orders execute') return @@ -146,11 +146,11 @@ if __name__ == '__main__': live = True if live: run_algorithm( - capital_base=0.001, + capital_base=1000, initialize=initialize, handle_data=handle_data, analyze=analyze, - exchange_name='binance', + exchange_name='bittrex', live=True, algo_namespace=algo_namespace, base_currency='btc', diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index da4aee11..aeff9e4e 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -391,8 +391,6 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): log.warn("Can't initialize signal handler inside another thread." "Exit should be handled by the user.") - log.info('initialized trading algorithm in live mode') - def interrupt_algorithm(self): self.is_running = False @@ -874,6 +872,13 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): raise NotImplementedError() def _get_open_orders(self, asset=None): + if self.simulate_orders: + raise ValueError( + 'The get_open_orders() method only works in live mode. ' + 'The purpose is to list open orders on the exchange ' + 'regardless who placed them. To list the open orders of ' + 'this algo, use `context.blotter.open_orders`.' + ) if asset: exchange = self.exchanges[asset.exchange] return exchange.get_open_orders(asset) @@ -907,6 +912,7 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): If an asset is passed then this will return a list of the open orders for this asset. """ + # TODO: should this be a shortcut to the open orders in the blotter? return retry( action=self._get_open_orders, attempts=self.attempts['get_open_orders_attempts'],