Spaces:
Sleeping

Naufal Arhab commited on
Commit
cea524b
·
1 Parent(s): 0e7317d

Fix: Multiplier meme prefix spot lookup (1000PEPE, 1000SHIB, etc) and add safety badges to TopTradeBanner and PairItem

Browse files
backend/engine/data_collector.py CHANGED
@@ -22,28 +22,49 @@ from exchanges.hyperliquid import HyperliquidClient
22
 
23
  logger = logging.getLogger(__name__)
24
 
25
- # Cache spot availability across Binance & Bybit spot markets
26
  _SPOT_VERIFICATION_CACHE: dict[str, bool] = {}
27
 
28
 
 
 
 
 
 
 
 
 
 
29
  async def check_spot_market_exists(symbol: str) -> bool:
30
  """
31
- Check if a symbol exists on Binance Spot or Bybit Spot market.
 
32
  Cached indefinitely in-memory to prevent redundant network calls.
33
  """
34
  if symbol in _SPOT_VERIFICATION_CACHE:
35
  return _SPOT_VERIFICATION_CACHE[symbol]
36
 
 
 
 
 
 
37
  # 1. Check Binance Spot
38
  try:
39
  def _check_binance():
40
  import httpx
41
- r = httpx.get(
42
- f"https://api.binance.com/api/v3/ticker/price?symbol={symbol}",
43
- timeout=4.0,
44
- verify=False,
45
- )
46
- return r.status_code == 200
 
 
 
 
 
 
47
 
48
  has_spot = await asyncio.to_thread(_check_binance)
49
  if has_spot:
@@ -57,17 +78,51 @@ async def check_spot_market_exists(symbol: str) -> bool:
57
  def _check_bybit():
58
  import httpx
59
  from config import BYBIT_BASE_URL
60
- r = httpx.get(
61
- f"{BYBIT_BASE_URL}/v5/market/instruments-info?category=spot&symbol={symbol}",
62
- timeout=4.0,
63
- verify=False,
64
- )
65
- if r.status_code == 200:
66
- data = r.json()
67
- return len(data.get("result", {}).get("list", [])) > 0
 
 
 
 
 
68
  return False
69
 
70
  has_spot = await asyncio.to_thread(_check_bybit)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  _SPOT_VERIFICATION_CACHE[symbol] = bool(has_spot)
72
  return bool(has_spot)
73
  except Exception:
 
22
 
23
  logger = logging.getLogger(__name__)
24
 
25
+ # Cache spot availability across Binance, Bybit, and OKX spot markets
26
  _SPOT_VERIFICATION_CACHE: dict[str, bool] = {}
27
 
28
 
29
+ def _clean_spot_symbol(symbol: str) -> str:
30
+ """
31
+ Strip futures multiplier prefixes (1000, 10000, 1000000, k) to match spot tickers.
32
+ e.g. 1000PEPEUSDT -> PEPEUSDT, 1000SHIBUSDT -> SHIBUSDT, 1000BONKUSDT -> BONKUSDT
33
+ """
34
+ import re
35
+ return re.sub(r'^(1000000000|1000000|100000|10000|1000|k)', '', symbol, flags=re.IGNORECASE).upper()
36
+
37
+
38
  async def check_spot_market_exists(symbol: str) -> bool:
39
  """
40
+ Check if a symbol exists on Binance Spot, Bybit Spot, or OKX Spot market.
41
+ Supports both raw tickers (BTCUSDT, 1000SATSUSDT) and cleaned tickers (PEPEUSDT for 1000PEPEUSDT).
42
  Cached indefinitely in-memory to prevent redundant network calls.
43
  """
44
  if symbol in _SPOT_VERIFICATION_CACHE:
45
  return _SPOT_VERIFICATION_CACHE[symbol]
46
 
47
+ clean_symbol = _clean_spot_symbol(symbol)
48
+ symbols_to_try = [symbol]
49
+ if clean_symbol != symbol and clean_symbol.endswith("USDT"):
50
+ symbols_to_try.append(clean_symbol)
51
+
52
  # 1. Check Binance Spot
53
  try:
54
  def _check_binance():
55
  import httpx
