a
This commit is contained in:
parent
6e922d7921
commit
17e3d10d89
|
|
@ -269,7 +269,14 @@ async def ensure_all_positions_sltp(limit: int = Query(50, ge=1, le=200, descrip
|
||||||
for sym in symbols:
|
for sym in symbols:
|
||||||
try:
|
try:
|
||||||
res = await _ensure_exchange_sltp_for_symbol(sym)
|
res = await _ensure_exchange_sltp_for_symbol(sym)
|
||||||
results.append({"symbol": sym, "ok": True, "orders": res.get("orders")})
|
results.append(
|
||||||
|
{
|
||||||
|
"symbol": sym,
|
||||||
|
"ok": True,
|
||||||
|
"orders": res.get("orders"),
|
||||||
|
"open_protection_orders": res.get("open_protection_orders"),
|
||||||
|
}
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errors.append({"symbol": sym, "ok": False, "error": str(e)})
|
errors.append({"symbol": sym, "ok": False, "error": str(e)})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ const StatsDashboard = () => {
|
||||||
const [closingSymbol, setClosingSymbol] = useState(null)
|
const [closingSymbol, setClosingSymbol] = useState(null)
|
||||||
const [sltpSymbol, setSltpSymbol] = useState(null)
|
const [sltpSymbol, setSltpSymbol] = useState(null)
|
||||||
const [sltpAllBusy, setSltpAllBusy] = useState(false)
|
const [sltpAllBusy, setSltpAllBusy] = useState(false)
|
||||||
|
const [sltpDebugText, setSltpDebugText] = useState('')
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
const [tradingConfig, setTradingConfig] = useState(null)
|
const [tradingConfig, setTradingConfig] = useState(null)
|
||||||
|
|
||||||
|
|
@ -113,12 +114,14 @@ const StatsDashboard = () => {
|
||||||
}
|
}
|
||||||
setSltpSymbol(symbol)
|
setSltpSymbol(symbol)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
|
setSltpDebugText('')
|
||||||
try {
|
try {
|
||||||
const res = await api.ensurePositionSLTP(symbol)
|
const res = await api.ensurePositionSLTP(symbol)
|
||||||
const slId = res?.orders?.stop_market?.orderId
|
const slId = res?.orders?.stop_market?.orderId
|
||||||
const tpId = res?.orders?.take_profit_market?.orderId
|
const tpId = res?.orders?.take_profit_market?.orderId
|
||||||
const cnt = Array.isArray(res?.open_protection_orders) ? res.open_protection_orders.length : 0
|
const cnt = Array.isArray(res?.open_protection_orders) ? res.open_protection_orders.length : 0
|
||||||
setMessage(`${symbol} 已补挂保护单:SL=${slId || '-'} / TP=${tpId || '-'}(币安条件单可见,当前检测到保护单 ${cnt} 条)`)
|
setMessage(`${symbol} 已尝试补挂:SL=${slId || '-'} / TP=${tpId || '-'}(当前检测到保护单 ${cnt} 条)`)
|
||||||
|
setSltpDebugText(JSON.stringify(res || {}, null, 2))
|
||||||
await loadDashboard()
|
await loadDashboard()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setMessage(`补挂失败 ${symbol}: ${error.message || '未知错误'}`)
|
setMessage(`补挂失败 ${symbol}: ${error.message || '未知错误'}`)
|
||||||
|
|
@ -134,11 +137,20 @@ const StatsDashboard = () => {
|
||||||
}
|
}
|
||||||
setSltpAllBusy(true)
|
setSltpAllBusy(true)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
|
setSltpDebugText('')
|
||||||
try {
|
try {
|
||||||
const res = await api.ensureAllPositionsSLTP(50)
|
const res = await api.ensureAllPositionsSLTP(50)
|
||||||
const ok = res?.ok ?? 0
|
const ok = res?.ok ?? 0
|
||||||
const failed = res?.failed ?? 0
|
const failed = res?.failed ?? 0
|
||||||
setMessage(`一键补挂完成:成功 ${ok} / 失败 ${failed}(请在币安【条件单/止盈止损】里查看)`)
|
let openCnt = 0
|
||||||
|
try {
|
||||||
|
const arr = Array.isArray(res?.results) ? res.results : []
|
||||||
|
openCnt = arr.reduce((acc, it) => acc + (Array.isArray(it?.open_protection_orders) ? it.open_protection_orders.length : 0), 0)
|
||||||
|
} catch (e) {
|
||||||
|
openCnt = 0
|
||||||
|
}
|
||||||
|
setMessage(`一键补挂完成:成功 ${ok} / 失败 ${failed}(检测到保护单 ${openCnt} 条)`)
|
||||||
|
setSltpDebugText(JSON.stringify(res || {}, null, 2))
|
||||||
await loadDashboard()
|
await loadDashboard()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setMessage(`一键补挂失败: ${error.message || '未知错误'}`)
|
setMessage(`一键补挂失败: ${error.message || '未知错误'}`)
|
||||||
|
|
@ -227,6 +239,14 @@ const StatsDashboard = () => {
|
||||||
{message && (
|
{message && (
|
||||||
<div className={`message ${message.includes('失败') || message.includes('错误') ? 'error' : 'success'}`}>
|
<div className={`message ${message.includes('失败') || message.includes('错误') ? 'error' : 'success'}`}>
|
||||||
{message}
|
{message}
|
||||||
|
{sltpDebugText ? (
|
||||||
|
<details style={{ marginTop: '8px' }}>
|
||||||
|
<summary style={{ cursor: 'pointer' }}>查看补挂返回详情(用于排查)</summary>
|
||||||
|
<pre style={{ marginTop: '8px', whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontSize: '12px' }}>
|
||||||
|
{sltpDebugText}
|
||||||
|
</pre>
|
||||||
|
</details>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user