diff --git a/catalyst/examples/buy_low_sell_high_live.py b/catalyst/examples/buy_low_sell_high_live.py index 702471a3..b722a890 100644 --- a/catalyst/examples/buy_low_sell_high_live.py +++ b/catalyst/examples/buy_low_sell_high_live.py @@ -33,7 +33,7 @@ def initialize(context): context.TARGET_POSITIONS = 5000 context.PROFIT_TARGET = 0.1 - context.SLIPPAGE_ALLOWED = 0.02 + context.SLIPPAGE_ALLOWED = 0.05 context.retry_check_open_orders = 10 context.retry_update_portfolio = 10 diff --git a/catalyst/exchange/algorithm_exchange.py b/catalyst/exchange/algorithm_exchange.py index c9515b5c..9b797278 100644 --- a/catalyst/exchange/algorithm_exchange.py +++ b/catalyst/exchange/algorithm_exchange.py @@ -69,7 +69,7 @@ class ExchangeTradingAlgorithm(TradingAlgorithm): self.stats_minutes = 5 super(self.__class__, self).__init__(*args, **kwargs) - self._create_minute_writer() + # self._create_minute_writer() signal.signal(signal.SIGINT, self.signal_handler) diff --git a/catalyst/exchange/bittrex/bittrex.py b/catalyst/exchange/bittrex/bittrex.py index c9093b16..2ac974d4 100644 --- a/catalyst/exchange/bittrex/bittrex.py +++ b/catalyst/exchange/bittrex/bittrex.py @@ -25,6 +25,9 @@ class Bittrex(Exchange): self.base_currency = base_currency self._portfolio = portfolio + self.minute_writer=None + self.minute_reader=None + self.assets = dict() self.load_assets() @@ -85,8 +88,9 @@ class Bittrex(Exchange): return std_balances def create_order(self, asset, amount, is_buy, style): - log.info('creating order') + log.info('creating {} order'.format('buy' if is_buy else 'sell')) exchange_symbol = self.get_symbol(asset) + if isinstance(style, LimitOrder) or isinstance(style, StopLimitOrder): if isinstance(style, StopLimitOrder): log.warn('{} will ignore the stop price'.format(self.name)) @@ -94,9 +98,11 @@ class Bittrex(Exchange): price = style.get_limit_price(is_buy) try: if is_buy: - order_status = self.api.buylimit(exchange_symbol, amount, price) + order_status = self.api.buylimit(exchange_symbol, amount, + price) else: - order_status = self.api.selllimit(exchange_symbol, amount, price) + order_status = self.api.selllimit(exchange_symbol, + abs(amount), price) except Exception as e: raise ExchangeRequestError(error=e) @@ -161,7 +167,7 @@ class Bittrex(Exchange): return order, executed_price def get_order(self, order_id): - log.info('retrieving order') + log.info('retrieving order {}'.format(order_id)) try: order_status = self.api.getorder(order_id) except Exception as e: @@ -170,8 +176,7 @@ class Bittrex(Exchange): if order_status is None: raise OrderNotFound(order_id=order_id, exchange=self.name) - order, executed_price = self._create_order(order_status) - return order + return self._create_order(order_status) def cancel_order(self, order_param): order_id = order_param.id \ @@ -255,7 +260,7 @@ class Bittrex(Exchange): ordered_candles = list(reversed(candles)) if bar_count is None: - ohlc_map[asset] = ohlc_from_candle(ordered_candles[-1]) + ohlc_map[asset] = ohlc_from_candle(ordered_candles[0]) else: ohlc_bars = [] for candle in ordered_candles[:bar_count]: diff --git a/tests/exchange/test_bitfinex.py b/tests/exchange/test_bitfinex.py index 0315ef6b..6b9990c3 100644 --- a/tests/exchange/test_bitfinex.py +++ b/tests/exchange/test_bitfinex.py @@ -26,11 +26,11 @@ class BitfinexTestCase(BaseExchangeTestCase): log.info('creating order') asset = self.exchange.get_asset('eth_usd') order_id = self.exchange.order( - asset=asset, - style=LimitOrder(limit_price=200), - limit_price=200, - amount=0.5, - stop_price=None + asset=asset, + style=LimitOrder(limit_price=200), + limit_price=200, + amount=0.5, + stop_price=None ) log.info('order created {}'.format(order_id)) pass @@ -68,78 +68,3 @@ class BitfinexTestCase(BaseExchangeTestCase): log.info('testing exchange balances') balances = self.exchange.get_balances() pass - - # def test_order(self): - # log.info('ordering from bitfinex') - # bitfinex = Bitfinex() - # order_id = bitfinex.order( - # asset=bitfinex.get_asset('eth_usd'), - # style=LimitOrder(limit_price=200), - # limit_price=200, - # amount=0.5, - # stop_price=None - # ) - # log.info('order created {}'.format(order_id)) - # pass - # - # def test_portfolio(self): - # log.info('fetching portfolio data') - # pass - # - # def test_account(self): - # log.info('fetching account data') - # pass - # - # def test_time_skew(self): - # log.info('time skew not implemented') - # pass - # - # def test_get_open_orders(self): - # log.info('fetching open orders') - # bitfinex = Bitfinex() - # order_id = bitfinex.get_open_orders() - # log.info('open orders: {}'.format(order_id)) - # pass - # - # def test_get_order(self): - # log.info('querying orders from bitfinex') - # bitfinex = Bitfinex() - # response = bitfinex.get_order(order_id=3361248395) - # log.info('the order: {}'.format(response)) - # pass - # - # def test_cancel_order(self): - # log.info('canceling order from bitfinex') - # bitfinex = Bitfinex() - # response = bitfinex.cancel_order(order_id=3330847408) - # log.info('canceled order: {}'.format(response)) - # pass - # - # def test_get_spot_value(self): - # log.info('spot value not implemented') - # bitfinex = Bitfinex() - # assets = [ - # bitfinex.get_asset('eth_usd'), - # bitfinex.get_asset('etc_usd'), - # bitfinex.get_asset('eos_usd'), - # ] - # # assets = bitfinex.get_asset('eth_usd') - # value = bitfinex.get_spot_value( - # assets=assets, - # field='close', - # data_frequency='minute' - # ) - # pass - # - # def test_tickers(self): - # log.info('fetching ticker from bitfinex') - # bitfinex = Bitfinex() - # current_date = pd.Timestamp.utcnow() - # assets = [ - # bitfinex.get_asset('eth_usd'), - # bitfinex.get_asset('etc_usd'), - # bitfinex.get_asset('eos_usd'), - # ] - # tickers = bitfinex.tickers(date=current_date, assets=assets) - # log.info('got tickers {}'.format(tickers)) - # pass