From 713d48780853f881ebeec37da9a6d1a901696825 Mon Sep 17 00:00:00 2001 From: Frederic Fortier Date: Wed, 10 Jan 2018 23:25:27 -0500 Subject: [PATCH] BUG: troubleshooting and minor fixes --- catalyst/examples/mean_reversion_simple.py | 4 +- catalyst/exchange/utils/exchange_utils.py | 5 ++- catalyst/support/issue_111.py | 44 ++++++++++++++++++++++ catalyst/support/issue_112.py | 44 ++++++++++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 catalyst/support/issue_111.py create mode 100644 catalyst/support/issue_112.py diff --git a/catalyst/examples/mean_reversion_simple.py b/catalyst/examples/mean_reversion_simple.py index 4178e0f8..b441565f 100644 --- a/catalyst/examples/mean_reversion_simple.py +++ b/catalyst/examples/mean_reversion_simple.py @@ -244,7 +244,7 @@ def analyze(context=None, perf=None): if __name__ == '__main__': # The execution mode: backtest or live - live = False + live = True if live: run_algorithm( @@ -257,7 +257,7 @@ if __name__ == '__main__': algo_namespace=NAMESPACE, base_currency='btc', live_graph=False, - simulate_orders=False, + simulate_orders=True, stats_output=None, ) diff --git a/catalyst/exchange/utils/exchange_utils.py b/catalyst/exchange/utils/exchange_utils.py index f6669c4b..081da592 100644 --- a/catalyst/exchange/utils/exchange_utils.py +++ b/catalyst/exchange/utils/exchange_utils.py @@ -129,7 +129,10 @@ def get_exchange_symbols(exchange_name, is_local=False, environ=None): if not is_local and (not os.path.isfile(filename) or pd.Timedelta( pd.Timestamp('now', tz='UTC') - last_modified_time( filename)).days > 1): - download_exchange_symbols(exchange_name, environ) + try: + download_exchange_symbols(exchange_name, environ) + except Exception as e: + pass if os.path.isfile(filename): with open(filename) as data_file: diff --git a/catalyst/support/issue_111.py b/catalyst/support/issue_111.py new file mode 100644 index 00000000..d5efdc3a --- /dev/null +++ b/catalyst/support/issue_111.py @@ -0,0 +1,44 @@ +from logbook import Logger + +from catalyst import run_algorithm +from catalyst.api import order_target_percent + +NAMESPACE = 'goose7' +log = Logger(NAMESPACE) + +from catalyst.api import record, symbol + + +def initialize(context): + context.asset = symbol('trx_btc') + + +def handle_data(context, data): + price = data.current(context.asset, 'price') + record(btc=price) + + # Only ordering if it does not have any position to avoid trying some + # tiny orders with the leftover btc + pos_amount = context.portfolio.positions[context.asset].amount + if pos_amount > 0: + return + + # Adding a limit price to workaround an issue with performance + # calculations of market orders + order_target_percent( + context.asset, 1, limit_price=price * 1.01 + ) + + +if __name__ == '__main__': + run_algorithm( + capital_base=0.003, + initialize=initialize, + handle_data=handle_data, + exchange_name='binance', + live=True, + algo_namespace=NAMESPACE, + base_currency='btc', + live_graph=False, + simulate_orders=False, + ) diff --git a/catalyst/support/issue_112.py b/catalyst/support/issue_112.py new file mode 100644 index 00000000..746a6a74 --- /dev/null +++ b/catalyst/support/issue_112.py @@ -0,0 +1,44 @@ +import pandas as pd + +from catalyst import run_algorithm +from catalyst.api import symbol + + +def initialize(context): + context.asset = symbol('btc_usdt') + + +def handle_data(context, data): + df = data.history(context.asset, + 'close', + bar_count=10, + frequency='5T', + ) + + +if __name__ == '__main__': + LIVE = True + if LIVE: + run_algorithm( + capital_base=1, + initialize=initialize, + handle_data=handle_data, + exchange_name='poloniex', + algo_namespace='test_algo', + base_currency='usdt', + live=True, + simulate_orders=True, + ) + else: + run_algorithm( + capital_base=1, + data_frequency='minute', + initialize=initialize, + handle_data=handle_data, + exchange_name='poloniex', + algo_namespace='test_algo', + base_currency='usdt', + live=False, + start=pd.to_datetime('2017-12-1', utc=True), + end=pd.to_datetime('2017-12-1', utc=True), + )