From 74c10c45a0b820feda3e2e29d44eb6b1f41bb175 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Mon, 1 Jan 2018 22:57:15 -0200 Subject: [PATCH] Fix cleanup on retries From redo docs: > cleanup (callable): optional; called if one of retry_exceptions is caught. __No arguments are passed to the cleanup function__; if your cleanup requires arguments, consider using functools.partial or a lambda function. --- catalyst/exchange/exchange_algorithm.py | 26 ++++++----------------- catalyst/exchange/exchange_blotter.py | 10 +++------ catalyst/exchange/exchange_data_portal.py | 14 ++++-------- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index bffe7d1f..5c395618 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -655,10 +655,7 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): attempts=self.attempts['synchronize_portfolio_attempts'], sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'ordering again: {}'.format(e) - ), - ) + cleanup=lambda: log.warn('Ordering again.')) log.info( 'got totals from exchanges, cash: {} positions: {}'.format( cash, positions_value @@ -807,11 +804,8 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): attempts=self.attempts['get_open_orders_attempts'], sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'fetching open orders again: {}'.format(e) - ), - args=(asset,) - ) + cleanup=lambda: log.warn('Fetching open orders again.'), + args=(asset,)) @api_method def get_order(self, order_id, exchange_name): @@ -836,11 +830,8 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): attempts=self.attempts['get_order_attempts'], sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'fetching orders again: {}'.format(e) - ), - args=(order_id,) - ) + cleanup=lambda: log.warn('Fetching orders again.'), + args=(order_id,)) @api_method def cancel_order(self, order_param, exchange_name): @@ -862,8 +853,5 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): attempts=self.attempts['cancel_order_attempts'], sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'cancelling order again: {}'.format(e) - ), - args=(order_id,) - ) + cleanup=lambda: log.warn('cancelling order again.'), + args=(order_id,)) diff --git a/catalyst/exchange/exchange_blotter.py b/catalyst/exchange/exchange_blotter.py index 530161e2..5c0023fd 100644 --- a/catalyst/exchange/exchange_blotter.py +++ b/catalyst/exchange/exchange_blotter.py @@ -175,9 +175,7 @@ class ExchangeBlotter(Blotter): attempts=self.attempts['order_attempts'], sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'ordering again: {}'.format(e) - ), + cleanup=lambda: log.warn('Ordering again.'), args=(asset, amount, style), ) @@ -270,7 +268,5 @@ class ExchangeBlotter(Blotter): attempts=self.attempts['get_transactions_attempts'], sleeptime=self.retry_sleeptime, retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'fetching exchange transactions again: {}'.format(e) - ), - ) + cleanup=lambda: log.warn( + 'Fetching exchange transactions again.')) diff --git a/catalyst/exchange/exchange_data_portal.py b/catalyst/exchange/exchange_data_portal.py index aaa38a5f..ad6b6d51 100644 --- a/catalyst/exchange/exchange_data_portal.py +++ b/catalyst/exchange/exchange_data_portal.py @@ -92,17 +92,14 @@ class DataPortalExchangeBase(DataPortal): attempts=self.attempts['get_history_window_attempts'], sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'fetching history again: {}'.format(e) - ), + cleanup=lambda: log.warn('fetching history again.'), args=(assets, end_dt, bar_count, frequency, field, data_frequency, - ffill) - ) + ffill)) @abc.abstractmethod def get_exchange_history_window(self, @@ -166,11 +163,8 @@ class DataPortalExchangeBase(DataPortal): attempts=self.attempts['get_spot_value_attempts'], sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), - cleanup=lambda e: log.warn( - 'fetching spot value again: {}'.format(e) - ), - args=(assets, field, dt, data_frequency), - ) + cleanup=lambda: log.warn('fetching spot value again.'), + args=(assets, field, dt, data_frequency)) @abc.abstractmethod def get_exchange_spot_value(self, exchange_name, assets, field, dt,