Logo van Broker Agnostic Adapter Interface

Broker Agnostic Adapter Interface

Community
HimanshuJ16
broker-agnostic-adapter-interface

Gebruik dit wanneer strateg code bij meerdere brokers moet werken en kiteconnect, alpaca-py of ibapi niet rechtstreeks mag importeren. Definieert een adaptercontract met Decimal-prijzen, getypeerde uitzonderingen en genormaliseerde orderstatussen voor verschillende handelsplatformen.

Overzicht

UitgeverHimanshuJ16
RepositoryAlgo-Trading-Skills
Skillnaambroker-agnostic-adapter-interface
Sterren
50
Forks
7
Meegeleverde bestanden
5
LicentieApache-2.0
Links
  • Instructies in Markdown

    Het model laadt het bestand SKILL.md alleen als dat nodig is. Dat kost dus alleen tokens als een verzoek daadwerkelijk bij de skill past.

  • Werkt met elk LLM

    AI-skills bestaan uit instructies in gewone Markdown, niet uit aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Meegeleverde bestanden: 5

    Scripts, sjablonen en referentiemateriaal die het model tijdens het werken kan lezen. De bestanden kunnen alleen worden gelezen en worden nooit uitgevoerd.

  • Open source

    Gepubliceerd door HimanshuJ16 op GitHub. Bekijk de bronbestanden voordat je de skill installeert.

Installatie

Installeer de AI-skill Broker Agnostic Adapter Interface in TypingMind om deze met elk LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map. De app leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-agnostic-adapter-interface
  4. Schakel de skill in voor elke chat waarin je de skill wilt kunnen gebruiken.
Plug-ins → Skills → Skill toevoegen → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

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-agnostic-adapter-interface .claude/skills/broker-agnostic-adapter-interface
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Broker Agnostic Adapter Interface in voor een chat naar keuze in TypingMind en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek bij de skill past, laadt het model zelf de volledige instructies. Je hoeft de skill nooit handmatig aan te roepen. Pas als het model de skill daadwerkelijk gebruikt, kost dat tokens.

Het model laadt Broker Agnostic Adapter Interface automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Broker Agnostic Adapter Interface niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

When to Use

Invoke this whenever building a trading platform or strategy engine intended to run across multiple brokers or venues. Coupling strategy code directly to broker SDKs (Zerodha kiteconnect, Alpaca alpaca-py, IBKR ibapi) fragments the codebase, leaks float imprecision into prices, and makes venue migration a rewrite. An abstract BaseBrokerAdapter with standardized models (OrderRequest, OrderResult, Position, AccountBalance) in Decimal isolates strategy code from broker API drift.

The two things this layer must get right, because everything downstream trusts it: the status normalization (does the strategy believe this order is live?) and the request validation (does a malformed order reach the venue?).

