From 18bfaff7c9a1106c7f5c63d04613a997e7723299 Mon Sep 17 00:00:00 2001 From: fredfortier Date: Mon, 18 Sep 2017 15:37:10 -0400 Subject: [PATCH] Trying to stabilize refactoring an last few commits (still unstable) --- catalyst/exchange/data_portal_exchange.py | 10 +++++----- catalyst/exchange/exchange_algorithm.py | 5 ++--- catalyst/utils/run_algo.py | 2 +- tests/exchange/__init__.py | 0 tests/exchange/test_data_portal.py | 22 ++++++++++++---------- 5 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 tests/exchange/__init__.py diff --git a/catalyst/exchange/data_portal_exchange.py b/catalyst/exchange/data_portal_exchange.py index 10df5389..3df15e98 100644 --- a/catalyst/exchange/data_portal_exchange.py +++ b/catalyst/exchange/data_portal_exchange.py @@ -27,15 +27,15 @@ log = Logger('DataPortalExchange') class DataPortalExchangeBase(DataPortal): - def __init__(self, exchanges, *args, **kwargs): - self.exchanges = exchanges + def __init__(self, *args, **kwargs): + self.exchanges = kwargs.pop('exchanges', None) # TODO: put somewhere accessible by each algo self.retry_get_history_window = 5 self.retry_get_spot_value = 5 self.retry_delay = 5 - super(self.__class__, self).__init__(*args, **kwargs) + super(DataPortalExchangeBase, self).__init__(*args, **kwargs) def _get_history_window(self, assets, @@ -199,8 +199,8 @@ class DataPortalExchangeBase(DataPortal): class DataPortalExchangeLive(DataPortalExchangeBase): - def __init__(self, exchanges, *args, **kwargs): - super(self.__class__, self).__init__(exchanges, *args, **kwargs) + def __init__(self, *args, **kwargs): + super(DataPortalExchangeLive, self).__init__(*args, **kwargs) def get_exchange_spot_value_history_window(self, exchange, diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index c09c17f2..030a3341 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -59,8 +59,7 @@ class ExchangeAlgorithmExecutor(AlgorithmSimulator): class ExchangeTradingAlgorithmBase(TradingAlgorithm): def __init__(self, *args, **kwargs): - self.exchanges = kwargs.pop('exchanges', None) - super(self.__class__, self).__init__(*args, **kwargs) + super(ExchangeTradingAlgorithmBase, self).__init__(*args, **kwargs) @api_method @preprocess(symbol_str=ensure_upper_case) @@ -135,7 +134,7 @@ class ExchangeTradingAlgorithm(ExchangeTradingAlgorithmBase): self.stats_minutes = 5 - super(self.__class__, self).__init__(*args, **kwargs) + super(ExchangeTradingAlgorithm, self).__init__(*args, **kwargs) # TODO: fix precision before re-enabling # self._create_minute_writer() diff --git a/catalyst/utils/run_algo.py b/catalyst/utils/run_algo.py index 89e3e9e4..6877bc54 100644 --- a/catalyst/utils/run_algo.py +++ b/catalyst/utils/run_algo.py @@ -37,7 +37,7 @@ from catalyst.utils.calendars import get_calendar from catalyst.utils.factory import create_simulation_parameters import catalyst.utils.paths as pth -from catalyst.exchange.algorithm_exchange import ExchangeTradingAlgorithm +from catalyst.exchange.exchange_algorithm import ExchangeTradingAlgorithm from catalyst.exchange.data_portal_exchange import DataPortalExchangeLive from catalyst.exchange.bitfinex.bitfinex import Bitfinex from catalyst.exchange.asset_finder_exchange import AssetFinderExchange diff --git a/tests/exchange/__init__.py b/tests/exchange/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/exchange/test_data_portal.py b/tests/exchange/test_data_portal.py index 21890a44..d98b2ac7 100644 --- a/tests/exchange/test_data_portal.py +++ b/tests/exchange/test_data_portal.py @@ -1,5 +1,5 @@ import pandas as pd -from catalyst import get_calendar +# from catalyst import get_calendar from logbook import Logger from catalyst.exchange.asset_finder_exchange import AssetFinderExchange @@ -17,7 +17,7 @@ class ExchangeDataPortalTestCase: def setup(self): log.info('creating bitfinex exchange') auth_bitfinex = get_exchange_auth('bitfinex') - bitfinex = Bitfinex( + self.bitfinex = Bitfinex( key=auth_bitfinex['key'], secret=auth_bitfinex['secret'], base_currency='usd' @@ -25,31 +25,33 @@ class ExchangeDataPortalTestCase: log.info('creating bittrex exchange') auth_bitfinex = get_exchange_auth('bittrex') - bittrex = Bittrex( + self.bittrex = Bittrex( key=auth_bitfinex['key'], secret=auth_bitfinex['secret'], base_currency='usd' ) - open_calendar = get_calendar('OPEN') + # open_calendar = get_calendar('OPEN') + open_calendar = None asset_finder = AssetFinderExchange() self.data_portal_live = DataPortalExchangeLive( - exchanges=dict(bitfinex=bitfinex, bittrex=bittrex), + exchanges=dict(bitfinex=self.bitfinex, bittrex=self.bittrex), asset_finder=asset_finder, trading_calendar=open_calendar, first_trading_day=pd.to_datetime('today', utc=True) ) - def test_history_window_live(self): + def test_get_history_window_live(self): pass - def test_spot_value_live(self): + def test_get_spot_value_live(self): asset_finder = self.data_portal_live.asset_finder - now = pd.Timestamp.utcnow() assets = [ - asset_finder.lookup_symbol('eth_usd',now,) + asset_finder.lookup_symbol('eth_usd', self.bitfinex), + asset_finder.lookup_symbol('eth_usd', self.bittrex) ] + now = pd.Timestamp.utcnow() value = self.data_portal_live.get_spot_value( - assets, field, dt, data_frequency) + assets, 'price', now, '1m') pass