From 05c8957c90c40d997bb98c2beec8be51c553d50e Mon Sep 17 00:00:00 2001 From: Frederic Fortier Date: Fri, 12 Jan 2018 00:48:53 -0500 Subject: [PATCH] BUG: fixed issue with history of multiple assets --- catalyst/exchange/ccxt/ccxt_exchange.py | 4 +- catalyst/support/history_multiple_assets.py | 50 +++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 catalyst/support/history_multiple_assets.py diff --git a/catalyst/exchange/ccxt/ccxt_exchange.py b/catalyst/exchange/ccxt/ccxt_exchange.py index ed3b2b24..bade7221 100644 --- a/catalyst/exchange/ccxt/ccxt_exchange.py +++ b/catalyst/exchange/ccxt/ccxt_exchange.py @@ -382,9 +382,9 @@ class CCXT(Exchange): ms = int(delta.total_seconds()) * 1000 candles = dict() - for asset in assets: + for index, asset in enumerate(assets): ohlcvs = self.api.fetch_ohlcv( - symbol=symbols[0], + symbol=symbols[index], timeframe=timeframe, since=ms, limit=bar_count, diff --git a/catalyst/support/history_multiple_assets.py b/catalyst/support/history_multiple_assets.py new file mode 100644 index 00000000..804ae58f --- /dev/null +++ b/catalyst/support/history_multiple_assets.py @@ -0,0 +1,50 @@ +import pandas as pd + +from catalyst import run_algorithm +from catalyst.api import symbol + + +def initialize(context): + context.asset1 = symbol('fct_btc') + context.asset2 = symbol('btc_usdt') + context.coins = [context.asset1, context.asset2] + + +def handle_data(context, data): + df = data.history(context.coins, + 'close', + bar_count=10, + frequency='5T', + ) + print(df) + print(data.current(context.asset1, 'close')) + print(data.current(context.asset2, 'close')) + exit(0) + + +if __name__ == '__main__': + LIVE = True + if LIVE: + run_algorithm( + capital_base=1, + initialize=initialize, + handle_data=handle_data, + exchange_name='poloniex', + algo_namespace='test_multi_assets', + 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_multi_assets', + base_currency='usdt', + live=False, + start=pd.to_datetime('2017-12-1', utc=True), + end=pd.to_datetime('2017-12-1', utc=True), + )