Hunting 'Ghost Positions': The F-160 Rule and Defensive Design in System State Reconciliation

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Hunting ‘Ghost Positions’: The F-160 Rule and Defensive Design in System State Reconciliation

追踪“幽灵仓位”:F-160 规则与系统状态对账中的防御性设计

It was 1:15 AM, and the trading system was running its routine midnight checks. Suddenly, the logs lit up with a series of critical warnings. The position_monitor had detected active, highly leveraged positions on the exchange—specifically, a 75x leveraged 1000PEPEUSDT long and a 20x leveraged ETHUSDT long. There was just one massive problem: our internal system had absolutely no record of opening them.

当时是凌晨 1:15,交易系统正在运行日常的午夜检查。突然,日志中弹出了一系列严重警告。仓位监控器(position_monitor)在交易所检测到了活跃的高杠杆仓位——具体来说,是一个 75 倍杠杆的 1000PEPEUSDT 多单和一个 20 倍杠杆的 ETHUSDT 多单。但有一个巨大的问题:我们的内部系统完全没有开仓记录。

In the high-stakes world of algorithmic crypto trading, these are known as “Ghost Positions.” If left unchecked, our AI trading engine would assume these were its own trades and attempt to apply automated Take Profit/Stop Loss (TP/SL) logic. The result? Catastrophic, unauthorized interventions on trades the system didn’t originate, potentially liquidating manual positions or triggering disastrous margin calls. This post-mortem explores how defensive state reconciliation and strict execution rules—specifically the F-160 Iron Rule—prevented a potential financial disaster, and the architectural philosophy that makes it possible.

在高风险的加密货币算法交易领域,这些被称为“幽灵仓位”。如果不加干预,我们的 AI 交易引擎会误以为这些是它自己的交易,并尝试应用自动止盈/止损(TP/SL)逻辑。结果会怎样?系统会对非自身发起的交易进行灾难性的、未经授权的干预,可能导致手动仓位被强平或触发灾难性的追加保证金通知。这篇事后分析探讨了防御性状态对账和严格的执行规则(特别是 F-160 铁律)如何防止了潜在的金融灾难,以及实现这一目标的架构哲学。

Background: The Illusion of Perfect Synchronization. In algorithmic trading, we operate under the assumption that the internal state (our database) and the exchange state (the broker’s reality) are perfectly synchronized. When the AI decides to open a trade, it sends an API request, records the OPEN state internally, and manages the lifecycle. However, in production environments, perfect synchronization is a myth. Exchange APIs experience latency, webhooks get dropped during network blips, and human operators occasionally log into the exchange’s web UI to manually adjust hedges or take speculative shots. When these external factors occur, the exchange state diverges from the internal ledger. If the system blindly trusts the exchange state, it will inevitably act on data it doesn’t fully understand.

背景:完美同步的幻觉。在算法交易中,我们的运作假设是内部状态(我们的数据库)与交易所状态(经纪商的现实)是完美同步的。当 AI 决定开仓时,它会发送 API 请求,在内部记录开仓状态,并管理其生命周期。然而,在生产环境中,完美同步是一个神话。交易所 API 会出现延迟,网络波动会导致 Webhook 丢失,人工操作员偶尔会登录交易所网页端手动调整对冲或进行投机交易。当这些外部因素发生时,交易所状态就会与内部账本产生偏差。如果系统盲目信任交易所状态,它必然会基于其无法完全理解的数据采取行动。

The Problem: The Anatomy of a Ghost Position. A “Ghost Position” is an active position on the exchange side that lacks a corresponding internal OPEN record in our algorithmic ledger. During a routine RECONCILE phase, our system compares the real-time exchange state against the internal ledger. Here is what the logs captured when the ghosts appeared: 2026-11-11 01:15:54,636 [WARNING] position_monitor: RECONCILE: Unrecorded position 牛来USDT LONG@0.0839 (10x) — treating as manual (no OPEN record). 2026-11-11 01:15:54,637 [WARNING] position_monitor: RECONCILE: Unrecorded position ETHUSDT LONG@2240.05 (20x) — treating as manual (no OPEN record). 2026-11-11 01:15:54,637 [WARNING] position_monitor: RECONCILE: Unrecorded position 1000PEPEUSDT LONG@0.0047 (75x) — treating as manual (no OPEN record).

问题:幽灵仓位的剖析。“幽灵仓位”是指交易所端存在活跃仓位,但在我们的算法账本中缺乏相应的内部开仓记录。在常规的对账(RECONCILE)阶段,我们的系统会将实时交易所状态与内部账本进行比对。以下是幽灵出现时日志捕获的内容:2026-11-11 01:15:54,636 [警告] position_monitor: RECONCILE: 未记录的仓位 牛来USDT LONG@0.0839 (10x) — 视为手动(无开仓记录)。2026-11-11 01:15:54,637 [警告] position_monitor: RECONCILE: 未记录的仓位 ETHUSDT LONG@2240.05 (20x) — 视为手动(无开仓记录)。2026-11-11 01:15:54,637 [警告] position_monitor: RECONCILE: 未记录的仓位 1000PEPEUSDT LONG@0.0047 (75x) — 视为手动(无开仓记录)。

