feat: 持仓监控数据库优先显示,修复开仓重复与同步前空白
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+24
-11
@@ -130,25 +130,32 @@
|
||||
riskBadge.className = 'badge ' + (data.risk_status.can_trade ? 'profit' : 'loss');
|
||||
}
|
||||
var rows = data.rows || [];
|
||||
var seenKeys = {};
|
||||
rows = rows.filter(function (row) {
|
||||
var k = row.key || ((row.symbol_code || '') + ':' + (row.direction || ''));
|
||||
if (seenKeys[k]) return false;
|
||||
seenKeys[k] = true;
|
||||
return true;
|
||||
});
|
||||
hasSlTpMonitoring = rows.some(function (row) {
|
||||
return row.stop_loss != null || row.take_profit != null;
|
||||
});
|
||||
updateSessionUi();
|
||||
savePosCache(data);
|
||||
positionsRendered = true;
|
||||
if (!connected) {
|
||||
if (connecting) {
|
||||
list.innerHTML = '<div class="empty-hint">CTP 连接中,请稍候…</div>';
|
||||
if (!rows.length) {
|
||||
if (!connected) {
|
||||
if (connecting) {
|
||||
list.innerHTML = '<div class="empty-hint">CTP 连接中,请稍候…</div>';
|
||||
return;
|
||||
}
|
||||
list.innerHTML = '<div class="empty-hint">CTP 未连接,正在尝试自动重连…</div>';
|
||||
tryAutoCtpReconnect();
|
||||
return;
|
||||
}
|
||||
list.innerHTML = '<div class="empty-hint">CTP 未连接,正在尝试自动重连…</div>';
|
||||
tryAutoCtpReconnect();
|
||||
return;
|
||||
}
|
||||
if (!rows.length) {
|
||||
var pendingOnly = data.pending_orders || [];
|
||||
if (pendingOnly.length) {
|
||||
list.innerHTML = '<div class="empty-hint" style="margin-bottom:.75rem">柜台暂无持仓</div>' +
|
||||
list.innerHTML = '<div class="empty-hint" style="margin-bottom:.75rem">暂无持仓</div>' +
|
||||
pendingOnly.map(function (p) {
|
||||
var dismissBtn = p.monitor_id ?
|
||||
'<button type="button" class="pos-dismiss-btn" data-monitor-id="' + p.monitor_id + '">取消</button>' : '';
|
||||
@@ -162,10 +169,13 @@
|
||||
}).join('');
|
||||
bindPendingDismiss(list);
|
||||
} else {
|
||||
list.innerHTML = '<div class="empty-hint">柜台暂无持仓。</div>';
|
||||
list.innerHTML = '<div class="empty-hint">暂无持仓。</div>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!connected) {
|
||||
tryAutoCtpReconnect();
|
||||
}
|
||||
list.innerHTML = rows.map(buildPosCard).join('');
|
||||
bindPendingDismiss(list);
|
||||
bindSlTpButtons(list);
|
||||
@@ -556,7 +566,9 @@
|
||||
'<div class="pos-card-head"><div><div class="title">' + row.symbol + ' <span class="badge dir">' + dirBadge + '</span></div>' +
|
||||
'<div class="text-muted" style="font-size:.72rem">' + (row.symbol_code || '') + '</div></div>' +
|
||||
actionBtns + '</div>' +
|
||||
'<div class="pos-card-meta">来源 <strong>' + (row.source_label || 'CTP') + '</strong> · 柜台浮盈' +
|
||||
'<div class="pos-card-meta">来源 <strong>' + (row.source_label || 'CTP') + '</strong>' +
|
||||
(row.sync_pending ? ' · <span class="text-muted">同步柜台中…</span>' : '') +
|
||||
' · 浮盈' +
|
||||
(slTpBtn ? ' · ' + slTpBtn : '') +
|
||||
(row.sl_order_active ? ' · <span class="text-profit">止损监控中</span>' : '') +
|
||||
(row.tp_order_active ? ' · <span class="text-profit">止盈监控中</span>' : '') +
|
||||
@@ -844,6 +856,7 @@
|
||||
if (cached) {
|
||||
applyPositionsData(cached);
|
||||
}
|
||||
pollPositions();
|
||||
connectPositionStream();
|
||||
connectRecommendStream();
|
||||
fetch('/api/recommend/list')
|
||||
|
||||
Reference in New Issue
Block a user