When NOT to Use

  • As a working broker client. scripts/broker_adapter.py defines the contract and ships simulated adapters that fabricate fills. It performs no network I/O, no auth, no rate limiting. Real adapters wrap real SDKs behind this interface.
  • As a single-broker abstraction. If you will only ever trade one venue, the indirection costs more than it saves; use the SDK directly and keep the enum normalization.
  • For anything the interface does not model. Bracket/OCO orders, order modification, multi-leg and options strategies, streaming order updates, and per-venue product types (Zerodha's MIS/CNC/NRML) are outside OrderRequest. Extend the model deliberately rather than smuggling them through a broker-specific side channel — that reintroduces the coupling this skill exists to remove.
  • As a substitute for idempotency or auth handling — see the Related Skills.

Prerequisites

  • Python abc for the interface and decimal.Decimal for all monetary values.
  • Each broker's documented status enumeration, not the four statuses you happened to see in testing. references/standards.md lists them with sources.
  • A typed exception hierarchy (BrokerAdapterError and subclasses) that every adapter maps its SDK errors into.
  • A registry key per broker, supplied by configuration.

Workflow

  1. Model the domain in Decimal, and enforce it at the boundary. _to_decimal accepts Decimal and int (exact) and rejects float with an explanatory error. A float that slips through survives every comparison and only fails much later, as a TypeError the first time it meets a Decimal in arithmetic — far from the code that introduced it.

  2. Validate the request on the base class, not in each adapter. _validate_request enforces symbol, enum types, finite positive quantity, and order-type/price consistency: LIMIT and STOP_LIMIT require a positive price, STOP and STOP_LIMIT require a positive stop price, and MARKET must not carry one. Putting it on the base class means a newly written adapter cannot forget it.

  3. Normalize status conservatively. normalize_status upper-cases and looks up _STATUS_MAP. An unmapped status returns OrderStatus.UNKNOWN and logs at ERROR — never PENDING. Handle UNKNOWN by re-querying or reconciling; it is neither live nor terminal, and OrderResult.is_terminal returns False for it. Treat its appearance as a defect report: the broker has a status your map does not know.

  4. Echo client_order_id on every OrderResult. Without it the caller cannot correlate a response to the request that produced it, and retry-safe submission is impossible.

  5. Register adapters explicitly; the factory registry starts empty. create() raises until you register a real adapter. The simulated adapters are not bound to production broker names by default — call register_simulated_adapters() to opt in for offline work. register() rejects any class that is not a BaseBrokerAdapter, so a bad wiring fails at startup rather than on the first order.

  6. Treat cancel_order as a request, not a cancellation. A True return means the broker accepted the cancellation request. The order can still fill in the race window. Confirm with get_order_status before releasing risk budget or reusing the ID.

Full step-by-step procedure with broker-specific detail: see references/workflows.md. Documented status sets per broker, with sources: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Defaulting an unrecognized status to PENDING. This is the worst default available: it asserts the order is live and working. Real terminal statuses get missed by hand-written maps — Zerodha's LAPSED, IBKR's ApiCancelled, Alpaca's done_for_day and replaced are all finished, and calling any of them PENDING leaves the strategy waiting on a dead order or re-sending one that already resolved.
  • Case-sensitive status lookup. IBKR returns mixed-case strings (PreSubmitted, ApiCancelled). A lookup that matches "Filled" but not "FILLED" sends the variant to the default branch — a filled order reported as still working.
  • Mapping only the statuses you saw in testing. Kite documents roughly a dozen order states and Alpaca a dozen more; the four obvious ones are not the contract.
  • Binding simulated adapters to production broker names. A factory that resolves config["broker"] to a mock reports every order FILLED at an invented price, with no error anywhere.
  • Falsy-checking a price. if request.price treats Decimal("0") as absent, so a zero limit price gets silently replaced by a default instead of rejected.
  • Floating point at the boundary. float cannot represent ordinary decimal prices and tick sizes exactly; construct Decimal(str(value)) where the value enters.
  • Leaky abstractions. Broker SDK exceptions, raw JSON, and — easy to miss — decimal.InvalidOperation from a NaN comparison must all be wrapped into BrokerAdapterError subclasses before crossing the adapter boundary.
  • Treating a cancel acknowledgement as a cancellation.
  • Mutating the shared registry from library code. It is process-wide class state; use reset() for test isolation.

Verification

  • Run the unit suite and confirm every test passes: python -m unittest discover -s skills/broker-agnostic-adapter-interface/scripts
  • For each adapter, assert an invented status string returns UNKNOWN, not PENDING. This is the highest-value single assertion in the suite.
  • Assert every status in the broker's documented enumeration maps to something, and that terminal broker states map to terminal OrderStatus values.
  • Assert case variants ("Filled", "FILLED", "filled") normalize identically.
  • Assert a float quantity or price is rejected, and that an int widens to Decimal losslessly.
  • Assert create() raises on an empty registry, and that register() refuses a class that does not implement BaseBrokerAdapter.
  • Place orders through every adapter and confirm filled_quantity, average_price and commission are all Decimal instances.

Related Skills

  • order-placement-idempotency
  • broker-api-idempotent-cancel-requests
  • headless-broker-auth-patterns
  • multi-broker-rate-limit-handling

Meegeleverde bestanden

Zolang de skill geladen is, leest het model deze bestanden als dat nodig is. Het model kan ze alleen lezen; ze worden nooit uitgevoerd.

Veelgestelde vragen

Wat doet de AI-skill Broker Agnostic Adapter Interface?

Gebruik dit wanneer strateg code bij meerdere brokers moet werken en kiteconnect, alpaca-py of ibapi niet rechtstreeks mag importeren. Definieert een adaptercontract met Decimal-prijzen, getypeerde uitzonderingen en genormaliseerde orderstatussen voor verschillende handelsplatformen.

Waarom Broker Agnostic Adapter Interface gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Broker Agnostic Adapter Interface bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model. Ook als je midden in een chat van model wisselt, blijft de skill werken. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek af te sluiten. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Broker Agnostic Adapter Interface in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-agnostic-adapter-interface. TypingMind leest het bestand SKILL.md, bundelt de bijbehorende bestanden en installeert het geheel als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Broker Agnostic Adapter Interface gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Broker Agnostic Adapter Interface gebruiken?

Zoveel als je wilt. Je kunt Broker Agnostic Adapter Interface gebruiken met elk model dat skills ondersteunt, zoals GPT, Claude, Gemini, Grok, DeepSeek, Mistral of Llama. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Broker Agnostic Adapter Interface gratis?

Ja. Deze skill is door HimanshuJ16 op GitHub gepubliceerd onder de licentie Apache-2.0. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. De skill volgt het open Agent Skills-formaat: het bestand SKILL.md bevat de naam en beschrijving van de skill. Daarnaast kan de skill scripts, sjablonen of referentiebestanden bevatten die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Bekijk alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