initial order book commit

This commit is contained in:
Nullart
2018-07-10 17:38:59 +08:00
parent f6d1cead53
commit 3843e4295e
2 changed files with 49 additions and 0 deletions

View File

@@ -237,6 +237,29 @@ class Exchange(object):
except ccxt.BaseError as e:
raise OperationalException(e)
@retrier
def get_order_book(self, pair: str, limit: Optional[int] = 100) -> dict:
try:
# 20180619: bittrex doesnt support limits -.-
# 20180619: binance support limits but only on specific range
if self.name == 'Binance':
limit_range = [5, 10, 20, 50, 100, 500, 1000]
for limitx in limit_range:
if limit < limitx:
limit = limitx
break
return self._api.fetch_l2_order_book(pair, limit)
except ccxt.NotSupported as e:
raise OperationalException(
f'Exchange {self.name} does not support fetching order book.'
f'Message: {e}')
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
raise TemporaryError(
f'Could not load order book due to {e.__class__.__name__}. Message: {e}')
except ccxt.BaseError as e:
raise OperationalException(e)
@retrier
def get_tickers(self) -> Dict:
try: