fix: dashboard improvements - remove AI strategy count, fix pie chart, fix position user_id
This commit is contained in:
@@ -529,10 +529,19 @@ class PendingOrderWorker:
|
|||||||
(float(u["size"]), float(u["entry_price"]), int(u["id"]))
|
(float(u["size"]), float(u["entry_price"]), int(u["id"]))
|
||||||
)
|
)
|
||||||
for ins in to_insert:
|
for ins in to_insert:
|
||||||
|
# Get user_id from strategy
|
||||||
|
ins_user_id = 1
|
||||||
|
try:
|
||||||
|
cur.execute("SELECT user_id FROM qd_strategies_trading WHERE id = %s", (int(ins["strategy_id"]),))
|
||||||
|
strategy_row = cur.fetchone()
|
||||||
|
if strategy_row and strategy_row.get("user_id"):
|
||||||
|
ins_user_id = int(strategy_row["user_id"])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""INSERT INTO qd_strategy_positions (user_id, strategy_id, symbol, side, size, entry_price, updated_at)
|
"""INSERT INTO qd_strategy_positions (user_id, strategy_id, symbol, side, size, entry_price, updated_at)
|
||||||
VALUES (%s, %s, %s, %s, %s, %s, NOW())""",
|
VALUES (%s, %s, %s, %s, %s, %s, NOW())""",
|
||||||
(1, int(ins["strategy_id"]), str(ins["symbol"]), str(ins["side"]), float(ins["size"]), float(ins["entry_price"]))
|
(ins_user_id, int(ins["strategy_id"]), str(ins["symbol"]), str(ins["side"]), float(ins["size"]), float(ins["entry_price"]))
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|||||||
@@ -132,13 +132,10 @@
|
|||||||
<span class="kpi-label">{{ $t('dashboard.runningStrategies') || '运行中策略' }}</span>
|
<span class="kpi-label">{{ $t('dashboard.runningStrategies') || '运行中策略' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="kpi-value">
|
<div class="kpi-value">
|
||||||
<span class="amount">{{ summary.indicator_strategy_count + summary.ai_strategy_count }}</span>
|
<span class="amount">{{ summary.indicator_strategy_count }}</span>
|
||||||
<span class="unit">{{ $t('dashboard.unit.strategies') }}</span>
|
<span class="unit">{{ $t('dashboard.unit.strategies') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="kpi-sub">
|
<div class="kpi-sub">
|
||||||
<span class="highlight">{{ summary.ai_strategy_count }}</span>
|
|
||||||
<span class="label"> AI</span>
|
|
||||||
<span class="divider">·</span>
|
|
||||||
<span class="highlight">{{ summary.indicator_strategy_count }}</span>
|
<span class="highlight">{{ summary.indicator_strategy_count }}</span>
|
||||||
<span class="label"> {{ $t('dashboard.label.indicator') }}</span>
|
<span class="label"> {{ $t('dashboard.label.indicator') }}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -1044,14 +1041,30 @@ export default {
|
|||||||
if (!chartDom) return
|
if (!chartDom) return
|
||||||
this.pieChart = echarts.init(chartDom)
|
this.pieChart = echarts.init(chartDom)
|
||||||
|
|
||||||
|
// Use strategy_stats for pie chart data (shows all strategies, not just those with positions)
|
||||||
|
const stats = Array.isArray(this.summary.strategy_stats) ? this.summary.strategy_stats : []
|
||||||
const raw = Array.isArray(this.summary.strategy_pnl_chart) ? this.summary.strategy_pnl_chart : []
|
const raw = Array.isArray(this.summary.strategy_pnl_chart) ? this.summary.strategy_pnl_chart : []
|
||||||
const data = raw
|
|
||||||
.map(it => {
|
// Prefer strategy_stats if available, fallback to strategy_pnl_chart
|
||||||
const name = (it && it.name) ? String(it.name) : '-'
|
let data = []
|
||||||
const val = Number(it && it.value ? it.value : 0)
|
if (stats.length > 0) {
|
||||||
return { name, value: Math.abs(val), signedValue: val }
|
data = stats.map(it => {
|
||||||
})
|
const name = (it && it.strategy_name) ? String(it.strategy_name) : '-'
|
||||||
.filter(it => it.value > 0)
|
const val = Number(it && it.total_pnl ? it.total_pnl : 0)
|
||||||
|
const trades = Number(it && it.total_trades ? it.total_trades : 0)
|
||||||
|
// Use trades count as value if no PnL, so at least we show the distribution
|
||||||
|
const displayVal = val !== 0 ? Math.abs(val) : trades
|
||||||
|
return { name, value: displayVal, signedValue: val, trades }
|
||||||
|
}).filter(it => it.value > 0)
|
||||||
|
} else {
|
||||||
|
data = raw
|
||||||
|
.map(it => {
|
||||||
|
const name = (it && it.name) ? String(it.name) : '-'
|
||||||
|
const val = Number(it && it.value ? it.value : 0)
|
||||||
|
return { name, value: Math.abs(val), signedValue: val }
|
||||||
|
})
|
||||||
|
.filter(it => it.value > 0)
|
||||||
|
}
|
||||||
|
|
||||||
const isDark = this.isDarkTheme
|
const isDark = this.isDarkTheme
|
||||||
const textColor = isDark ? '#9ca3af' : '#6b7280'
|
const textColor = isDark ? '#9ca3af' : '#6b7280'
|
||||||
|
|||||||
Reference in New Issue
Block a user