mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Add fetch_order_emulated to support exchanges without proper fetch_order method
This commit is contained in:
parent
871fa255fc
commit
322a3a3bbd
|
@ -1281,11 +1281,43 @@ class Exchange:
|
|||
except ccxt.BaseError as e:
|
||||
raise OperationalException(e) from e
|
||||
|
||||
def fetch_order_emulated(self, order_id: str, pair: str, params: Dict) -> Dict:
|
||||
"""
|
||||
Emulated fetch_order if the exchange doesn't support fetch_order, but requires separate
|
||||
calls for open and closed orders.
|
||||
"""
|
||||
try:
|
||||
order = self._api.fetch_open_order(order_id, pair, params=params)
|
||||
self._log_exchange_response('fetch_open_order', order)
|
||||
order = self._order_contracts_to_amount(order)
|
||||
return order
|
||||
except ccxt.OrderNotFound:
|
||||
try:
|
||||
order = self._api.fetch_closed_order(order_id, pair, params=params)
|
||||
self._log_exchange_response('fetch_closed_order', order)
|
||||
order = self._order_contracts_to_amount(order)
|
||||
return order
|
||||
except ccxt.OrderNotFound as e:
|
||||
raise RetryableOrderError(
|
||||
f'Order not found (pair: {pair} id: {order_id}). Message: {e}') from e
|
||||
except ccxt.InvalidOrder as e:
|
||||
raise InvalidOrderException(
|
||||
f'Tried to get an invalid order (pair: {pair} id: {order_id}). Message: {e}') from e
|
||||
except ccxt.DDoSProtection as e:
|
||||
raise DDosProtection(e) from e
|
||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||
raise TemporaryError(
|
||||
f'Could not get order due to {e.__class__.__name__}. Message: {e}') from e
|
||||
except ccxt.BaseError as e:
|
||||
raise OperationalException(e) from e
|
||||
|
||||
@retrier(retries=API_FETCH_ORDER_RETRY_COUNT)
|
||||
def fetch_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict:
|
||||
if self._config['dry_run']:
|
||||
return self.fetch_dry_run_order(order_id)
|
||||
try:
|
||||
if not self.exchange_has('fetchOrder'):
|
||||
return self.fetch_order_emulated(order_id, pair, params)
|
||||
order = self._api.fetch_order(order_id, pair, params=params)
|
||||
self._log_exchange_response('fetch_order', order)
|
||||
order = self._order_contracts_to_amount(order)
|
||||
|
|
Loading…
Reference in New Issue
Block a user