/algo-trading-skills:multi-broker-consolidated-position-viewfrom algo-trading-skills
Normalizes symbols, converts currencies, and nets long/short holdings across multiple brokers and exchanges to reconcile positions and P&L against your own ledger.
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 skill whenever a strategy distributes execution across multiple brokerage accounts or exchanges (e.g. US equities on IBKR and Alpaca, crypto on Binance). Isolated per-broker position views create blind spots in gross exposure and risk limits. This skill normalizes broker-specific symbol formats, converts multi-currency market values into a single base currency, nets long/short holdings across brokers, and audits position discrepancies against the strategy's own target ledger.
It is the normalization layer: cross-account-aggregate-risk-view explicitly delegates FX conversion, broker-symbol normalization, and multi-currency valuation to this skill and consumes canonical symbols and base-currency values from it. Numbers produced here therefore end up inside firm-wide gross-market-value caps, so this module fails closed rather than emitting a plausible-looking wrong figure.
weighted_avg_cost_base is an indicative net basis blended from brokers that compute cost basis under different rules, and it is undefined for a flat net position. Use fifo-vs-specific-lot-tax-accounting-methods and cross-strategy-tax-lot-optimization for anything an accountant or a tax authority will read.cross-account-aggregate-risk-view (firm-wide caps) or margin-utilization-circuit-breaker.is_internally_offset); the execution-side fix belongs to multi-order-netting-before-routing.options-greeks-real-time-portfolio-aggregation.broker_name, broker_symbol, signed quantity, average_cost, current_price, ISO 4217 currency, and contract_multiplier for anything that is not cash equity or spot).avgCost does for derivatives; its avgPrice does not).Ingest Raw Broker Positions:
RawBrokerPosition per leg. Quantities are signed — negative is short, matching IBKR, Alpaca qty, and Binance positionAmt. Validation happens on construction, so a NaN price or a malformed currency code raises here rather than poisoning an aggregate.contract_multiplier is mandatory and cannot be inferred from the symbol. A standard OCC equity option covers 100 shares; corporate actions can leave an adjusted contract delivering something other than 100 shares while keeping a 100 premium multiplier. Read the multiplier from the contract definition, never from the ticker.average_cost_includes_multiplier=True if so. Getting this backwards on a 50× futures contract inflates cost basis 50-fold and reports a large loss on a winning position.Normalize Symbols:
broker_symbol → canonical symbol.strict_symbol_mapping=True so it raises. The default fallback (upper-case the raw ticker) is what silently turns AAPL and AAPL.US into two canonical symbols, halving apparent netting and double-counting the asset. If you must run non-strict, check unmapped_broker_symbols() before trusting the output.Convert to Base Currency:
fx_rates[currency]. An unknown currency raises MissingFxRateError — it is never assumed to be 1:1.max_snapshot_age and pass valuation_time. Legs and the FX table are then age-checked and a stale one raises. Consolidating a 40-minute-old crypto snapshot with a live equity snapshot produces a view that was never simultaneously true at any broker. snapshot_skew_seconds reports the spread across a symbol's legs when all of them are timestamped.Aggregate & Net Consolidated Position:
gross_market_value_base. The signed total_market_value_base collapses a long-100/short-100 book to roughly zero while both legs still consume margin and carry borrow cost.weighted_avg_cost_base is None — not 0.0 — when the net position is flat within tolerance, because the quotient diverges as net quantity approaches zero.Reconciliation Audit:
QUANTITY_MISMATCH (both sides hold it, sizes differ) usually means a partial or missed fill. MISSING_AT_BROKER means an expected position does not exist — an unfilled order, or a broker-side forced close-out. UNEXPECTED_AT_BROKER means a broker holds something the strategy never intended, which is also the signature of a symbol-mapping failure creating a phantom symbol. Rule out the mapping before treating it as a rogue fill.symbol_tolerances per instrument.Full procedure: see
references/workflows.md. Standards reference: seereferences/standards.md. Printable pre-flight checklist: seeassets/checklist.md.
quantity × price understates it 100×. Twenty contracts at a $7.50 premium are $15,000 of exposure, not $150 — the difference between passing and breaching a gross-exposure cap.avgCost already reflects it for derivatives. Multiplying again turns a $840,000 cost basis into $42,000,000 and flips a $15,000 gain into a multi-million-dollar phantom loss.AAPL.US vs AAPL) yields two canonical entries for one asset. The offsetting legs never meet, so netting is understated and the same economic exposure is counted twice.gross_market_value_base and is_internally_offset are what surface it.as_of per leg and a maximum age, a stale leg is indistinguishable from a live one, and the "point-in-time" view never existed at any point in time.100.01 - 100.0 evaluates to 0.010000000000005, which exceeds a 0.01 tolerance and alerts a purely representational residue as a position break every cycle. Leave headroom.+0.00 reads as a non-event in the very alert raised to report it.net_quantity 300, gross_quantity 700, total_market_value_base $48,000, and gross_market_value_base $112,000 — the netted figure understates exposure by $64,000, and is_internally_offset must be true.contract_multiplier=100: verify $15,000, not $150. Value 3 futures at 5,700 index with contract_multiplier=50 and average_cost_includes_multiplier=True against a 280,000 avgCost: verify $855,000 market value, $840,000 cost, $15,000 unrealized — re-applying the 50× would report $42,000,000 of cost.fx_rates; an FX table missing the base currency or holding it at anything other than 1.0; a position in a currency absent from the table; a NaN or infinite quantity/cost/price; a negative price; a malformed currency code; a non-positive contract_multiplier; a naive (non-timezone-aware) as_of; a leg older than max_snapshot_age; a leg stamped ahead of valuation_time; an unmapped symbol under strict_symbol_mapping; duplicate target-ledger keys differing only in case.weighted_avg_cost_base is None rather than a cost per share in the hundreds of thousands.DiscrepancyKind values are produced by the three distinct situations, and that a 5e-06 BTC break is caught under symbol_tolerances={"BTC": 1e-8} while the 1e-5 default silently passes it.python -m unittest discover -s skills/multi-broker-consolidated-position-view/scripts and confirm 100% pass rate.cross-account-aggregate-risk-viewmulti-currency-pnl-and-fx-conversionmulti-asset-backtest-currency-normalizationreference-data-symbol-mapping-across-vendorsmulti-order-netting-before-routingbroker-failover-secondary-account-routingcorrelation-aware-exposure-limitsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub himanshuj16/algo-trading-skills --plugin algo-trading-broker-integration36 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.Other plugins' skills for the same job