Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:enigmampc/catalyst into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lenak25 committed Aug 30, 2018
2 parents b6ad6aa + 441caa6 commit c5a87d6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
11 changes: 8 additions & 3 deletions catalyst/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
-------
Expand Down
17 changes: 12 additions & 5 deletions catalyst/exchange/ccxt/ccxt_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
huobipro=ccxt.huobipro,
okex=ccxt.okex,
hitbtc=ccxt.hitbtc2,
kucoin=ccxt.kucoin,
)


Expand Down Expand Up @@ -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.
Expand All @@ -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
-------
Expand All @@ -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:
Expand Down Expand Up @@ -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]),
Expand Down
7 changes: 6 additions & 1 deletion catalyst/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
-------
Expand Down
7 changes: 5 additions & 2 deletions catalyst/exchange/exchange_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
-------
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/source/live-trading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5a87d6

Please sign in to comment.