BLD: trying redo for retrying calls as suggesting in issue #121

This commit is contained in:
Frederic Fortier
2017-12-29 16:14:26 -05:00
parent 8e232ac5ef
commit b1f49d3c8d
2 changed files with 18 additions and 24 deletions
+17 -24
View File
@@ -3,6 +3,7 @@ from time import sleep
import pandas as pd import pandas as pd
from catalyst.assets._assets import TradingPair from catalyst.assets._assets import TradingPair
from logbook import Logger from logbook import Logger
from redo import retry
from catalyst.constants import LOG_LEVEL from catalyst.constants import LOG_LEVEL
from catalyst.exchange.exchange_errors import ExchangeRequestError, \ from catalyst.exchange.exchange_errors import ExchangeRequestError, \
@@ -260,40 +261,32 @@ class ExchangeBlotter(Blotter):
) )
) )
def get_exchange_transactions(self, attempt_index=0): def get_exchange_transactions(self):
closed_orders = [] closed_orders = []
transactions = [] transactions = []
commissions = [] commissions = []
try: for order, txn in self.check_open_orders():
for order, txn in self.check_open_orders(): order.dt = txn.dt
order.dt = txn.dt
transactions.append(txn) transactions.append(txn)
if not order.open: if not order.open:
closed_orders.append(order) closed_orders.append(order)
return transactions, commissions, closed_orders return transactions, commissions, closed_orders
except ExchangeRequestError as e:
log.warn(
'check open orders attempt {}: {}'.format(attempt_index, e)
)
if attempt_index < self.retry_check_open_orders:
sleep(self.retry_delay)
return self.get_exchange_transactions(attempt_index + 1)
else:
raise ExchangePortfolioDataError(
data_type='order-status',
attempts=attempt_index,
error=e
)
def get_transactions(self, bar_data): def get_transactions(self, bar_data):
if self.simulate_orders: if self.simulate_orders:
return super(ExchangeBlotter, self).get_transactions(bar_data) return super(ExchangeBlotter, self).get_transactions(bar_data)
else: else:
return self.get_exchange_transactions() return retry(
action=self.get_exchange_transactions,
attempts=self.retry_check_open_orders,
sleeptime=self.retry_delay,
retry_exceptions=ExchangeRequestError,
cleanup=lambda e: log.warn(
'fetching exchange transactions again: {}'.format(e)
)
)
+1
View File
@@ -83,3 +83,4 @@ tables==3.3.0
#Catalyst dependencies #Catalyst dependencies
ccxt==1.10.283 ccxt==1.10.283
boto3==1.4.8 boto3==1.4.8
redo==1.6