diff --git a/catalyst/examples/mean_reversion_simple.py b/catalyst/examples/mean_reversion_simple.py index db0a90c3..da49e542 100644 --- a/catalyst/examples/mean_reversion_simple.py +++ b/catalyst/examples/mean_reversion_simple.py @@ -279,5 +279,5 @@ if __name__ == '__main__': base_currency='eth', live_graph=False, simulate_orders=False, - stats_output='s3://something' + stats_output=None ) diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index 013fc618..9745a876 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -625,6 +625,21 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): ) )) + today = pd.to_datetime('today', utc=True) + daily_stats = self.prepare_period_stats( + start_dt=today, + end_dt=pd.Timestamp.utcnow() + ) + save_algo_object( + algo_name=self.algo_namespace, + key=today.strftime('%Y-%m-%d'), + obj=daily_stats, + rel_path='daily_perf' + ) + except Exception as e: + log.warn('unable to calculate performance: {}'.format(e)) + + try: if self.stats_output is not None: if 's3://' in self.stats_output: stats_to_s3( @@ -638,22 +653,8 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase): raise ValueError( 'Only S3 stats output is supported for now.' ) - - today = pd.to_datetime('today', utc=True) - daily_stats = self.prepare_period_stats( - start_dt=today, - end_dt=pd.Timestamp.utcnow() - ) - save_algo_object( - algo_name=self.algo_namespace, - key=today.strftime('%Y-%m-%d'), - obj=daily_stats, - rel_path='daily_perf' - ) - except Exception as e: - log.warn('unable to calculate performance: {}'.format(e)) - + log.warn('unable save stats: {}'.format(e)) # TODO: pickle does not seem to work in python 3 try: save_algo_object( diff --git a/catalyst/exchange/exchange_blotter.py b/catalyst/exchange/exchange_blotter.py index 79757221..df8b352d 100644 --- a/catalyst/exchange/exchange_blotter.py +++ b/catalyst/exchange/exchange_blotter.py @@ -147,6 +147,9 @@ class ExchangeBlotter(Blotter): TradingPair: TradingPairFeeSchedule() } + self.retry_delay = 5 + self.retry_check_open_orders = 5 + def exchange_order(self, asset, amount, style=None, attempt_index=0): try: exchange = self.exchanges[asset.exchange] @@ -205,13 +208,25 @@ class ExchangeBlotter(Blotter): for order in self.open_orders[asset]: log.debug('found open order: {}'.format(order.id)) - order, executed_price = exchange.get_order(order.id, asset) + new_order, executed_price = exchange.get_order(order.id, asset) log.debug( 'got updated order {} {}'.format( - order, executed_price + new_order, executed_price ) ) + order.status = new_order.status + if order.status == ORDER_STATUS.FILLED: + order.commission = new_order.commission + if order.amount != new_order.amount: + log.warn( + 'executed order amount {} differs ' + 'from original'.format( + new_order.amount, order.amount + ) + ) + order.amount = new_order.amount + transaction = Transaction( asset=order.asset, amount=order.amount, diff --git a/catalyst/exchange/stats_utils.py b/catalyst/exchange/stats_utils.py index 77f4d283..3b486b77 100644 --- a/catalyst/exchange/stats_utils.py +++ b/catalyst/exchange/stats_utils.py @@ -2,8 +2,11 @@ import numbers import numpy as np import pandas as pd +import boto3 import time +s3 = boto3.resource('s3') + def trend_direction(series): if series[-1] is np.nan or series[-1] is np.nan: @@ -212,12 +215,9 @@ def get_csv_stats(df, recorded_cols=None): def stats_to_s3(uri, df, algo_namespace, recorded_cols=None): - import boto3 - s3 = boto3.resource('s3') - bytes_to_write = get_csv_stats(df, recorded_cols=recorded_cols) - timestr = time.strftime('%Y%m%d-%H%M%S') + timestr = time.strftime('%Y%m%d') parts = uri.split('//') obj = s3.Object(parts[1], 'stats/{}-{}.csv'.format( diff --git a/etc/requirements.txt b/etc/requirements.txt index be375309..1b44dd86 100644 --- a/etc/requirements.txt +++ b/etc/requirements.txt @@ -82,4 +82,4 @@ tables==3.3.0 #Catalyst dependencies ccxt==1.10.283 - +boto3=1.4.8 \ No newline at end of file