From f72074876dfa410d08b2f6f7725c1601a946088c Mon Sep 17 00:00:00 2001 From: fredfortier Date: Fri, 20 Oct 2017 13:17:02 -0400 Subject: [PATCH] Misc small fixes --- catalyst/data/loader.py | 4 ++-- catalyst/examples/buy_low_sell_high_live.py | 2 +- catalyst/exchange/bitfinex/bitfinex.py | 5 +++-- catalyst/exchange/bittrex/bittrex.py | 8 ++++++-- catalyst/exchange/poloniex/poloniex.py | 2 +- catalyst/sources/benchmark_source.py | 8 +++++++- catalyst/utils/run_algo.py | 2 +- tests/exchange/test_bundle.py | 19 +++++++++++++++++++ 8 files changed, 40 insertions(+), 10 deletions(-) diff --git a/catalyst/data/loader.py b/catalyst/data/loader.py index ce293e9b..7a539bfb 100644 --- a/catalyst/data/loader.py +++ b/catalyst/data/loader.py @@ -105,8 +105,8 @@ def load_crypto_market_data(trading_day=None, trading_days=None, # if trading_days is None: # trading_days = get_calendar('OPEN').schedule - if start_dt is None: - start_dt = get_calendar('OPEN').first_trading_session + # if start_dt is None: + start_dt = get_calendar('OPEN').first_trading_session if end_dt is None: end_dt = pd.Timestamp.utcnow() diff --git a/catalyst/examples/buy_low_sell_high_live.py b/catalyst/examples/buy_low_sell_high_live.py index 6742896f..bfd44a2f 100644 --- a/catalyst/examples/buy_low_sell_high_live.py +++ b/catalyst/examples/buy_low_sell_high_live.py @@ -21,7 +21,7 @@ def initialize(context): context.ASSET_NAME = 'etc_btc' context.asset = symbol(context.ASSET_NAME) - context.TARGET_POSITIONS = 3 + context.TARGET_POSITIONS = 30 context.PROFIT_TARGET = 0.1 context.SLIPPAGE_ALLOWED = 0.02 diff --git a/catalyst/exchange/bitfinex/bitfinex.py b/catalyst/exchange/bitfinex/bitfinex.py index 1817ea2d..da141e6f 100644 --- a/catalyst/exchange/bitfinex/bitfinex.py +++ b/catalyst/exchange/bitfinex/bitfinex.py @@ -56,7 +56,7 @@ class Bitfinex(Exchange): # Max is 90 but playing it safe # https://www.bitfinex.com/posts/188 - self.max_requests_per_minute = 20 + self.max_requests_per_minute = 80 self.request_cpt = dict() self.bundle = ExchangeBundle(self) @@ -665,10 +665,11 @@ class Bitfinex(Exchange): return time.strftime('%Y-%m-%d', time.gmtime(int(response.json()[-1][0] / 1000))) - def get_orderbook(self, asset, order_type='all'): + def get_orderbook(self, asset, order_type='all', limit=100): exchange_symbol = asset.exchange_symbol try: self.ask_request() + # TODO: implement limit response = self._request( 'book/{}'.format(exchange_symbol), None) data = response.json() diff --git a/catalyst/exchange/bittrex/bittrex.py b/catalyst/exchange/bittrex/bittrex.py index dcc9b943..94df439f 100644 --- a/catalyst/exchange/bittrex/bittrex.py +++ b/catalyst/exchange/bittrex/bittrex.py @@ -358,7 +358,7 @@ class Bittrex(Exchange): json.dump(symbol_map, f, sort_keys=True, indent=2, separators=(',', ':')) - def get_orderbook(self, asset, order_type='all'): + def get_orderbook(self, asset, order_type='all', limit=100): if order_type == 'all': order_type = 'both' elif order_type == 'bid': @@ -369,7 +369,11 @@ class Bittrex(Exchange): raise ValueError('invalid type') exchange_symbol = asset.exchange_symbol - data = self.api.getorderbook(market=exchange_symbol, type=order_type) + data = self.api.getorderbook( + market=exchange_symbol, + type=order_type, + depth=100 + ) result = dict() for exchange_type in data: diff --git a/catalyst/exchange/poloniex/poloniex.py b/catalyst/exchange/poloniex/poloniex.py index e24acc75..099e64a2 100644 --- a/catalyst/exchange/poloniex/poloniex.py +++ b/catalyst/exchange/poloniex/poloniex.py @@ -49,7 +49,7 @@ class Poloniex(Exchange): self.transactions = defaultdict(list) self.num_candles_limit = 2000 - self.max_requests_per_minute = 20 + self.max_requests_per_minute = 60 self.request_cpt = dict() self.bundle = ExchangeBundle(self) diff --git a/catalyst/sources/benchmark_source.py b/catalyst/sources/benchmark_source.py index 05d5c601..a20bf15f 100644 --- a/catalyst/sources/benchmark_source.py +++ b/catalyst/sources/benchmark_source.py @@ -72,7 +72,13 @@ class BenchmarkSource(object): "benchmark_returns.") def get_value(self, dt): - return self._precalculated_series.loc[dt] + try: + series = self._precalculated_series + value = series.loc[dt] + return value + except Exception: + # TODO: workaround, find permanent fix + return 0 def get_range(self, start_dt, end_dt): return self._precalculated_series.loc[start_dt:end_dt] diff --git a/catalyst/utils/run_algo.py b/catalyst/utils/run_algo.py index 3a318748..cadf8d3d 100644 --- a/catalyst/utils/run_algo.py +++ b/catalyst/utils/run_algo.py @@ -268,7 +268,7 @@ def _run(handle_data, ) # TODO: use the constructor instead - # sim_params._arena = 'live' + sim_params._arena = 'live' algorithm_class = partial( ExchangeTradingAlgorithmLive, diff --git a/tests/exchange/test_bundle.py b/tests/exchange/test_bundle.py index 301f71bb..d7ef9ed7 100644 --- a/tests/exchange/test_bundle.py +++ b/tests/exchange/test_bundle.py @@ -17,6 +17,25 @@ log = Logger('test_exchange_bundle') class ExchangeBundleTestCase: + def test_spot_value(self): + data_frequency = 'daily' + exchange_name = 'poloniex' + + exchange = get_exchange(exchange_name) + exchange_bundle = ExchangeBundle(exchange) + assets = [ + exchange.get_asset('btc_usdt') + ] + dt = pd.to_datetime('2017-9-29 23:59', utc=True) + + values = exchange_bundle.get_spot_values( + assets=assets, + field='close', + dt=dt, + data_frequency=data_frequency + ) + pass + def test_ingest_minute(self): data_frequency = 'minute' exchange_name = 'bitfinex'