mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-16 04:41:15 +00:00
refactor: fetch_orders pagination to base class
This commit is contained in:
@@ -35,6 +35,7 @@ class Bybit(Exchange):
|
|||||||
"order_time_in_force": ["GTC", "FOK", "IOC", "PO"],
|
"order_time_in_force": ["GTC", "FOK", "IOC", "PO"],
|
||||||
"ws_enabled": True,
|
"ws_enabled": True,
|
||||||
"trades_has_history": False, # Endpoint doesn't support pagination
|
"trades_has_history": False, # Endpoint doesn't support pagination
|
||||||
|
"fetch_orders_limit_minutes": 7 * 1440, # 7 days
|
||||||
"exchange_has_overrides": {
|
"exchange_has_overrides": {
|
||||||
# Bybit spot does not support fetch_order
|
# Bybit spot does not support fetch_order
|
||||||
# Unless the account is unified.
|
# Unless the account is unified.
|
||||||
@@ -234,25 +235,6 @@ class Bybit(Exchange):
|
|||||||
logger.warning(f"Could not update funding fees for {pair}.")
|
logger.warning(f"Could not update funding fees for {pair}.")
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
def fetch_orders(
|
|
||||||
self, pair: str, since: datetime, params: dict | None = None
|
|
||||||
) -> list[CcxtOrder]:
|
|
||||||
"""
|
|
||||||
Fetch all orders for a pair "since"
|
|
||||||
:param pair: Pair for the query
|
|
||||||
:param since: Starting time for the query
|
|
||||||
"""
|
|
||||||
# On bybit, the distance between since and "until" can't exceed 7 days.
|
|
||||||
# we therefore need to split the query into multiple queries.
|
|
||||||
orders = []
|
|
||||||
|
|
||||||
while since < dt_now():
|
|
||||||
until = since + timedelta(days=7, minutes=-1)
|
|
||||||
orders += super().fetch_orders(pair, since, params={"until": dt_ts(until)})
|
|
||||||
since = until
|
|
||||||
|
|
||||||
return orders
|
|
||||||
|
|
||||||
def fetch_order(self, order_id: str, pair: str, params: dict | None = None) -> CcxtOrder:
|
def fetch_order(self, order_id: str, pair: str, params: dict | None = None) -> CcxtOrder:
|
||||||
if self.exchange_has("fetchOrder"):
|
if self.exchange_has("fetchOrder"):
|
||||||
# Set acknowledged to True to avoid ccxt exception
|
# Set acknowledged to True to avoid ccxt exception
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ class Exchange:
|
|||||||
"ccxt_futures_name": "swap",
|
"ccxt_futures_name": "swap",
|
||||||
"needs_trading_fees": False, # use fetch_trading_fees to cache fees
|
"needs_trading_fees": False, # use fetch_trading_fees to cache fees
|
||||||
"order_props_in_contracts": ["amount", "filled", "remaining"],
|
"order_props_in_contracts": ["amount", "filled", "remaining"],
|
||||||
|
"fetch_orders_limit_minutes": None, # "fetch_orders" is not time-limited by default
|
||||||
# Override createMarketBuyOrderRequiresPrice where ccxt has it wrong
|
# Override createMarketBuyOrderRequiresPrice where ccxt has it wrong
|
||||||
"marketOrderRequiresPrice": False,
|
"marketOrderRequiresPrice": False,
|
||||||
"exchange_has_overrides": {}, # Dictionary overriding ccxt's "has".
|
"exchange_has_overrides": {}, # Dictionary overriding ccxt's "has".
|
||||||
@@ -1742,7 +1743,7 @@ class Exchange:
|
|||||||
return orders
|
return orders
|
||||||
|
|
||||||
@retrier(retries=0)
|
@retrier(retries=0)
|
||||||
def fetch_orders(
|
def _fetch_orders(
|
||||||
self, pair: str, since: datetime, params: dict | None = None
|
self, pair: str, since: datetime, params: dict | None = None
|
||||||
) -> list[CcxtOrder]:
|
) -> list[CcxtOrder]:
|
||||||
"""
|
"""
|
||||||
@@ -1781,6 +1782,22 @@ class Exchange:
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
|
def fetch_orders(
|
||||||
|
self, pair: str, since: datetime, params: dict | None = None
|
||||||
|
) -> list[CcxtOrder]:
|
||||||
|
if self._config["dry_run"]:
|
||||||
|
return []
|
||||||
|
if (limit := self._ft_has.get("fetch_orders_limit_minutes")) is not None:
|
||||||
|
orders = []
|
||||||
|
while since < dt_now():
|
||||||
|
until = since + timedelta(minutes=limit - 1)
|
||||||
|
orders += self._fetch_orders(pair, since, params={"until": dt_ts(until)})
|
||||||
|
since = until
|
||||||
|
return orders
|
||||||
|
|
||||||
|
else:
|
||||||
|
return self._fetch_orders(pair, since, params=params)
|
||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def fetch_trading_fees(self) -> dict[str, Any]:
|
def fetch_trading_fees(self) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ class FtHas(TypedDict, total=False):
|
|||||||
l2_limit_range: list[int] | None
|
l2_limit_range: list[int] | None
|
||||||
l2_limit_range_required: bool
|
l2_limit_range_required: bool
|
||||||
l2_limit_upper: int | None
|
l2_limit_upper: int | None
|
||||||
|
# fetch_orders
|
||||||
|
fetch_orders_limit_minutes: int | None
|
||||||
# Futures
|
# Futures
|
||||||
ccxt_futures_name: str # usually swap
|
ccxt_futures_name: str # usually swap
|
||||||
mark_ohlcv_price: str
|
mark_ohlcv_price: str
|
||||||
|
|||||||
Reference in New Issue
Block a user