Skip to content

Commit 94891c7

Browse files
v3.0.1
Signed-off-by: Dinger <quantdinger@gmail.com>
1 parent 0923331 commit 94891c7

136 files changed

Lines changed: 2276 additions & 382 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎backend_api_python/app/config/api_keys.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ def FINNHUB_API_KEY(cls):
1212
from app.utils.config_loader import load_addon_config
1313
val = load_addon_config().get('finnhub', {}).get('api_key')
1414
return val if val else os.getenv('FINNHUB_API_KEY', '')
15+
16+
@property
17+
def COINGLASS_API_KEY(cls):
18+
from app.utils.config_loader import load_addon_config
19+
val = load_addon_config().get('coinglass', {}).get('api_key')
20+
return val if val else os.getenv('COINGLASS_API_KEY', '')
21+
22+
@property
23+
def CRYPTOQUANT_API_KEY(cls):
24+
from app.utils.config_loader import load_addon_config
25+
val = load_addon_config().get('cryptoquant', {}).get('api_key')
26+
return val if val else os.getenv('CRYPTOQUANT_API_KEY', '')
1527

1628
@property
1729
def TIINGO_API_KEY(cls):

‎backend_api_python/app/routes/dashboard.py‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ def _as_list(value: Any) -> List[str]:
8484
return []
8585

8686

87+
def _is_bot_strategy(row: Dict[str, Any]) -> bool:
88+
try:
89+
mode = str((row or {}).get("strategy_mode") or "").strip().lower()
90+
return mode == "bot"
91+
except Exception:
92+
return False
93+
94+
8795
def _calc_unrealized_pnl(side: str, entry_price: float, current_price: float, size: float) -> float:
8896
try:
8997
ep = float(entry_price or 0.0)
@@ -310,7 +318,7 @@ def summary():
310318
cur = db.cursor()
311319
cur.execute(
312320
"""
313-
SELECT id, strategy_name, strategy_type, status, initial_capital, trading_config
321+
SELECT id, strategy_name, strategy_type, status, initial_capital, trading_config, strategy_mode
314322
FROM qd_strategies_trading
315323
WHERE user_id = ?
316324
""",
@@ -319,6 +327,7 @@ def summary():
319327
strategies = cur.fetchall() or []
320328
cur.close()
321329

330+
strategies = [s for s in strategies if not _is_bot_strategy(s)]
322331
running = [s for s in strategies if (s.get("status") or "").strip().lower() == "running"]
323332
indicator_strategy_count = len([s for s in running if (s.get("strategy_type") or "") == "IndicatorStrategy"])
324333

@@ -346,11 +355,13 @@ def _truthy(v: Any) -> bool:
346355
"""
347356
SELECT p.*, s.strategy_name, s.initial_capital, s.leverage, s.market_type
348357
FROM qd_strategy_positions p
349-
LEFT JOIN qd_strategies_trading s ON s.id = p.strategy_id
358+
INNER JOIN qd_strategies_trading s ON s.id = p.strategy_id
350359
WHERE p.user_id = ?
360+
AND s.user_id = ?
361+
AND COALESCE(LOWER(TRIM(s.strategy_mode)), 'signal') <> 'bot'
351362
ORDER BY p.updated_at DESC
352363
""",
353-
(user_id,)
364+
(user_id, user_id)
354365
)
355366
rows = cur.fetchall() or []
356367
cur.close()
@@ -385,7 +396,17 @@ def _truthy(v: Any) -> bool:
385396
# Also compute all-time trade count for dashboard top cards.
386397
with get_db_connection() as db:
387398
cur = db.cursor()
388-
cur.execute("SELECT COUNT(1) AS cnt FROM qd_strategy_trades WHERE user_id = ?", (user_id,))
399+
cur.execute(
400+
"""
401+
SELECT COUNT(1) AS cnt
402+
FROM qd_strategy_trades t
403+
INNER JOIN qd_strategies_trading s ON s.id = t.strategy_id
404+
WHERE t.user_id = ?
405+
AND s.user_id = ?
406+
AND COALESCE(LOWER(TRIM(s.strategy_mode)), 'signal') <> 'bot'
407+
""",
408+
(user_id, user_id)
409+
)
389410
total_trades_all = int((cur.fetchone() or {}).get("cnt") or 0)
390411
cur.close()
391412

@@ -395,12 +416,14 @@ def _truthy(v: Any) -> bool:
395416
"""
396417
SELECT t.*, s.strategy_name
397418
FROM qd_strategy_trades t
398-
LEFT JOIN qd_strategies_trading s ON s.id = t.strategy_id
419+
INNER JOIN qd_strategies_trading s ON s.id = t.strategy_id
399420
WHERE t.user_id = ?
421+
AND s.user_id = ?
422+
AND COALESCE(LOWER(TRIM(s.strategy_mode)), 'signal') <> 'bot'
400423
ORDER BY t.created_at DESC
401424
LIMIT 500
402425
""",
403-
(user_id,)
426+
(user_id, user_id)
404427
)
405428
recent_trades_raw = cur.fetchall() or []
406429
cur.close()

0 commit comments

Comments
 (0)