Logo di Broker Account Margin Call Handling

Broker Account Margin Call Handling

Community
HimanshuJ16
broker-account-margin-call-handling

Usa questa skill quando un bot opera su un conto a margine Reg T, portfolio o futures e deve intervenire prima della liquidazione da parte del broker. Include avvisi a livelli sul margine di mantenimento, verificati rispetto alla liquidità disponibile comunicata dal broker, controlli sugli ordini in base al margine iniziale e riduzione della leva in base alla liquidità.

Add to TypingMind

Panoramica

Pubblicato daHimanshuJ16
RepositoryAlgo-Trading-Skills
Nome della skillbroker-account-margin-call-handling
Stelle
50
Fork
7
File inclusi
5
LicenzaApache-2.0
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • File inclusi: 5

    Script, template e riferimenti che il modello può leggere mentre lavora. I file sono di sola lettura e non vengono mai eseguiti.

  • Open source

    Pubblicata da HimanshuJ16 su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Broker Account Margin Call Handling in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-account-margin-call-handling
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Aggiungi skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella della skill nella directory delle skill di quell'agente.

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
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Broker Account Margin Call Handling in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Broker Account Margin Call Handling non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Broker Account Margin Call Handling non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

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

File inclusi

Il modello legge questi file quando servono, mentre la skill è caricata. Sono accessibili in sola lettura e non vengono mai eseguiti.

Domande frequenti

Cosa fa la skill IA Broker Account Margin Call Handling?

Usa questa skill quando un bot opera su un conto a margine Reg T, portfolio o futures e deve intervenire prima della liquidazione da parte del broker. Include avvisi a livelli sul margine di mantenimento, verificati rispetto alla liquidità disponibile comunicata dal broker, controlli sugli ordini in base al margine iniziale e riduzione della leva in base alla liquidità.

Perché usare Broker Account Margin Call Handling su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Broker Account Margin Call Handling è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che la skill smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Broker Account Margin Call Handling in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-account-margin-call-handling. TypingMind legge il file SKILL.md, include i file associati e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Broker Account Margin Call Handling?

Qualsiasi modello che colleghi a TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Broker Account Margin Call Handling?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Broker Account Margin Call Handling: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Broker Account Margin Call Handling è gratuita?

Sì. È pubblicata su GitHub da HimanshuJ16 con licenza Apache-2.0. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, template o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Elenco completo

Crea subito il tuo spazio di lavoro AI

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