Broker Account Margin Call Handling 标志

Broker Account Margin Call Handling

社区
HimanshuJ16
broker-account-margin-call-handling

当机器人交易 Reg T、投资组合保证金或期货保证金账户,且必须在经纪商强制平仓前采取行动时使用:分级维护保证金预警需与经纪商超额流动性交叉核对,并包括初始保证金订单门控和考虑流动性的去杠杆操作。

Add to TypingMind

概览

发布者HimanshuJ16
代码仓库Algo-Trading-Skills
技能名称broker-account-margin-call-handling
星标数
50
复刻数
7
附带文件
5
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 5 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 HimanshuJ16 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Broker Account Margin Call Handling AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-account-margin-call-handling
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/broker-account-margin-call-handling .claude/skills/broker-account-margin-call-handling
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Broker Account Margin Call Handling,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Broker Account Margin Call Handling。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Broker Account Margin Call Handling 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

When to Use

Invoke this whenever an algorithmic trading bot operates on a margin account (Reg T, Portfolio Margin, or futures margin). When adverse market moves push maintenance margin requirements toward or past account equity, brokers liquidate positions at market prices, and they choose which ones. Acting first — cancelling resting orders, blocking new leverage, and unwinding on your own schedule with liquidity limits — is the difference between a controlled reduction and a forced one.

Use it to run three gates: a tiered house ratio as early warning, a broker-cushion check that catches deficiency the house ratio can miss, and a pre-trade veto on orders that would consume margin you do not have.

When NOT to Use

  • As a substitute for the broker's own numbers. The engine grades a snapshot you supply. If your feed is stale, the grade is stale. Poll excess_liquidity and available_funds from the broker; do not derive them from NLV.
  • As a guaranteed way to beat the broker to liquidation. IBKR does not make margin calls — it liquidates in real time, without prior notice, and may do so without the account ever displaying a margin warning. If you are already at BREACH you may have no window at all. The pre-breach tiers are where this skill earns its keep.
  • To size liquidations under Portfolio Margin or SPAN without re-pricing. The planner assumes margin is separable per position. Under portfolio-level regimes, closing one leg of a hedge can raise total margin — see Workflow step 5.
  • On a cash account, or for exchange margin-shortfall penalty accounting, which is a separate settlement-side concern.

Prerequisites

  • Broker real-time account data: net_liquidation_value, initial_margin, maintenance_margin, and critically excess_liquidity and available_funds.
  • A pre-trade margin impact source. Estimating it is the weak link — get it from the broker. At IBKR that is an Order.whatIf = true submission, whose OrderState returns initMarginChange and maintMarginChange.
  • An open-order cancellation interface.
  • Per-position average_daily_volume. It is a required field, not an optional one: it caps how much of a position the plan will sell, and a guessed value defeats the cap.
  • An execution path for liquidation slices (TWAP/VWAP or equivalent).

