Spaces:
Sleeping
Sleeping
Naufal Arhab commited on
Commit ·
5b56d1b
1
Parent(s): f9a601f
feat(bitget): integrate live V2 long-short ratio endpoint, AddPairModal exchange check, and 5-venue pair support
Browse files- backend/database/db.py +14 -8
- backend/exchanges/bitget.py +19 -0
- backend/main.py +52 -30
- backend/routers/signals.py +10 -2
- frontend/src/components/pairs/AddPairModal.tsx +4 -1
- frontend/src/components/pairs/PairItem.tsx +8 -0
backend/database/db.py
CHANGED
|
@@ -71,7 +71,7 @@ def _format_row(row: dict | None) -> dict | None:
|
|
| 71 |
d["signal_data"]["streak"] = int(d.get("streak_count") or 0)
|
| 72 |
if "streak_direction" not in d["signal_data"] or not d["signal_data"].get("streak_direction"):
|
| 73 |
d["signal_data"]["streak_direction"] = str(d.get("streak_direction") or "NEUTRAL")
|
| 74 |
-
for bool_col in ("on_binance", "on_bybit", "on_okx", "on_hyperliquid", "is_active"):
|
| 75 |
if bool_col in d and d[bool_col] is not None:
|
| 76 |
d[bool_col] = bool(d[bool_col])
|
| 77 |
if "streak_count" in d and d["streak_count"] is not None:
|
|
@@ -118,6 +118,7 @@ def init_db() -> None:
|
|
| 118 |
try:
|
| 119 |
cur.execute("""
|
| 120 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS on_okx BOOLEAN DEFAULT FALSE;
|
|
|
|
| 121 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS on_hyperliquid BOOLEAN DEFAULT FALSE;
|
| 122 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS streak_count INTEGER DEFAULT 0;
|
| 123 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS streak_direction TEXT DEFAULT 'NEUTRAL';
|
|
@@ -186,22 +187,24 @@ def db_insert_pair(
|
|
| 186 |
on_binance: bool = False,
|
| 187 |
on_bybit: bool = False,
|
| 188 |
on_okx: bool = False,
|
|
|
|
| 189 |
on_hyperliquid: bool = False,
|
| 190 |
) -> dict:
|
| 191 |
with get_connection() as conn:
|
| 192 |
with conn.cursor() as cur:
|
| 193 |
cur.execute(
|
| 194 |
-
"""INSERT INTO pairs (symbol, display_name, on_binance, on_bybit, on_okx, on_hyperliquid, is_active)
|
| 195 |
-
VALUES (%s, %s, %s, %s, %s, %s, TRUE)
|
| 196 |
ON CONFLICT (symbol) DO UPDATE SET
|
| 197 |
display_name = EXCLUDED.display_name,
|
| 198 |
on_binance = EXCLUDED.on_binance,
|
| 199 |
on_bybit = EXCLUDED.on_bybit,
|
| 200 |
on_okx = EXCLUDED.on_okx,
|
|
|
|
| 201 |
on_hyperliquid = EXCLUDED.on_hyperliquid,
|
| 202 |
is_active = TRUE
|
| 203 |
RETURNING *""",
|
| 204 |
-
(symbol, display_name, bool(on_binance), bool(on_bybit), bool(on_okx), bool(on_hyperliquid)),
|
| 205 |
)
|
| 206 |
row = cur.fetchone()
|
| 207 |
return _format_row(row)
|
|
@@ -212,16 +215,17 @@ def db_update_pair_exchanges(
|
|
| 212 |
on_binance: bool,
|
| 213 |
on_bybit: bool,
|
| 214 |
on_okx: bool = False,
|
|
|
|
| 215 |
on_hyperliquid: bool = False,
|
| 216 |
) -> dict | None:
|
| 217 |
with get_connection() as conn:
|
| 218 |
with conn.cursor() as cur:
|
| 219 |
cur.execute(
|
| 220 |
"""UPDATE pairs
|
| 221 |
-
SET on_binance = %s, on_bybit = %s, on_okx = %s, on_hyperliquid = %s
|
| 222 |
WHERE symbol = %s
|
| 223 |
RETURNING *""",
|
| 224 |
-
(bool(on_binance), bool(on_bybit), bool(on_okx), bool(on_hyperliquid), symbol),
|
| 225 |
)
|
| 226 |
row = cur.fetchone()
|
| 227 |
return _format_row(row)
|
|
@@ -438,10 +442,11 @@ async def async_insert_pair(
|
|
| 438 |
on_binance: bool = False,
|
| 439 |
on_bybit: bool = False,
|
| 440 |
on_okx: bool = False,
|
|
|
|
| 441 |
on_hyperliquid: bool = False,
|
| 442 |
) -> dict:
|
| 443 |
return await asyncio.to_thread(
|
| 444 |
-
db_insert_pair, symbol, display_name, on_binance, on_bybit, on_okx, on_hyperliquid
|
| 445 |
)
|
| 446 |
|
| 447 |
async def async_update_pair_exchanges(
|
|
@@ -449,10 +454,11 @@ async def async_update_pair_exchanges(
|
|
| 449 |
on_binance: bool,
|
| 450 |
on_bybit: bool,
|
| 451 |
on_okx: bool = False,
|
|
|
|
| 452 |
on_hyperliquid: bool = False,
|
| 453 |
) -> dict | None:
|
| 454 |
return await asyncio.to_thread(
|
| 455 |
-
db_update_pair_exchanges, symbol, on_binance, on_bybit, on_okx, on_hyperliquid
|
| 456 |
)
|
| 457 |
|
| 458 |
async def async_update_pair_streak(
|
|
|
|
| 71 |
d["signal_data"]["streak"] = int(d.get("streak_count") or 0)
|
| 72 |
if "streak_direction" not in d["signal_data"] or not d["signal_data"].get("streak_direction"):
|
| 73 |
d["signal_data"]["streak_direction"] = str(d.get("streak_direction") or "NEUTRAL")
|
| 74 |
+
for bool_col in ("on_binance", "on_bybit", "on_okx", "on_bitget", "on_hyperliquid", "is_active"):
|
| 75 |
if bool_col in d and d[bool_col] is not None:
|
| 76 |
d[bool_col] = bool(d[bool_col])
|
| 77 |
if "streak_count" in d and d["streak_count"] is not None:
|
|
|
|
| 118 |
try:
|
| 119 |
cur.execute("""
|
| 120 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS on_okx BOOLEAN DEFAULT FALSE;
|
| 121 |
+
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS on_bitget BOOLEAN DEFAULT FALSE;
|
| 122 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS on_hyperliquid BOOLEAN DEFAULT FALSE;
|
| 123 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS streak_count INTEGER DEFAULT 0;
|
| 124 |
ALTER TABLE pairs ADD COLUMN IF NOT EXISTS streak_direction TEXT DEFAULT 'NEUTRAL';
|
|
|
|
| 187 |
on_binance: bool = False,
|
| 188 |
on_bybit: bool = False,
|
| 189 |
on_okx: bool = False,
|
| 190 |
+
on_bitget: bool = False,
|
| 191 |
on_hyperliquid: bool = False,
|
| 192 |
) -> dict:
|
| 193 |
with get_connection() as conn:
|
| 194 |
with conn.cursor() as cur:
|
| 195 |
cur.execute(
|
| 196 |
+
"""INSERT INTO pairs (symbol, display_name, on_binance, on_bybit, on_okx, on_bitget, on_hyperliquid, is_active)
|
| 197 |
+
VALUES (%s, %s, %s, %s, %s, %s, %s, TRUE)
|
| 198 |
ON CONFLICT (symbol) DO UPDATE SET
|
| 199 |
display_name = EXCLUDED.display_name,
|
| 200 |
on_binance = EXCLUDED.on_binance,
|
| 201 |
on_bybit = EXCLUDED.on_bybit,
|
| 202 |
on_okx = EXCLUDED.on_okx,
|
| 203 |
+
on_bitget = EXCLUDED.on_bitget,
|
| 204 |
on_hyperliquid = EXCLUDED.on_hyperliquid,
|
| 205 |
is_active = TRUE
|
| 206 |
RETURNING *""",
|
| 207 |
+
(symbol, display_name, bool(on_binance), bool(on_bybit), bool(on_okx), bool(on_bitget), bool(on_hyperliquid)),
|
| 208 |
)
|
| 209 |
row = cur.fetchone()
|
| 210 |
return _format_row(row)
|
|
|
|
| 215 |
on_binance: bool,
|
| 216 |
on_bybit: bool,
|
| 217 |
on_okx: bool = False,
|
| 218 |
+
on_bitget: bool = False,
|
| 219 |
on_hyperliquid: bool = False,
|
| 220 |
) -> dict | None:
|
| 221 |
with get_connection() as conn:
|
| 222 |
with conn.cursor() as cur:
|
| 223 |
cur.execute(
|
| 224 |
"""UPDATE pairs
|
| 225 |
+
SET on_binance = %s, on_bybit = %s, on_okx = %s, on_bitget = %s, on_hyperliquid = %s
|
| 226 |
WHERE symbol = %s
|
| 227 |
RETURNING *""",
|
| 228 |
+
(bool(on_binance), bool(on_bybit), bool(on_okx), bool(on_bitget), bool(on_hyperliquid), symbol),
|
| 229 |
)
|
| 230 |
row = cur.fetchone()
|
| 231 |
return _format_row(row)
|
|
|
|
| 442 |
on_binance: bool = False,
|
| 443 |
on_bybit: bool = False,
|
| 444 |
on_okx: bool = False,
|
| 445 |
+
on_bitget: bool = False,
|
| 446 |
on_hyperliquid: bool = False,
|
| 447 |
) -> dict:
|
| 448 |
return await asyncio.to_thread(
|
| 449 |
+
db_insert_pair, symbol, display_name, on_binance, on_bybit, on_okx, on_bitget, on_hyperliquid
|
| 450 |
)
|
| 451 |
|
| 452 |
async def async_update_pair_exchanges(
|
|
|
|
| 454 |
on_binance: bool,
|
| 455 |
on_bybit: bool,
|
| 456 |
on_okx: bool = False,
|
| 457 |
+
on_bitget: bool = False,
|
| 458 |
on_hyperliquid: bool = False,
|
| 459 |
) -> dict | None:
|
| 460 |
return await asyncio.to_thread(
|
| 461 |
+
db_update_pair_exchanges, symbol, on_binance, on_bybit, on_okx, on_bitget, on_hyperliquid
|
| 462 |
)
|
| 463 |
|
| 464 |
async def async_update_pair_streak(
|
backend/exchanges/bitget.py
CHANGED
|
@@ -157,6 +157,25 @@ class BitgetClient(BaseExchange):
|
|
| 157 |
return {"open_interest": None, "open_interest_value": None, "oi_change_pct": None}
|
| 158 |
|
| 159 |
async def get_long_short_ratio(self, symbol: str, period: str = "1h") -> dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
return {
|
| 161 |
"long_ratio": None,
|
| 162 |
"short_ratio": None,
|
|
|
|
| 157 |
return {"open_interest": None, "open_interest_value": None, "oi_change_pct": None}
|
| 158 |
|
| 159 |
async def get_long_short_ratio(self, symbol: str, period: str = "1h") -> dict[str, Any]:
|
| 160 |
+
"""Fetch Long/Short account ratio from Bitget V2 mix market."""
|
| 161 |
+
sym = self._to_bitget_symbol(symbol)
|
| 162 |
+
try:
|
| 163 |
+
data = await self._get(
|
| 164 |
+
"/api/v2/mix/market/long-short",
|
| 165 |
+
{"symbol": sym, "productType": "USDT-FUTURES"},
|
| 166 |
+
)
|
| 167 |
+
if data and isinstance(data, list) and len(data) > 0:
|
| 168 |
+
# Bitget returns list of time intervals with newest at data[-1]
|
| 169 |
+
latest = data[-1]
|
| 170 |
+
long_ratio = float(latest.get("longRatio", 0.5))
|
| 171 |
+
short_ratio = float(latest.get("shortRatio", 0.5))
|
| 172 |
+
return {
|
| 173 |
+
"long_ratio": round(long_ratio, 4),
|
| 174 |
+
"short_ratio": round(short_ratio, 4),
|
| 175 |
+
"source": "top_trader",
|
| 176 |
+
}
|
| 177 |
+
except Exception as exc:
|
| 178 |
+
logger.debug("[Bitget] L/S ratio fetch for %s: %s", sym, exc)
|
| 179 |
return {
|
| 180 |
"long_ratio": None,
|
| 181 |
"short_ratio": None,
|
backend/main.py
CHANGED
|
@@ -78,6 +78,7 @@ async def _process_pair(
|
|
| 78 |
on_binance = bool(pair.get("on_binance", False))
|
| 79 |
on_bybit = bool(pair.get("on_bybit", False))
|
| 80 |
on_okx = bool(pair.get("on_okx", False))
|
|
|
|
| 81 |
on_hyperliquid = bool(pair.get("on_hyperliquid", False))
|
| 82 |
|
| 83 |
# Auto-Discovery: Check if newly listed or newly resolved on an exchange where it was previously marked unavailable
|
|
@@ -119,6 +120,15 @@ async def _process_pair(
|
|
| 119 |
except Exception:
|
| 120 |
pass
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if not on_hyperliquid:
|
| 123 |
try:
|
| 124 |
if await collector._hyperliquid.check_symbol_exists(symbol):
|
|
@@ -130,7 +140,7 @@ async def _process_pair(
|
|
| 130 |
|
| 131 |
if exchanges_updated:
|
| 132 |
try:
|
| 133 |
-
updated_pair = await async_update_pair_exchanges(symbol, on_binance, on_bybit, on_okx, on_hyperliquid)
|
| 134 |
if updated_pair:
|
| 135 |
await broadcast({"type": "pair_updated", "data": updated_pair})
|
| 136 |
except Exception as exc:
|
|
@@ -143,7 +153,7 @@ async def _process_pair(
|
|
| 143 |
on_bybit=on_bybit,
|
| 144 |
on_okx=on_okx,
|
| 145 |
on_hyperliquid=on_hyperliquid,
|
| 146 |
-
on_bitget=
|
| 147 |
)
|
| 148 |
except Exception as exc:
|
| 149 |
logger.error("[%s] Data collection error: %s", symbol, exc)
|
|
@@ -477,14 +487,15 @@ async def list_pairs():
|
|
| 477 |
@app.post("/api/pairs/validate", tags=["pairs"])
|
| 478 |
async def validate_pair(body: ValidateRequest, request: Request):
|
| 479 |
"""
|
| 480 |
-
Check if a symbol exists on Binance, Bybit, OKX, or Hyperliquid as a perpetual.
|
| 481 |
Automatically appends USDT if only base asset is provided (e.g. 'BTC' -> 'BTCUSDT').
|
| 482 |
-
Returns: {"symbol": str, "on_binance": bool, "on_bybit": bool, "on_okx": bool, "on_hyperliquid": bool, "valid": bool}
|
| 483 |
"""
|
| 484 |
symbol = _normalize_symbol(body.symbol)
|
| 485 |
binance: BinanceClient = request.app.state.binance
|
| 486 |
bybit: BybitClient = request.app.state.bybit
|
| 487 |
okx: OKXClient = getattr(request.app.state, "okx", None)
|
|
|
|
| 488 |
hl: HyperliquidClient = getattr(request.app.state, "hyperliquid", None)
|
| 489 |
|
| 490 |
tasks = [
|
|
@@ -493,35 +504,40 @@ async def validate_pair(body: ValidateRequest, request: Request):
|
|
| 493 |
]
|
| 494 |
if okx:
|
| 495 |
tasks.append(okx.check_symbol_exists(symbol))
|
|
|
|
|
|
|
| 496 |
if hl:
|
| 497 |
tasks.append(hl.check_symbol_exists(symbol))
|
| 498 |
|
| 499 |
results = await asyncio.gather(*tasks, return_exceptions=True)
|
| 500 |
|
| 501 |
-
|
| 502 |
-
logger.warning("[%s] Binance validate error: %s", symbol, results[0])
|
| 503 |
-
if isinstance(results[1], Exception):
|
| 504 |
-
logger.warning("[%s] Bybit validate error: %s", symbol, results[1])
|
| 505 |
-
if len(results) > 2 and isinstance(results[2], Exception):
|
| 506 |
-
logger.warning("[%s] OKX validate error: %s", symbol, results[2])
|
| 507 |
-
if len(results) > 3 and isinstance(results[3], Exception):
|
| 508 |
-
logger.warning("[%s] Hyperliquid validate error: %s", symbol, results[3])
|
| 509 |
-
|
| 510 |
on_binance = bool(results[0]) if not isinstance(results[0], Exception) else False
|
| 511 |
on_bybit = bool(results[1]) if not isinstance(results[1], Exception) else False
|
| 512 |
-
on_okx =
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
| 515 |
-
is_valid = bool(on_binance or on_bybit or on_okx or on_hl)
|
| 516 |
|
| 517 |
return {
|
| 518 |
"symbol": symbol,
|
| 519 |
"on_binance": on_binance,
|
| 520 |
"on_bybit": on_bybit,
|
| 521 |
"on_okx": on_okx,
|
|
|
|
| 522 |
"on_hyperliquid": on_hl,
|
| 523 |
"valid": is_valid,
|
| 524 |
-
"message": "Valid perpetual pair" if is_valid else "Symbol not found on Binance, Bybit, OKX, or Hyperliquid"
|
| 525 |
}
|
| 526 |
|
| 527 |
|
|
@@ -548,6 +564,7 @@ async def add_pair(body: AddPairRequest, request: Request):
|
|
| 548 |
binance: BinanceClient = request.app.state.binance
|
| 549 |
bybit: BybitClient = request.app.state.bybit
|
| 550 |
okx: OKXClient = getattr(request.app.state, "okx", None)
|
|
|
|
| 551 |
hl: HyperliquidClient = getattr(request.app.state, "hyperliquid", None)
|
| 552 |
|
| 553 |
tasks = [
|
|
@@ -556,30 +573,34 @@ async def add_pair(body: AddPairRequest, request: Request):
|
|
| 556 |
]
|
| 557 |
if okx:
|
| 558 |
tasks.append(okx.check_symbol_exists(symbol))
|
|
|
|
|
|
|
| 559 |
if hl:
|
| 560 |
tasks.append(hl.check_symbol_exists(symbol))
|
| 561 |
|
| 562 |
results = await asyncio.gather(*tasks, return_exceptions=True)
|
| 563 |
|
| 564 |
-
|
| 565 |
-
logger.warning("[%s] Binance validate error: %s", symbol, results[0])
|
| 566 |
-
if isinstance(results[1], Exception):
|
| 567 |
-
logger.warning("[%s] Bybit validate error: %s", symbol, results[1])
|
| 568 |
-
if len(results) > 2 and isinstance(results[2], Exception):
|
| 569 |
-
logger.warning("[%s] OKX validate error: %s", symbol, results[2])
|
| 570 |
-
if len(results) > 3 and isinstance(results[3], Exception):
|
| 571 |
-
logger.warning("[%s] Hyperliquid validate error: %s", symbol, results[3])
|
| 572 |
-
|
| 573 |
on_binance = bool(results[0]) if not isinstance(results[0], Exception) else False
|
| 574 |
on_bybit = bool(results[1]) if not isinstance(results[1], Exception) else False
|
| 575 |
-
on_okx =
|
| 576 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
|
| 578 |
-
if not (on_binance or on_bybit or on_okx or on_hl):
|
| 579 |
from fastapi import HTTPException
|
| 580 |
raise HTTPException(
|
| 581 |
status_code=422,
|
| 582 |
-
detail=f"{symbol} not found on Binance, Bybit, OKX, or Hyperliquid as a perpetual",
|
| 583 |
)
|
| 584 |
|
| 585 |
coin = symbol
|
|
@@ -596,6 +617,7 @@ async def add_pair(body: AddPairRequest, request: Request):
|
|
| 596 |
on_binance=on_binance,
|
| 597 |
on_bybit=on_bybit,
|
| 598 |
on_okx=on_okx,
|
|
|
|
| 599 |
on_hyperliquid=on_hl,
|
| 600 |
)
|
| 601 |
|
|
|
|
| 78 |
on_binance = bool(pair.get("on_binance", False))
|
| 79 |
on_bybit = bool(pair.get("on_bybit", False))
|
| 80 |
on_okx = bool(pair.get("on_okx", False))
|
| 81 |
+
on_bitget = bool(pair.get("on_bitget", False))
|
| 82 |
on_hyperliquid = bool(pair.get("on_hyperliquid", False))
|
| 83 |
|
| 84 |
# Auto-Discovery: Check if newly listed or newly resolved on an exchange where it was previously marked unavailable
|
|
|
|
| 120 |
except Exception:
|
| 121 |
pass
|
| 122 |
|
| 123 |
+
if not on_bitget:
|
| 124 |
+
try:
|
| 125 |
+
if await collector._bitget.check_symbol_exists(symbol):
|
| 126 |
+
on_bitget = True
|
| 127 |
+
exchanges_updated = True
|
| 128 |
+
logger.info("🎉 [%s] Auto-Discovery: Terdeteksi di Bitget! Mengaktifkan Bitget feed.", symbol)
|
| 129 |
+
except Exception:
|
| 130 |
+
pass
|
| 131 |
+
|
| 132 |
if not on_hyperliquid:
|
| 133 |
try:
|
| 134 |
if await collector._hyperliquid.check_symbol_exists(symbol):
|
|
|
|
| 140 |
|
| 141 |
if exchanges_updated:
|
| 142 |
try:
|
| 143 |
+
updated_pair = await async_update_pair_exchanges(symbol, on_binance, on_bybit, on_okx, on_bitget, on_hyperliquid)
|
| 144 |
if updated_pair:
|
| 145 |
await broadcast({"type": "pair_updated", "data": updated_pair})
|
| 146 |
except Exception as exc:
|
|
|
|
| 153 |
on_bybit=on_bybit,
|
| 154 |
on_okx=on_okx,
|
| 155 |
on_hyperliquid=on_hyperliquid,
|
| 156 |
+
on_bitget=on_bitget,
|
| 157 |
)
|
| 158 |
except Exception as exc:
|
| 159 |
logger.error("[%s] Data collection error: %s", symbol, exc)
|
|
|
|
| 487 |
@app.post("/api/pairs/validate", tags=["pairs"])
|
| 488 |
async def validate_pair(body: ValidateRequest, request: Request):
|
| 489 |
"""
|
| 490 |
+
Check if a symbol exists on Binance, Bybit, OKX, Bitget, or Hyperliquid as a perpetual.
|
| 491 |
Automatically appends USDT if only base asset is provided (e.g. 'BTC' -> 'BTCUSDT').
|
| 492 |
+
Returns: {"symbol": str, "on_binance": bool, "on_bybit": bool, "on_okx": bool, "on_bitget": bool, "on_hyperliquid": bool, "valid": bool}
|
| 493 |
"""
|
| 494 |
symbol = _normalize_symbol(body.symbol)
|
| 495 |
binance: BinanceClient = request.app.state.binance
|
| 496 |
bybit: BybitClient = request.app.state.bybit
|
| 497 |
okx: OKXClient = getattr(request.app.state, "okx", None)
|
| 498 |
+
bitget: BitgetClient = getattr(request.app.state, "bitget", None)
|
| 499 |
hl: HyperliquidClient = getattr(request.app.state, "hyperliquid", None)
|
| 500 |
|
| 501 |
tasks = [
|
|
|
|
| 504 |
]
|
| 505 |
if okx:
|
| 506 |
tasks.append(okx.check_symbol_exists(symbol))
|
| 507 |
+
if bitget:
|
| 508 |
+
tasks.append(bitget.check_symbol_exists(symbol))
|
| 509 |
if hl:
|
| 510 |
tasks.append(hl.check_symbol_exists(symbol))
|
| 511 |
|
| 512 |
results = await asyncio.gather(*tasks, return_exceptions=True)
|
| 513 |
|
| 514 |
+
idx = 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
on_binance = bool(results[0]) if not isinstance(results[0], Exception) else False
|
| 516 |
on_bybit = bool(results[1]) if not isinstance(results[1], Exception) else False
|
| 517 |
+
on_okx = False
|
| 518 |
+
if okx:
|
| 519 |
+
on_okx = bool(results[idx]) if not isinstance(results[idx], Exception) else False
|
| 520 |
+
idx += 1
|
| 521 |
+
on_bitget = False
|
| 522 |
+
if bitget:
|
| 523 |
+
on_bitget = bool(results[idx]) if not isinstance(results[idx], Exception) else False
|
| 524 |
+
idx += 1
|
| 525 |
+
on_hl = False
|
| 526 |
+
if hl:
|
| 527 |
+
on_hl = bool(results[idx]) if not isinstance(results[idx], Exception) else False
|
| 528 |
+
idx += 1
|
| 529 |
|
| 530 |
+
is_valid = bool(on_binance or on_bybit or on_okx or on_bitget or on_hl)
|
| 531 |
|
| 532 |
return {
|
| 533 |
"symbol": symbol,
|
| 534 |
"on_binance": on_binance,
|
| 535 |
"on_bybit": on_bybit,
|
| 536 |
"on_okx": on_okx,
|
| 537 |
+
"on_bitget": on_bitget,
|
| 538 |
"on_hyperliquid": on_hl,
|
| 539 |
"valid": is_valid,
|
| 540 |
+
"message": "Valid perpetual pair" if is_valid else "Symbol not found on Binance, Bybit, OKX, Bitget, or Hyperliquid"
|
| 541 |
}
|
| 542 |
|
| 543 |
|
|
|
|
| 564 |
binance: BinanceClient = request.app.state.binance
|
| 565 |
bybit: BybitClient = request.app.state.bybit
|
| 566 |
okx: OKXClient = getattr(request.app.state, "okx", None)
|
| 567 |
+
bitget: BitgetClient = getattr(request.app.state, "bitget", None)
|
| 568 |
hl: HyperliquidClient = getattr(request.app.state, "hyperliquid", None)
|
| 569 |
|
| 570 |
tasks = [
|
|
|
|
| 573 |
]
|
| 574 |
if okx:
|
| 575 |
tasks.append(okx.check_symbol_exists(symbol))
|
| 576 |
+
if bitget:
|
| 577 |
+
tasks.append(bitget.check_symbol_exists(symbol))
|
| 578 |
if hl:
|
| 579 |
tasks.append(hl.check_symbol_exists(symbol))
|
| 580 |
|
| 581 |
results = await asyncio.gather(*tasks, return_exceptions=True)
|
| 582 |
|
| 583 |
+
idx = 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 584 |
on_binance = bool(results[0]) if not isinstance(results[0], Exception) else False
|
| 585 |
on_bybit = bool(results[1]) if not isinstance(results[1], Exception) else False
|
| 586 |
+
on_okx = False
|
| 587 |
+
if okx:
|
| 588 |
+
on_okx = bool(results[idx]) if not isinstance(results[idx], Exception) else False
|
| 589 |
+
idx += 1
|
| 590 |
+
on_bitget = False
|
| 591 |
+
if bitget:
|
| 592 |
+
on_bitget = bool(results[idx]) if not isinstance(results[idx], Exception) else False
|
| 593 |
+
idx += 1
|
| 594 |
+
on_hl = False
|
| 595 |
+
if hl:
|
| 596 |
+
on_hl = bool(results[idx]) if not isinstance(results[idx], Exception) else False
|
| 597 |
+
idx += 1
|
| 598 |
|
| 599 |
+
if not (on_binance or on_bybit or on_okx or on_bitget or on_hl):
|
| 600 |
from fastapi import HTTPException
|
| 601 |
raise HTTPException(
|
| 602 |
status_code=422,
|
| 603 |
+
detail=f"{symbol} not found on Binance, Bybit, OKX, Bitget, or Hyperliquid as a perpetual",
|
| 604 |
)
|
| 605 |
|
| 606 |
coin = symbol
|
|
|
|
| 617 |
on_binance=on_binance,
|
| 618 |
on_bybit=on_bybit,
|
| 619 |
on_okx=on_okx,
|
| 620 |
+
on_bitget=on_bitget,
|
| 621 |
on_hyperliquid=on_hl,
|
| 622 |
)
|
| 623 |
|
backend/routers/signals.py
CHANGED
|
@@ -224,6 +224,14 @@ async def refresh_signal(symbol: str, request: Request):
|
|
| 224 |
exchanges_updated = True
|
| 225 |
except Exception:
|
| 226 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
if not on_hyperliquid:
|
| 228 |
try:
|
| 229 |
if await collector._hyperliquid.check_symbol_exists(sym):
|
|
@@ -234,7 +242,7 @@ async def refresh_signal(symbol: str, request: Request):
|
|
| 234 |
|
| 235 |
if exchanges_updated:
|
| 236 |
try:
|
| 237 |
-
updated_p = await async_update_pair_exchanges(sym, on_binance, on_bybit, on_okx, on_hyperliquid)
|
| 238 |
if updated_p:
|
| 239 |
await broadcast({"type": "pair_updated", "data": updated_p})
|
| 240 |
except Exception:
|
|
@@ -246,7 +254,7 @@ async def refresh_signal(symbol: str, request: Request):
|
|
| 246 |
on_bybit=on_bybit,
|
| 247 |
on_okx=on_okx,
|
| 248 |
on_hyperliquid=on_hyperliquid,
|
| 249 |
-
on_bitget=
|
| 250 |
)
|
| 251 |
signal = _signal_engine.compute(raw)
|
| 252 |
|
|
|
|
| 224 |
exchanges_updated = True
|
| 225 |
except Exception:
|
| 226 |
pass
|
| 227 |
+
on_bitget = bool(pair_meta.get("on_bitget", False)) if pair_meta else False
|
| 228 |
+
if not on_bitget:
|
| 229 |
+
try:
|
| 230 |
+
if await collector._bitget.check_symbol_exists(sym):
|
| 231 |
+
on_bitget = True
|
| 232 |
+
exchanges_updated = True
|
| 233 |
+
except Exception:
|
| 234 |
+
pass
|
| 235 |
if not on_hyperliquid:
|
| 236 |
try:
|
| 237 |
if await collector._hyperliquid.check_symbol_exists(sym):
|
|
|
|
| 242 |
|
| 243 |
if exchanges_updated:
|
| 244 |
try:
|
| 245 |
+
updated_p = await async_update_pair_exchanges(sym, on_binance, on_bybit, on_okx, on_bitget, on_hyperliquid)
|
| 246 |
if updated_p:
|
| 247 |
await broadcast({"type": "pair_updated", "data": updated_p})
|
| 248 |
except Exception:
|
|
|
|
| 254 |
on_bybit=on_bybit,
|
| 255 |
on_okx=on_okx,
|
| 256 |
on_hyperliquid=on_hyperliquid,
|
| 257 |
+
on_bitget=on_bitget,
|
| 258 |
)
|
| 259 |
signal = _signal_engine.compute(raw)
|
| 260 |
|
frontend/src/components/pairs/AddPairModal.tsx
CHANGED
|
@@ -74,7 +74,7 @@ export function AddPairModal({ isOpen, onClose }: AddPairModalProps) {
|
|
| 74 |
|
| 75 |
const canAdd = Boolean(
|
| 76 |
validationResult &&
|
| 77 |
-
(validationResult.valid ?? (validationResult.on_binance || validationResult.on_bybit || validationResult.on_okx || validationResult.on_hyperliquid))
|
| 78 |
);
|
| 79 |
|
| 80 |
return (
|
|
@@ -158,6 +158,9 @@ export function AddPairModal({ isOpen, onClose }: AddPairModalProps) {
|
|
| 158 |
{validationResult.on_okx !== undefined && (
|
| 159 |
<ExchangeCheck label="OKX" found={validationResult.on_okx} />
|
| 160 |
)}
|
|
|
|
|
|
|
|
|
|
| 161 |
{validationResult.on_hyperliquid !== undefined && (
|
| 162 |
<ExchangeCheck label="Hyperliquid" found={validationResult.on_hyperliquid} />
|
| 163 |
)}
|
|
|
|
| 74 |
|
| 75 |
const canAdd = Boolean(
|
| 76 |
validationResult &&
|
| 77 |
+
(validationResult.valid ?? (validationResult.on_binance || validationResult.on_bybit || validationResult.on_okx || validationResult.on_bitget || validationResult.on_hyperliquid))
|
| 78 |
);
|
| 79 |
|
| 80 |
return (
|
|
|
|
| 158 |
{validationResult.on_okx !== undefined && (
|
| 159 |
<ExchangeCheck label="OKX" found={validationResult.on_okx} />
|
| 160 |
)}
|
| 161 |
+
{validationResult.on_bitget !== undefined && (
|
| 162 |
+
<ExchangeCheck label="Bitget" found={validationResult.on_bitget} />
|
| 163 |
+
)}
|
| 164 |
{validationResult.on_hyperliquid !== undefined && (
|
| 165 |
<ExchangeCheck label="Hyperliquid" found={validationResult.on_hyperliquid} />
|
| 166 |
)}
|
frontend/src/components/pairs/PairItem.tsx
CHANGED
|
@@ -119,6 +119,14 @@ export function PairItem({ pair, signal, isSelected, onSelect }: PairItemProps)
|
|
| 119 |
>
|
| 120 |
{pair.on_okx ? '✓' : '○'} OKX
|
| 121 |
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
<span
|
| 123 |
className={`flex items-center gap-0.5 font-mono ${
|
| 124 |
pair.on_hyperliquid ? 'text-signal-long font-medium' : 'text-text-muted/40'
|
|
|
|
| 119 |
>
|
| 120 |
{pair.on_okx ? '✓' : '○'} OKX
|
| 121 |
</span>
|
| 122 |
+
<span
|
| 123 |
+
className={`flex items-center gap-0.5 font-mono ${
|
| 124 |
+
pair.on_bitget ? 'text-signal-long font-medium' : 'text-text-muted/40'
|
| 125 |
+
}`}
|
| 126 |
+
title={`Bitget: ${pair.on_bitget ? 'Available' : 'Unavailable'}`}
|
| 127 |
+
>
|
| 128 |
+
{pair.on_bitget ? '✓' : '○'} Bit
|
| 129 |
+
</span>
|
| 130 |
<span
|
| 131 |
className={`flex items-center gap-0.5 font-mono ${
|
| 132 |
pair.on_hyperliquid ? 'text-signal-long font-medium' : 'text-text-muted/40'
|