diff --git a/catalyst/api.pyi b/catalyst/api.pyi index 5b131c59a..c8e305359 100644 --- a/catalyst/api.pyi +++ b/catalyst/api.pyi @@ -63,6 +63,7 @@ def cancel_order(order_param, symbol=None, params={}): Extra parameters to pass to the exchange """ + def get_orderbook(asset, order_type='all', limit=None): """Get the order book of asset.exchange. @@ -76,6 +77,7 @@ def get_orderbook(asset, order_type='all', limit=None): limit : int, optional """ + def get_open_orders(asset=None): """Retrieve all of the current open orders. @@ -244,7 +246,8 @@ def get_environment(field='platform'): """ -def get_order(order_id, asset_or_symbol=None, return_price=False): +def get_order(order_id, asset_or_symbol=None, + return_price=False, params={}): """Lookup an order based on the order id returned from one of the order functions. @@ -254,8 +257,10 @@ def get_order(order_id, asset_or_symbol=None, return_price=False): The unique identifier for the order. asset_or_symbol: Asset or str The asset or the tradingPair symbol of the order. - return_price: bool - get the trading price in addition to the order + return_price: bool + get the trading price in addition to the order + params: dict, optional + Extra parameters to pass to the exchange Returns ------- diff --git a/catalyst/exchange/ccxt/ccxt_exchange.py b/catalyst/exchange/ccxt/ccxt_exchange.py index e28a3b668..11aad4789 100644 --- a/catalyst/exchange/ccxt/ccxt_exchange.py +++ b/catalyst/exchange/ccxt/ccxt_exchange.py @@ -44,6 +44,7 @@ huobipro=ccxt.huobipro, okex=ccxt.okex, hitbtc=ccxt.hitbtc2, + kucoin=ccxt.kucoin, ) @@ -1150,7 +1151,8 @@ def process_order(self, order): order.broker_order_id = ', '.join([t['id'] for t in trades]) return transactions - def get_order(self, order_id, asset_or_symbol=None, return_price=False): + def get_order(self, order_id, asset_or_symbol=None, + return_price=False, params={}): """Lookup an order based on the order id returned from one of the order functions. @@ -1162,6 +1164,8 @@ def get_order(self, order_id, asset_or_symbol=None, return_price=False): The asset or the tradingPair symbol of the order. return_price: bool get the trading price in addition to the order + params: dict, optional + Extra parameters to pass to the exchange Returns ------- @@ -1178,7 +1182,9 @@ def get_order(self, order_id, asset_or_symbol=None, return_price=False): try: symbol = self.get_symbol(asset_or_symbol) \ if asset_or_symbol is not None else None - order_status = self.api.fetch_order(id=order_id, symbol=symbol) + order_status = self.api.fetch_order(id=order_id, + symbol=symbol, + params=params) order, executed_price = self._create_order(order_status) if return_price: @@ -1311,10 +1317,11 @@ def get_orderbook(self, asset, order_type='all', limit=None): order_types = ['bids', 'asks'] if order_type == 'all' else [order_type] result = dict(last_traded=from_ms_timestamp(order_book['timestamp'])) for index, order_type in enumerate(order_types): - if limit is not None and index > limit - 1: - break - result[order_type] = [] + + if limit is not None and len(order_book[order_type]) > limit: + order_book[order_type] = order_book[order_type][:limit] + for entry in order_book[order_type]: result[order_type].append(dict( rate=float(entry[0]), diff --git a/catalyst/exchange/exchange.py b/catalyst/exchange/exchange.py index 687c9178e..8191b8fa4 100644 --- a/catalyst/exchange/exchange.py +++ b/catalyst/exchange/exchange.py @@ -915,7 +915,8 @@ def get_open_orders(self, asset): pass @abstractmethod - def get_order(self, order_id, symbol_or_asset=None): + def get_order(self, order_id, symbol_or_asset=None, + return_price=False, params={}): """Lookup an order based on the order id returned from one of the order functions. @@ -925,6 +926,10 @@ def get_order(self, order_id, symbol_or_asset=None): The unique identifier for the order. symbol_or_asset: str|TradingPair The catalyst symbol, some exchanges need this + return_price: bool + get the trading price in addition to the order + params: dict, optional + Extra parameters to pass to the exchange Returns ------- diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index 5393beb80..b99852b36 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -1086,7 +1086,8 @@ def get_open_orders(self, asset=None): ) @api_method - def get_order(self, order_id, asset_or_symbol=None, return_price=False): + def get_order(self, order_id, asset_or_symbol=None, + return_price=False, params={}): """Lookup an order based on the order id returned from one of the order functions. @@ -1098,6 +1099,8 @@ def get_order(self, order_id, asset_or_symbol=None, return_price=False): The asset or the tradingPair symbol of the order. return_price: bool get the trading price in addition to the order + params: dict, optional + Extra parameters to pass to the exchange Returns ------- @@ -1114,7 +1117,7 @@ def get_order(self, order_id, asset_or_symbol=None, return_price=False): sleeptime=self.attempts['retry_sleeptime'], retry_exceptions=(ExchangeRequestError,), cleanup=lambda: log.warn('Fetching orders again.'), - args=(order_id, asset_or_symbol, return_price) + args=(order_id, asset_or_symbol, return_price, params) ) @api_method diff --git a/docs/source/live-trading.rst b/docs/source/live-trading.rst index ad882c79e..133be76bf 100644 --- a/docs/source/live-trading.rst +++ b/docs/source/live-trading.rst @@ -23,6 +23,7 @@ Additionally, we have successfully tested in live mode the following exchanges: - Huobi Pro, id = ``huobipro`` - OKEX, id = ``okex`` - HitBTC, id = ``hitbtc`` +- KuCoin, id = ``kucoin`` As Catalyst is currently in Alpha and is under active development, you are encouraged to thoroughly test any exchange in *paper trading* mode before trading