56
+ for sym in symbols_to_try:
57
+ try:
58
+ r = httpx.get(
59
+ f"https://api.binance.com/api/v3/ticker/price?symbol={sym}",
60
+ timeout=3.5,
61
+ verify=False,
62
+ )
63
+ if r.status_code == 200:
64
+ return True
65
+ except Exception:
66
+ pass
67
+ return False
68
 
69
  has_spot = await asyncio.to_thread(_check_binance)
70
  if has_spot:
 
78
  def _check_bybit():
79
  import httpx
80
  from config import BYBIT_BASE_URL
81
+ for sym in symbols_to_try:
82
+ try:
83
+ r = httpx.get(
84
+ f"{BYBIT_BASE_URL}/v5/market/instruments-info?category=spot&symbol={sym}",
85
+ timeout=3.5,
86
+ verify=False,
87
+ )
88
+ if r.status_code == 200:
89
+ data = r.json()
90
+ if len(data.get("result", {}).get("list", [])) > 0:
91
+ return True
92
+ except Exception:
93
+ pass
94
  return False
95
 
96
  has_spot = await asyncio.to_thread(_check_bybit)
97
+ if has_spot:
98
+ _SPOT_VERIFICATION_CACHE[symbol] = True
99
+ return True
100
+ except Exception:
101
+ pass
102
+
103
+ # 3. Check OKX Spot
104
+ try:
105
+ def _check_okx():
106
+ import httpx
107
+ for sym in symbols_to_try:
108
+ if sym.endswith("USDT"):
109
+ base = sym[:-4]
110
+ inst_id = f"{base}-USDT"
111
+ try:
112
+ r = httpx.get(
113
+ f"https://www.okx.com/api/v5/public/instruments?instType=SPOT&instId={inst_id}",
114
+ timeout=3.5,
115
+ verify=False,
116
+ )
117
+ if r.status_code == 200:
118
+ data = r.json()
119
+ if len(data.get("data", [])) > 0:
120
+ return True
121
+ except Exception:
122
+ pass
123
+ return False
124
+
125
+ has_spot = await asyncio.to_thread(_check_okx)
126
  _SPOT_VERIFICATION_CACHE[symbol] = bool(has_spot)
127
  return bool(has_spot)
128
  except Exception:
backend/exchanges/binance.py CHANGED
@@ -207,13 +207,26 @@ class BinanceClient(BaseExchange):
207
 
208
  async def get_spot_trades(self, symbol: str, limit: int = 500) -> list[dict]:
209
  """Fetch spot trades from Binance Spot API for Spot CVD vs Futures CVD analysis."""
 
 
 
 
 
 
210
  def _fetch_spot():
211
- resp = self._client.get("https://api.binance.com/api/v3/trades", params={"symbol": symbol, "limit": min(limit, 1000)})
212
- resp.raise_for_status()
213
- return resp.json()
 
 
 
 
 
214
 
215
  try:
216
  data = await asyncio.to_thread(_fetch_spot)
 
 