These positions could exist for several reasons: Manual UI Trading: The operator manually opened a position via the exchange interface while the bot was running. API Desyncs: A network partition caused the bot’s order to fill on the exchange, but the internal database failed to record the OPEN event. External Interventions: A sub-account or external script modified the position. The danger is immediate. The AI’s execution engine sees an open position and naturally attempts to manage it. If it applies its automated TP/SL logic to a manually opened 75x leveraged meme coin position, it could prematurely close a winning manual trade, or worse, execute conflicting orders that violate the exchange’s margin requirements.

这些仓位存在的原因可能有几种:手动 UI 交易:操作员在机器人运行时通过交易所界面手动开仓。API 同步失败:网络分区导致机器人的订单在交易所成交,但内部数据库未能记录开仓事件。外部干预:子账户或外部脚本修改了仓位。危险是即时的。AI 的执行引擎看到一个开仓位,自然会尝试对其进行管理。如果它将自动止盈/止损逻辑应用于一个手动开仓的 75 倍杠杆 Meme 币仓位,可能会过早平掉一个盈利的手动交易,或者更糟的是,执行违反交易所保证金要求的冲突订单。

The Solution: Defensive Reconciliation & The F-160 Iron Rule. To prevent catastrophic automated interventions, we rely on a two-pronged defensive mechanism: Defensive Reconciliation and the F-160 Execution Guardrail. Defensive Reconciliation in the RECONCILE Phase: The position_monitor logic is designed to be inherently suspicious. When it compares the real-time exchange state against the internal ledger and finds a discrepancy, it does not guess. It does not attempt to “adopt” the position into the algorithmic strategy. Instead, it applies a critical design choice: flag the discrepancy as ‘manual’ with a safe default.

解决方案:防御性对账与 F-160 铁律。为了防止灾难性的自动干预,我们依赖于双重防御机制:防御性对账和 F-160 执行护栏。对账阶段的防御性对账:position_monitor 的逻辑设计为天生多疑。当它将实时交易所状态与内部账本进行比对并发现差异时,它不会进行猜测。它不会试图将该仓位“收养”进算法策略中。相反,它采用了一个关键的设计选择:将差异标记为“手动”,并使用一个安全默认值。

The F-160 Iron Rule Execution Guardrail: Flagging the position is only half the battle; we must also prevent the execution engine from acting on it. This is where the F-160 mechanism comes in. F-160 acts as a hard circuit breaker. When the system processes these flagged positions, F-160 explicitly checks if the position is in the approved manual list or if it has specific algorithmic markers (like CAT_ conditional orders). If it lacks these, F-160 triggers: 2026-11-11 01:15:54,637 [WARNING] position_monitor: F-160: ETHUSDT not in manual list and no CAT_ orders - treating as MANUAL (safe default).

F-160 铁律执行护栏:标记仓位只是成功了一半;我们还必须防止执行引擎对其采取行动。这就是 F-160 机制发挥作用的地方。F-160 充当了硬性断路器。当系统处理这些被标记的仓位时,F-160 会明确检查该仓位是否在批准的手动列表中,或者是否具有特定的算法标记(如 CAT_ 条件订单)。如果缺少这些,F-160 就会触发:2026-11-11 01:15:54,637 [警告] position_monitor: F-160: ETHUSDT 不在手动列表中且没有 CAT_ 订单 - 视为手动(安全默认值)。

Consequently, the execution engine applies the F-160 iron law, bypassing all automated TP/SL logic for these unregistered positions: “error”: “Manual position (unknown (F-160 safe default)) - skipped auto TP/SL per F-160 iron law” “error”: “Manual position (known manual) - skipped auto TP/SL per F-160 iron law”. The Result: The AI trading system successfully maintains strict isolation between its own algorithmic strategies and external/manual market activities. The ghost positions are safely ignored by the automated engine, preserving system stability and preventing disastrous automated overrides.

因此,执行引擎应用了 F-160 铁律,绕过了所有针对这些未注册仓位的自动止盈/止损逻辑:“错误”:“手动仓位(未知(F-160 安全默认值))- 根据 F-160 铁律跳过自动止盈/止损”,“错误”:“手动仓位(已知手动)- 根据 F-160 铁律跳过自动止盈/止损”。结果:AI 交易系统成功地在其自身的算法策略与外部/手动市场活动之间保持了严格的隔离。幽灵仓位被自动引擎安全地忽略,从而维护了系统稳定性并防止了灾难性的自动覆盖。

Technical Details: State Isolation Architecture. The F-160 rule is not just a standalone script; it is a manifestation of a deeper engineering principle: State Isolation Architecture. In our system, we strictly separate the intent of the algorithm from the reality of the exchange. The Internal Ledger is the Single Source of Truth for Actions: The algorithmic engine only reads from and writes to the internal database. If a trade is not explicitly recorded in the internal ledger with an OPEN status, the algorithmic engine is mathematically prohibited from executing management logic (TP/SL, trailing stops, scaling) on it. The Exchange State is a Read-Only Reality Check: The exchange API is used stri…

技术细节:状态隔离架构。F-160 规则不仅仅是一个独立的脚本;它是更深层工程原则的体现:状态隔离架构。在我们的系统中,我们严格将算法的意图与交易所的现实分离开来。内部账本是行动的唯一事实来源:算法引擎仅从内部数据库读取和写入。如果一笔交易没有在内部账本中明确记录为开仓状态,算法引擎在数学上被禁止对其执行管理逻辑(止盈/止损、追踪止损、加仓)。交易所状态仅作为只读的现实检查:交易所 API 被严格用于…