|
12 | 12 | from datetime import datetime, timedelta, timezone |
13 | 13 | from math import floor, isnan |
14 | 14 | from threading import Lock |
15 | | -from typing import Any, Literal, TypeGuard |
| 15 | +from typing import Any, Literal, TypeGuard, TypeVar |
16 | 16 |
|
17 | 17 | import ccxt |
18 | 18 | import ccxt.pro as ccxt_pro |
|
112 | 112 |
|
113 | 113 |
|
114 | 114 | logger = logging.getLogger(__name__) |
| 115 | +T = TypeVar("T") |
115 | 116 |
|
116 | 117 |
|
117 | 118 | class Exchange: |
@@ -887,6 +888,24 @@ def exchange_has(self, endpoint: str) -> bool: |
887 | 888 | return self._ft_has["exchange_has_overrides"][endpoint] |
888 | 889 | return endpoint in self._api_async.has and self._api_async.has[endpoint] |
889 | 890 |
|
| 891 | + def features( |
| 892 | + self, market_type: Literal["spot", "futures"], endpoint, attribute, default: T |
| 893 | + ) -> T: |
| 894 | + """ |
| 895 | + Returns the exchange features for the given markettype |
| 896 | + https://docs.ccxt.com/#/README?id=features |
| 897 | + attributes are in a nested dict, with spot and swap.linear |
| 898 | + e.g. spot.fetchOHLCV.limit |
| 899 | + swap.linear.fetchOHLCV.limit |
| 900 | + """ |
| 901 | + feat = ( |
| 902 | + self._api_async.features.get("spot", {}) |
| 903 | + if market_type == "spot" |
| 904 | + else self._api_async.features.get("swap", {}).get("linear", {}) |
| 905 | + ) |
| 906 | + |
| 907 | + return feat.get(endpoint, {}).get(attribute, default) |
| 908 | + |
890 | 909 | def get_precision_amount(self, pair: str) -> float | None: |
891 | 910 | """ |
892 | 911 | Returns the amount precision of the exchange. |
|
0 commit comments