BLD: more live trading testing and added s3 stats output

This commit is contained in:
fredfortier
2017-12-07 00:20:27 -05:00
parent 9688d71e23
commit 5b78f161a4
5 changed files with 39 additions and 23 deletions
+1 -1
View File
@@ -279,5 +279,5 @@ if __name__ == '__main__':
base_currency='eth',
live_graph=False,
simulate_orders=False,
stats_output='s3://something'
stats_output=None
)
+16 -15
View File
@@ -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(
+17 -2
View File
@@ -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,
+4 -4
View File
@@ -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(
+1 -1
View File
@@ -82,4 +82,4 @@ tables==3.3.0
#Catalyst dependencies
ccxt==1.10.283
boto3=1.4.8