Workflow

  1. Evaluate account health with evaluate_margin_health(snapshot). It escalates on the worse of two signals:

    • the house ratio $M = \text{maintenance margin} / \text{NLV}$, against your configured tiers, and
    • excess_liquidity < 0, the broker's own cushion, which is authoritative. Unusable input (NaN, infinity, negative margin) raises MarginDataError rather than grading the account. A margin engine that reports NORMAL because its feed broke is worse than one that stops.
  2. Act on the tier. Defaults are house policy, not regulation — set them for your book:

    • NORMAL ($M < 0.85$): trade normally.
    • WARNING ($0.85 \le M < 0.95$): block new leverage-increasing orders; alert.
    • CRITICAL ($0.95 \le M < 1.0$): cancel all resting orders to release reserved margin.
    • BREACH ($M \ge 1.0$, or negative excess liquidity): de-leverage now. For calibration, IBKR's own warning fires at roughly a 90.9% maintenance/ELV ratio, between the 85% and 95% defaults.
  3. Handle non-positive equity as a different problem. If NLV $\le 0$ the ratio is undefined — the engine returns math.inf and the action HALT_AND_ESCALATE rather than DE_LEVERAGE_IMMEDIATELY. There is no target margin to de-leverage toward against non-positive equity; stop trading and involve a human.

  4. Gate every new order through guard_new_order(snapshot, margin_impact, initial_margin_impact=...). Pass initial_margin_impact whenever you have it: new positions are opened against initial margin (Reg T requires 50% on a long margin equity purchase) not maintenance margin (FINRA 4210's 25% minimum), so a maintenance-only projection is the weaker constraint and can pass an order the broker refuses. The guard returns True or raises — it never returns False, so treat any exception as a hard veto.

  5. Plan de-leveraging with plan_deleveraging(snapshot, positions), which orders by short-option tail risk, then margin density, then liquidity, and caps each slice at max_participation_rate of ADV. Then re-price the plan before acting on it if you are on Portfolio Margin or SPAN — the planner's linear "units × margin per unit" model does not hold when margin is computed on portfolio-level stressed loss, and unwinding a hedge leg can increase the requirement. Send each slice through the broker's own pre-trade check first.

  6. Expect the plan to be incomplete under illiquidity. The ADV cap can leave the plan short of the required reduction. That is the intended trade-off — dumping the position would crush its price, lower NLV and trigger a second deficiency — but it means you must check whether the plan actually clears the deficit and escalate when it does not.

Full step-by-step procedure with broker-specific detail: see references/workflows.md. Broker triggers, cushion definitions and regulatory reference points: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Trusting the house ratio alone. maintenance_margin / NLV uses NLV; the broker's cushion uses Equity with Loan Value, which excludes non-margin-eligible value and can be much lower. An account can read 70% and healthy while excess_liquidity is already negative and liquidation is underway.
  • Letting NaN through a threshold chain. Every comparison against NaN is False, so a NaN ratio falls past >= breach, >= critical and >= warning into the healthy branch. A broken feed must fail closed.
  • Checking new orders against maintenance margin. Positions are opened against initial margin, which is roughly double under Reg T.
  • Flooring NLV to avoid dividing by zero. It manufactures a finite ratio from an undefined one and, if the deficit is computed from the floored value, understates the deficit by exactly the amount of negative equity.
  • Exempting "de-leveraging" orders without checking they de-leverage. A bypass flag that is trusted unconditionally lets a margin-increasing order through every gate.
  • Unordered thresholds. Setting warning above critical makes the WARNING tier unreachable — the account jumps straight to CRITICAL and the early gate never fires.
  • Passive waiting for broker liquidation, taking market-order slippage on positions someone else chose.
  • Illiquidity spirals: dumping an illiquid asset at once, crushing the bid, lowering NLV, and triggering a secondary call.
  • Ignoring tail risk: unwinding long equity first while naked short options stay open through a volatility spike.
  • Ignoring the clock. Where the broker force-closes intraday products on a schedule (Zerodha squares off MIS positions around 15:20 IST), being margin-healthy is not enough.

Verification

  • Run the unit suite and confirm every test passes: python -m unittest discover -s skills/broker-account-margin-call-handling/scripts
  • Feed a snapshot with a healthy ratio but negative excess_liquidity and confirm the state is MARGIN_CALL_BREACH with broker_deficiency set — this is the failure mode most likely to be missed in production.
  • Feed NaN in each snapshot field in turn and confirm MarginDataError every time; a NORMAL result from any of them is a fail-open bug.
  • Check each tier at its exact boundary (85.0%, 95.0%, 100.0%), not just mid-band.
  • Submit a snapshot with $M = 0.88$ and confirm WARNING.
  • Submit an order whose initial_margin_impact exceeds available_funds and confirm the veto, even when the maintenance projection alone would have passed.
  • Replay a historical drawdown that actually breached, and confirm the tiers would have fired early enough to matter given your broker's liquidation behaviour.

Related Skills

  • kill-switch-and-drawdown-circuit-breakers
  • options-margin-span-calculation-global
  • correlation-aware-exposure-limits
  • margin-utilization-circuit-breaker

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Broker Account Margin Call Handling AI 技能有什么作用?

当机器人交易 Reg T、投资组合保证金或期货保证金账户,且必须在经纪商强制平仓前采取行动时使用:分级维护保证金预警需与经纪商超额流动性交叉核对,并包括初始保证金订单门控和考虑流动性的去杠杆操作。

为什么在 TypingMind 中使用 Broker Account Margin Call Handling?

因为您只需安装一次,就能搭配任何模型使用。Broker Account Margin Call Handling 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Broker Account Margin Call Handling?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-account-margin-call-handling。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Broker Account Margin Call Handling?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Broker Account Margin Call Handling 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Broker Account Margin Call Handling 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Broker Account Margin Call Handling AI 技能免费吗?

是的。HimanshuJ16 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