217
  trades = [
218
  {
219
  "price": float(t["price"]),
 
207
 
208
  async def get_spot_trades(self, symbol: str, limit: int = 500) -> list[dict]:
209
  """Fetch spot trades from Binance Spot API for Spot CVD vs Futures CVD analysis."""
210
+ import re
211
+ clean_symbol = re.sub(r'^(1000000000|1000000|100000|10000|1000|k)', '', symbol, flags=re.IGNORECASE).upper()
212
+ symbols_to_try = [symbol]
213
+ if clean_symbol != symbol and clean_symbol.endswith("USDT"):
214
+ symbols_to_try.append(clean_symbol)
215
+
216
  def _fetch_spot():
217
+ for sym in symbols_to_try:
218
+ try:
219
+ resp = self._client.get("https://api.binance.com/api/v3/trades", params={"symbol": sym, "limit": min(limit, 1000)})
220
+ if resp.status_code == 200:
221
+ return resp.json()
222
+ except Exception:
223
+ pass
224
+ return []
225
 
226
  try:
227
  data = await asyncio.to_thread(_fetch_spot)
228
+ if not data:
229
+ return []
230
  trades = [
231
  {
232
  "price": float(t["price"]),
frontend/src/components/pairs/PairItem.tsx CHANGED
@@ -74,22 +74,30 @@ export function PairItem({ pair, signal, isSelected, onSelect }: PairItemProps)
74
  </button>
75
  </div>
76
 
77
- {/* Exchange availability */}
78
- <div className="flex items-center gap-3 pl-4">
79
- <span
80
- className={`text-[10px] flex items-center gap-1 ${
81
- pair.on_binance ? 'text-signal-long' : 'text-text-muted'
82
- }`}
83
- >
84
- {pair.on_binance ? '✓' : '○'} Binance
85
- </span>
86
- <span
87
- className={`text-[10px] flex items-center gap-1 ${
88
- pair.on_bybit ? 'text-signal-long' : 'text-text-muted'
89
- }`}
90
- >
91
- {pair.on_bybit ? '✓' : '○'} Bybit
92
- </span>
 
 
 
 
 
 
 
 
93
  </div>
94
  </div>
95
  );
 
74
  </button>
75
  </div>
76
 
77
+ {/* Exchange availability & Safety badge */}
78
+ <div className="flex items-center justify-between pl-4 text-[10px]">
79
+ <div className="flex items-center gap-2.5">
80
+ <span
81
+ className={`flex items-center gap-0.5 ${
82
+ pair.on_binance ? 'text-signal-long' : 'text-text-muted'
83
+ }`}
84
+ >
85
+ {pair.on_binance ? '✓' : '○'} Binance
86
+ </span>
87
+ <span
88
+ className={`flex items-center gap-0.5 ${
89
+ pair.on_bybit ? 'text-signal-long' : 'text-text-muted'
90
+ }`}
91
+ >
92
+ {pair.on_bybit ? '✓' : '○'} Bybit
93
+ </span>
94
+ </div>
95
+ {signal && signal.has_spot === true && (
96
+ <span className="text-[9px] font-mono text-emerald-400 font-medium">🛡️ Spot</span>
97
+ )}
98
+ {signal && signal.has_spot === false && (
99
+ <span className="text-[9px] font-mono text-amber-400 font-bold">⚠️ Perp</span>
100
+ )}
101
  </div>
102
  </div>
103
  );
frontend/src/components/signals/TopTradeBanner.tsx CHANGED
@@ -1,5 +1,5 @@
1
  import { useState, memo } from 'react';
2
- import { Flame, Copy, Check, ShieldCheck, Coffee, Zap, Target } from 'lucide-react';
3
  import { useToast } from '../ui/Toast';
4
  import type { Signal } from '../../types';
5
 
@@ -86,6 +86,18 @@ Forward Anticipation: ${topSignal.anticipation || levels?.anticipation || ''}`;
86
  <span className="text-[11px] font-mono text-text-secondary uppercase">
87
  TF: {topSignal.active_timeframe}
88
  </span>
 
 
 
 
 
 
 
 
 
 
 
 
89
  {isSqueeze && (
90
  <span className="px-2 py-0.5 rounded-md text-[10px] font-mono font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30 flex items-center gap-1 animate-pulse">
91
  <Zap size={11} />
 
1
  import { useState, memo } from 'react';
2
+ import { Flame, Copy, Check, ShieldCheck, Coffee, Zap, Target, AlertTriangle } from 'lucide-react';
3
  import { useToast } from '../ui/Toast';
4
  import type { Signal } from '../../types';
5
 
 
86
  <span className="text-[11px] font-mono text-text-secondary uppercase">
87
  TF: {topSignal.active_timeframe}
88
  </span>
89
+ {topSignal.has_spot === true && (
90
+ <span className="px-2 py-0.5 rounded-md text-[10px] font-mono font-bold bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 flex items-center gap-1">
91
+ <ShieldCheck size={11} className="text-emerald-400" />
92
+ 🛡️ AMAN (Ada Spot)
93
+ </span>
94
+ )}
95
+ {topSignal.has_spot === false && (
96
+ <span className="px-2 py-0.5 rounded-md text-[10px] font-mono font-bold bg-amber-500/20 text-amber-300 border border-amber-500/40 flex items-center gap-1">
97
+ <AlertTriangle size={11} className="text-amber-400" />
98
+ ⚠️ RAWAN (Perp Only)
99
+ </span>
100
+ )}
101
  {isSqueeze && (
102
  <span className="px-2 py-0.5 rounded-md text-[10px] font-mono font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30 flex items-center gap-1 animate-pulse">
103
  <Zap size={11} />