/algo-trading-skills:broker-agnostic-adapter-interfacefrom algo-trading-skills
Defines an abstract broker adapter contract with Decimal prices, typed exceptions, and normalized order status for multi-venue trading. Use when strategy code must run across multiple brokers without direct SDK imports.
Ships in algo-trading-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
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?).
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.OrderRequest. Extend the model deliberately
rather than smuggling them through a broker-specific side channel — that reintroduces
the coupling this skill exists to remove.abc for the interface and decimal.Decimal for all monetary values.references/standards.md lists them with sources.BrokerAdapterError and subclasses) that every adapter
maps its SDK errors into.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.
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.
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.
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.
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.
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: seereferences/standards.md. Printable pre-flight checklist: seeassets/checklist.md.
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.PreSubmitted,
ApiCancelled). A lookup that matches "Filled" but not "FILLED" sends the variant
to the default branch — a filled order reported as still working.config["broker"] to a mock reports every order FILLED at an invented price, with no
error anywhere.if request.price treats Decimal("0") as absent, so a
zero limit price gets silently replaced by a default instead of rejected.float cannot represent ordinary decimal prices
and tick sizes exactly; construct Decimal(str(value)) where the value enters.decimal.InvalidOperation from a NaN comparison must all be wrapped into
BrokerAdapterError subclasses before crossing the adapter boundary.reset() for test isolation.python -m unittest discover -s skills/broker-agnostic-adapter-interface/scriptsUNKNOWN, not PENDING.
This is the highest-value single assertion in the suite.OrderStatus values."Filled", "FILLED", "filled") normalize identically.float quantity or price is rejected, and that an int widens to Decimal
losslessly.create() raises on an empty registry, and that register() refuses a class
that does not implement BaseBrokerAdapter.filled_quantity, average_price and
commission are all Decimal instances.order-placement-idempotencybroker-api-idempotent-cancel-requestsheadless-broker-auth-patternsmulti-broker-rate-limit-handlingWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
36 skills in this plugin
/alpaca-paper-live-key-separationUse when a bot connects to the Alpaca Trading API and must never cross paper keys with the live endpoint; pins the base URL per environment, checks the key prefix, probes /v2/account and requires an explicit ALLOW_LIVE_TRADING flag./api-key-least-privilege-audit-toolUse before deploying a live bot, to audit existing broker API keys for scopes they do not need. Flags withdrawal, transfer and admin rights that turn a leaked execution key into theft./broker-account-margin-call-handlingUse when a bot trades a Reg T, portfolio or futures margin account and must act before the broker liquidates: tiered maintenance-margin warnings cross-checked against broker excess liquidity, initial-margin order gating and liquidity-aware de-leveraging.npx claudepluginhub himanshuj16/algo-trading-skills --plugin algo-trading-broker-integrationOther plugins' skills for the same job