diff --git a/catalyst/data/loader.py b/catalyst/data/loader.py index 19627f25..53409d23 100644 --- a/catalyst/data/loader.py +++ b/catalyst/data/loader.py @@ -107,8 +107,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..a1fd326c 100644 --- a/catalyst/examples/buy_low_sell_high_live.py +++ b/catalyst/examples/buy_low_sell_high_live.py @@ -18,10 +18,10 @@ log = Logger('buy low sell high') def initialize(context): log.info('initializing algo') - context.ASSET_NAME = 'etc_btc' + context.ASSET_NAME = 'btc_usdt' context.asset = symbol(context.ASSET_NAME) - context.TARGET_POSITIONS = 3 + context.TARGET_POSITIONS = 30 context.PROFIT_TARGET = 0.1 context.SLIPPAGE_ALLOWED = 0.02 @@ -41,7 +41,7 @@ def _handle_data(context, data): context.asset, fields='price', bar_count=20, - frequency='15m' + frequency='1d' ) rsi = talib.RSI(prices.values, timeperiod=14)[-1] log.info('got rsi: {}'.format(rsi)) @@ -54,7 +54,7 @@ def _handle_data(context, data): elif rsi <= 70: buy_increment = 0.2 else: - buy_increment = None + buy_increment = 0.1 cash = context.portfolio.cash log.info('base currency available: {cash}'.format(cash=cash)) @@ -147,14 +147,14 @@ def analyze(context, stats): run_algorithm( - capital_base=1, + capital_base=100000, initialize=initialize, handle_data=handle_data, analyze=analyze, - exchange_name='bitfinex', + exchange_name='poloniex', start=pd.to_datetime('2017-5-01', utc=True), - end=pd.to_datetime('2017-10-01', utc=True), - base_currency='btc', + end=pd.to_datetime('2017-10-16', utc=True), + base_currency='usdt', data_frequency='daily' ) # run_algorithm( diff --git a/catalyst/exchange/bitfinex/bitfinex.py b/catalyst/exchange/bitfinex/bitfinex.py index baf7d650..a5ebebbb 100644 --- a/catalyst/exchange/bitfinex/bitfinex.py +++ b/catalyst/exchange/bitfinex/bitfinex.py @@ -58,7 +58,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) @@ -667,10 +667,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 fdcce9ca..9b331b1a 100644 --- a/catalyst/exchange/bittrex/bittrex.py +++ b/catalyst/exchange/bittrex/bittrex.py @@ -360,7 +360,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': @@ -371,7 +371,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/exchange.py b/catalyst/exchange/exchange.py index 6e0871ab..e617fb17 100644 --- a/catalyst/exchange/exchange.py +++ b/catalyst/exchange/exchange.py @@ -474,7 +474,7 @@ class Exchange: # Adding bars too recent to be contained in the consolidated # exchanges bundles. We go directly against the exchange # to retrieve the candles. - + start_dt = get_start_dt(end_dt, adj_bar_count, data_frequency) trailing_dt = \ series[asset].index[-1] + get_delta(1, data_frequency) \ if asset in series else start_dt diff --git a/catalyst/exchange/exchange_bundle.py b/catalyst/exchange/exchange_bundle.py index 18b1f848..4cfa4016 100644 --- a/catalyst/exchange/exchange_bundle.py +++ b/catalyst/exchange/exchange_bundle.py @@ -596,7 +596,7 @@ class ExchangeBundle: for asset_index, asset in enumerate(assets): asset_values = arrays[asset_index] - value_series = pd.Series(asset_values[0], index=periods) + value_series = pd.Series(asset_values.flatten(), index=periods) series[asset] = value_series return series diff --git a/catalyst/exchange/poloniex/poloniex.py b/catalyst/exchange/poloniex/poloniex.py index baddc2de..60e5b4b5 100644 --- a/catalyst/exchange/poloniex/poloniex.py +++ b/catalyst/exchange/poloniex/poloniex.py @@ -51,7 +51,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 2745fc00..da2c3ef8 100644 --- a/catalyst/utils/run_algo.py +++ b/catalyst/utils/run_algo.py @@ -270,7 +270,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..c4575fe8 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-10-14', 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'