🏠 天馬行空 首頁

少了 0.001 顆幣的死迴圈:幽靈庫存 Auto-Drop 逃生機制實戰

📅 2026-11-23 Quant Log 👁️ 載入中...
Trapped by 0.001 Coins: Solving Ghost Inventory Infinite Loops
這週的 Quant Log 我們回顧了一次發生在 9 月的「死迴圈」災難:當利潤觸達、觸發賣出,卻因為交易所的小數點進位偏差,導致庫存少了 0.001 顆幣。這個微小的誤差,竟然癱瘓了整個交易網格!

1. 災難還原:幽靈庫存的詛咒

在 2026-09-11 發生了一次嚴重故障:某個盈利的網格達到賣出條件,但因為四捨五入或手動干預,交易所的實際餘額略低於系統預期的 95%。機器人因此無法順利賣出,陷入了死迴圈,不斷重試並產生大量的報錯日誌,淹沒了 WebSync 和 LINE 的通知系統,同時也暫停了所有新的買入操作。

🚨 觸發點 (Trigger) 盈利網格觸發賣出閾值,但交易所實際餘額低於網格預期數量的 95%。

2. 逃生機制:Auto-Drop 與 95% 水位校驗

為了徹底解決這個問題,我們引入了 Auto-Drop(自動放棄) 機制與雙層檢查:

  • 95% 庫存檢查:在賣出前,檢查實際餘額。如果低於預期數量的 95%,自動將該網格標記為 error_closed(庫存不足),從迴圈中強制釋放。
  • API 錯誤 vs 餘額不足:區分單純的 API 連線失敗(此時回傳 None 並跳過該次 tick,不移動網格)與確實的低餘額情況。
  • 通知過濾:在 WebSync 防洗頻白名單中加入「庫存不足」過濾器,避免相同的報錯持續轟炸。

3. 本週交易數據追蹤 (2026-11-16 ~ 2026-11-23)

總買入次數 0
總賣出次數 0
V 型反轉次數 77
瀑布緩衝觸發 0

目前持倉格數:BTC 11 格、ETH 16 格、MAX 15 格。

In this week's Quant Log, we revisit an infinite loop disaster from September: a profitable grid hit the sell threshold, but an exchange rounding error left the balance 0.001 coins short. This tiny discrepancy paralyzed the entire trading grid!

1. The Disaster: Curse of the Ghost Inventory

On September 11, 2026, a critical failure occurred: a profitable lot hit its sell threshold, but the actual exchange balance was slightly under 95% of the expected lot quantity due to rounding or manual intervention. The bot couldn't sell and entered an infinite loop, retrying constantly. This froze new buys and flooded the WebSync and LINE notification channels with errors.

🚨 Trigger A profitable lot hit the sell threshold, but the actual exchange balance fell below 95% of the expected quantity.

2. The Escape Mechanism: Auto-Drop & 95% Check

To eliminate this issue, we introduced the Auto-Drop mechanism and a dual-layer check:

  • 95% Balance Check: Before selling, the bot checks the actual balance. If it's below 95%, it automatically marks the lot as error_closed (Inventory shortage), releasing it cleanly from the loop.
  • API Error vs. Low Balance: The bot now distinguishes between an API failure (returning None, skipping the tick without moving the grid level) and a confirmed low balance.
  • Notification Filter: Added an inventory-shortage filter to the WebSync anti-flood whitelist to prevent log spam.

3. Weekly Trading Stats (2026-11-16 ~ 2026-11-23)

Total Buys 0
Total Sells 0
V-Turns 77
Waterfall Buffers 0

Current open lots: BTC 11, ETH 16, MAX 15.

註:本文為軟體工程與自動化交易風控紀錄之技術分享,所有倉位與數據均已脫敏(僅呈現市價、百分比與格數),不構成任何投資建議。 Note: This is a technical engineering and risk-control log. Balances and account identifiers are omitted (showing market prices, percentages, and grid counts only). Not financial advice.