Skip to content

Commit 9000a1b

Browse files
committed
fix(mobile): preserve runtime errors and explain rebalance replay
Signed-off-by: TIANHE <[email protected]>
1 parent 959a249 commit 9000a1b

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎src/locales/strategy-runtime.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export default {
22
"zh-CN": {
3+
"strategyV2.rebalanceReplaySkipped": "本次调仓已有记录,已跳过重复提交;已有订单继续对账。如上次执行中断,请核查尚未入队的部分。",
34
"strategyRuntime.fillContractMetadataUnavailable": "合约规格暂不可用,成交入账将重试,不会猜测成交数量。",
45
"strategyRuntime.unsupportedFillContract": "当前入账模型不支持此合约单位。",
56
"strategyRuntime.invalidFillQuantity": "交易所成交数量无效,已暂缓入账。",
@@ -70,6 +71,7 @@ export default {
7071
"strategyV2.commandStatusUnavailable": "暂时无法确认暂停指令的最终状态,请刷新后核查。"
7172
},
7273
"zh-TW": {
74+
"strategyV2.rebalanceReplaySkipped": "本次調倉已有記錄,已跳過重複提交;已有訂單繼續對帳。如上次執行中斷,請核查尚未入隊的部分。",
7375
"strategyRuntime.fillContractMetadataUnavailable": "合約規格暫不可用,成交入帳將重試,不會猜測成交數量。",
7476
"strategyRuntime.unsupportedFillContract": "目前入帳模型不支援此合約單位。",
7577
"strategyRuntime.invalidFillQuantity": "交易所成交數量無效,已暫緩入帳。",
@@ -140,6 +142,7 @@ export default {
140142
"strategyV2.commandStatusUnavailable": "暫時無法確認暫停指令的最終狀態,請重新整理後核查。"
141143
},
142144
"en-US": {
145+
"strategyV2.rebalanceReplaySkipped": "This rebalance is already recorded; duplicate submission was skipped. Existing orders will continue reconciliation. If the previous attempt was interrupted, review any unqueued legs.",
143146
"strategyV2.dualDirectionHedgeModeRequired": "Hedge-leg or neutral strategies require hedge mode on the exchange account.",
144147
"strategyV2.oneWayPositionModeRequired": "This strategy requires one-way mode on the exchange account.",
145148
"strategyV2.positionModeDetail.binanceOneWay": "Binance Futures currently reports One-way Mode. Change the account to Hedge Mode, then start the strategy again.",
@@ -210,6 +213,7 @@ export default {
210213
"strategyV2.commandStatusUnavailable": "The final pause status could not be confirmed. Refresh and verify the strategy state."
211214
},
212215
"ja-JP": {
216+
"strategyV2.rebalanceReplaySkipped": "このリバランスは記録済みのため、重複送信をスキップしました。既存注文の照合は継続します。前回の処理が中断された場合は、未登録の注文を確認してください。",
213217
"strategyV2.dualDirectionHedgeModeRequired": "両建てまたは中立ストラテジーでは、取引所口座をヘッジモードにする必要があります。",
214218
"strategyV2.oneWayPositionModeRequired": "このストラテジーでは、取引所口座をワンウェイモードにする必要があります。",
215219
"strategyV2.positionModeDetail.binanceOneWay": "Binance 先物口座は現在ワンウェイモードです。ヘッジモードに切り替えてから再起動してください。",
@@ -280,6 +284,7 @@ export default {
280284
"strategyV2.commandStatusUnavailable": "一時停止の最終状態を確認できません。更新して状態を確認してください。"
281285
},
282286
"ko-KR": {
287+
"strategyV2.rebalanceReplaySkipped": "이미 기록된 리밸런싱이므로 중복 제출을 건너뛰었습니다. 기존 주문 대조는 계속됩니다. 이전 실행이 중단됐다면 대기열에 등록되지 않은 주문을 확인하세요.",
283288
"strategyV2.dualDirectionHedgeModeRequired": "양방향 또는 중립 전략은 거래소 계정의 헤지 모드가 필요합니다.",
284289
"strategyV2.oneWayPositionModeRequired": "이 전략은 거래소 계정의 단방향 모드가 필요합니다.",
285290
"strategyV2.positionModeDetail.binanceOneWay": "Binance 선물 계정이 현재 단방향 모드입니다. 헤지 모드로 전환한 후 전략을 다시 시작하세요.",

‎src/utils/strategyLogs.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ export const translateStrategyRuntimeMessage = (message, translate, exchangeErro
8686
match = text.match(/^Exchange order failed \(([^)]+)\):/i)
8787
if (match) return localize('trading-assistant.logs.message.exchangeOrderFailed', { context: match[1] }) || text
8888

89-
if (/^Runtime cycle failed:/i.test(text)) {
90-
return localize('trading-assistant.logs.message.runtimeCycleFailed') || text
89+
match = text.match(/^Runtime cycle failed:\s*([\s\S]*)/i)
90+
if (match) {
91+
const summary = localize('trading-assistant.logs.message.runtimeCycleFailed')
92+
return summary ? `${summary} ${match[1]}`.trim() : text
9193
}
9294

9395
match = text.match(/^Order queued:\s*(\w+)\s+(\S+)\s+quantity=([^\s]+)[\s\S]*?pending_id=([^\s]+)/i)

‎tests/unit/strategy-log-localization.test.mjs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ import test from 'node:test'
44
import messages from '../../src/locales/strategy-runtime.js'
55
import { translateStrategyRuntimeMessage } from '../../src/utils/strategyLogs.js'
66

7+
test('runtime failures retain the actual cause and replay notices are localized', () => {
8+
const key = 'strategyV2.rebalanceReplaySkipped'
9+
for (const locale of Object.keys(messages)) {
10+
const translate = value => messages[locale][value] || value
11+
const raw = 'Runtime cycle failed: strategyV2.rebalanceBatchClosed'
12+
assert.match(translateStrategyRuntimeMessage(raw, translate), /strategyV2.rebalanceBatchClosed/)
13+
const multiline = 'Runtime cycle failed: example error\ncontext detail'
14+
assert.match(translateStrategyRuntimeMessage(multiline, translate), /example error\ncontext detail/)
15+
assert.equal(translateStrategyRuntimeMessage(raw, value => value), raw)
16+
assert.ok(messages[locale][key])
17+
const replay = translateStrategyRuntimeMessage(`${key}:2026-11-25T14:35:49Z`, translate)
18+
assert.ok(replay.includes(messages[locale][key]))
19+
assert.ok(replay.includes('2026-11-25T14:35:49Z'))
20+
}
21+
})
22+
723
const render = (locale, message) => translateStrategyRuntimeMessage(message, (key, params = {}) => {
824
let value = messages[locale][key] || key
925
for (const [name, replacement] of Object.entries(params)) {

0 commit comments

Comments
 (0)