fix: add l2 upper-limit (for gate)

closes #11592
This commit is contained in:
Matthias
2025-04-02 19:41:07 +02:00
parent be2d97b559
commit 2e343b9fbd
3 changed files with 13 additions and 3 deletions

View File

@@ -148,6 +148,7 @@ class Exchange:
"trades_has_history": False, "trades_has_history": False,
"l2_limit_range": None, "l2_limit_range": None,
"l2_limit_range_required": True, # Allow Empty L2 limit (kucoin) "l2_limit_range_required": True, # Allow Empty L2 limit (kucoin)
"l2_limit_upper": None, # Upper limit for L2 limit
"mark_ohlcv_price": "mark", "mark_ohlcv_price": "mark",
"mark_ohlcv_timeframe": "8h", "mark_ohlcv_timeframe": "8h",
"funding_fee_timeframe": "8h", "funding_fee_timeframe": "8h",
@@ -1955,14 +1956,17 @@ class Exchange:
@staticmethod @staticmethod
def get_next_limit_in_list( def get_next_limit_in_list(
limit: int, limit_range: list[int] | None, range_required: bool = True limit: int,
limit_range: list[int] | None,
range_required: bool = True,
upper_limit: int | None = None,
): ):
""" """
Get next greater value in the list. Get next greater value in the list.
Used by fetch_l2_order_book if the api only supports a limited range Used by fetch_l2_order_book if the api only supports a limited range
""" """
if not limit_range: if not limit_range:
return limit return min(limit, upper_limit) if upper_limit else limit
result = min([x for x in limit_range if limit <= x] + [max(limit_range)]) result = min([x for x in limit_range if limit <= x] + [max(limit_range)])
if not range_required and limit > result: if not range_required and limit > result:
@@ -1979,7 +1983,10 @@ class Exchange:
{'asks': [price, volume], 'bids': [price, volume]} {'asks': [price, volume], 'bids': [price, volume]}
""" """
limit1 = self.get_next_limit_in_list( limit1 = self.get_next_limit_in_list(
limit, self._ft_has["l2_limit_range"], self._ft_has["l2_limit_range_required"] limit,
self._ft_has["l2_limit_range"],
self._ft_has["l2_limit_range_required"],
self._ft_has["l2_limit_upper"],
) )
try: try:
return self._api.fetch_l2_order_book(pair, limit1) return self._api.fetch_l2_order_book(pair, limit1)

View File

@@ -37,6 +37,7 @@ class FtHas(TypedDict, total=False):
# Orderbook # Orderbook
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
# Futures # Futures
ccxt_futures_name: str # usually swap ccxt_futures_name: str # usually swap
mark_ohlcv_price: str mark_ohlcv_price: str

View File

@@ -35,6 +35,7 @@ class Gate(Exchange):
"stoploss_order_types": {"limit": "limit"}, "stoploss_order_types": {"limit": "limit"},
"stop_price_param": "stopPrice", "stop_price_param": "stopPrice",
"stop_price_prop": "stopPrice", "stop_price_prop": "stopPrice",
"l2_limit_upper": 1000,
"marketOrderRequiresPrice": True, "marketOrderRequiresPrice": True,
"trades_has_history": False, # Endpoint would support this - but ccxt doesn't. "trades_has_history": False, # Endpoint would support this - but ccxt doesn't.
} }
@@ -44,6 +45,7 @@ class Gate(Exchange):
"marketOrderRequiresPrice": False, "marketOrderRequiresPrice": False,
"funding_fee_candle_limit": 90, "funding_fee_candle_limit": 90,
"stop_price_type_field": "price_type", "stop_price_type_field": "price_type",
"l2_limit_upper": 300,
"stop_price_type_value_mapping": { "stop_price_type_value_mapping": {
PriceType.LAST: 0, PriceType.LAST: 0,
PriceType.MARK: 1, PriceType.MARK: 1,