feat: initial "features" support

This commit is contained in:
Matthias
2025-01-31 06:56:41 +01:00
parent 7a17cd781a
commit 8af8260b7c

View File

@@ -12,7 +12,7 @@ from copy import deepcopy
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from math import floor, isnan from math import floor, isnan
from threading import Lock from threading import Lock
from typing import Any, Literal, TypeGuard from typing import Any, Literal, TypeGuard, TypeVar
import ccxt import ccxt
import ccxt.pro as ccxt_pro import ccxt.pro as ccxt_pro
@@ -112,6 +112,7 @@ from freqtrade.util.periodic_cache import PeriodicCache
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
T = TypeVar("T")
class Exchange: class Exchange:
@@ -887,6 +888,24 @@ class Exchange:
return self._ft_has["exchange_has_overrides"][endpoint] return self._ft_has["exchange_has_overrides"][endpoint]
return endpoint in self._api_async.has and self._api_async.has[endpoint] return endpoint in self._api_async.has and self._api_async.has[endpoint]
def features(
self, market_type: Literal["spot", "futures"], endpoint, attribute, default: T
) -> T:
"""
Returns the exchange features for the given markettype
https://docs.ccxt.com/#/README?id=features
attributes are in a nested dict, with spot and swap.linear
e.g. spot.fetchOHLCV.limit
swap.linear.fetchOHLCV.limit
"""
feat = (
self._api_async.features.get("spot", {})
if market_type == "spot"
else self._api_async.features.get("swap", {}).get("linear", {})
)
return feat.get(endpoint, {}).get(attribute, default)
def get_precision_amount(self, pair: str) -> float | None: def get_precision_amount(self, pair: str) -> float | None:
""" """
Returns the amount precision of the exchange. Returns the amount precision of the exchange.