Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
This commit is contained in:
TIANHE
2025-12-29 04:45:59 +08:00
parent d5e987b8ee
commit 278b88ec71
26 changed files with 3220 additions and 317 deletions
@@ -10,7 +10,7 @@ We convert them into exchange-specific identifiers.
from __future__ import annotations
from typing import Tuple
from typing import Dict, Tuple
def _split_base_quote(symbol: str) -> Tuple[str, str]:
@@ -53,3 +53,135 @@ def to_bitget_um_symbol(symbol: str) -> str:
return f"{base}{quote}"
_KRAKEN_BASE_MAP: Dict[str, str] = {
# Common spot naming differences
"BTC": "XBT",
}
_BITFINEX_QUOTE_MAP: Dict[str, str] = {
# Bitfinex uses "UST" for Tether USDt
"USDT": "UST",
}
_KUCOIN_FUTURES_BASE_MAP: Dict[str, str] = {
# KuCoin futures uses XBT for BTC on many contracts
"BTC": "XBT",
}
def to_bybit_symbol(symbol: str) -> str:
"""
Bybit symbol format (v5): typically concatenated, e.g. BTCUSDT.
"""
return to_binance_futures_symbol(symbol)
def to_coinbase_product_id(symbol: str) -> str:
"""
Coinbase Exchange product id format: BASE-QUOTE, e.g. BTC-USDT.
"""
base, quote = _split_base_quote(symbol)
if not base or not quote:
return symbol
return f"{base}-{quote}"
def to_kraken_pair(symbol: str) -> str:
"""
Kraken spot pair format is exchange-specific (e.g. XBTUSDT).
We use a best-effort mapping for common assets; callers can override by passing
already-normalized Kraken pair strings.
"""
base, quote = _split_base_quote(symbol)
if not base or not quote:
return symbol
b = _KRAKEN_BASE_MAP.get(base, base)
return f"{b}{quote}"
def to_kucoin_symbol(symbol: str) -> str:
"""
KuCoin spot symbol format: BASE-QUOTE, e.g. BTC-USDT.
"""
base, quote = _split_base_quote(symbol)
if not base or not quote:
return symbol
return f"{base}-{quote}"
def to_kucoin_futures_symbol(symbol: str) -> str:
"""
KuCoin Futures (USDT perpetual) symbol is exchange-specific, common examples:
- XBTUSDTM, ETHUSDTM
We provide a best-effort mapping: BASEQUOTE + "M".
If caller already provides an exchange-native symbol (no '/'), we return as-is.
"""
s = (symbol or "").strip()
if "/" not in s:
return s
base, quote = _split_base_quote(symbol)
if not base or not quote:
return s
b = _KUCOIN_FUTURES_BASE_MAP.get(base, base)
return f"{b}{quote}M"
def to_kraken_futures_symbol(symbol: str) -> str:
"""
Kraken Futures instruments are exchange-specific (e.g. PF_XBTUSD, PI_XBTUSD).
This helper is best-effort:
- If caller already passes an exchange-native instrument (contains '_' or starts with PF_/PI_), return as-is.
- Otherwise, map BTC->XBT and assume USD quote for futures (most Kraken Futures perps are USD margined).
"""
s = (symbol or "").strip()
if not s:
return s
up = s.upper()
if "_" in up or up.startswith("PF_") or up.startswith("PI_"):
return s
base, quote = _split_base_quote(symbol)
if not base:
return s
b = _KRAKEN_BASE_MAP.get(base, base)
q = "USD"
# Keep USDT as USD best-effort (platform-dependent)
if quote and quote.upper() == "USD":
q = "USD"
return f"PF_{b}{q}"
def to_gate_currency_pair(symbol: str) -> str:
"""
Gate spot/futures currency_pair/contract format: BASE_QUOTE, e.g. BTC_USDT.
"""
base, quote = _split_base_quote(symbol)
if not base or not quote:
return symbol
return f"{base}_{quote}"
def to_bitfinex_spot_symbol(symbol: str) -> str:
"""
Bitfinex spot trading symbol format: tBASEQUOTE, e.g. tBTCUST.
"""
base, quote = _split_base_quote(symbol)
if not base or not quote:
s = str(symbol or "").strip()
return s if s.startswith("t") else f"t{s}"
q = _BITFINEX_QUOTE_MAP.get(quote, quote)
return f"t{base}{q}"
def to_bitfinex_perp_symbol(symbol: str) -> str:
"""
Bitfinex derivatives perpetual naming (best-effort): tBASEF0:QUOTEF0, e.g. tBTCF0:USTF0.
"""
base, quote = _split_base_quote(symbol)
if not base or not quote:
s = str(symbol or "").strip()
return s if s.startswith("t") else f"t{s}"
q = _BITFINEX_QUOTE_MAP.get(quote, quote)
return f"t{base}F0:{q}F0"