Skip to content

fix: Alpaca broker fixes + IBroker redesign (provider → meta, aliceId → UTA)#71

Merged
luokerenx4 merged 5 commits intomasterfrom
dev
Mar 17, 2026
Merged

fix: Alpaca broker fixes + IBroker redesign (provider → meta, aliceId → UTA)#71
luokerenx4 merged 5 commits intomasterfrom
dev

Conversation

@luokerenx4
Copy link
Contributor

Summary

  • AlpacaBroker bug fixes: getOrder() was passing object instead of string ID (→404), UUID orderId parseInt→NaN, unrealizedPnL float drift in aggregation
  • realizedPnL optional: Alpaca API doesn't provide it natively; removed expensive fetchAllFills+FIFO computation from hot path
  • IBroker redesign: removed ambiguous provider field, added generic meta<TMeta> for broker-specific metadata (CcxtBroker uses meta.exchange)
  • aliceId ownership moved to UTA: new format {utaId}|{nativeKey} (e.g. alpaca-paper|META). Brokers no longer construct aliceId — fixes root cause of AI building invalid alpaca-paper-META
  • E2e coverage: Alpaca paper (11 tests), UTA real-broker lifecycle for both Alpaca+Bybit

Test plan

  • 856 unit tests passing
  • 37 e2e tests passing (Alpaca paper, Bybit demo, UTA lifecycle, UTA real-broker)
  • Full trading flow verified: stage→commit→push→sync→verify on both platforms

🤖 Generated with Claude Code

luokerenx4 and others added 5 commits March 17, 2026 19:33
…lete-branch

Lesson learned: squash merge with --delete-branch destroyed dev's
step-by-step commit history. Rules now explicit: no branch deletion,
prefer merge over squash, never combine squash with delete-branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tests

- getOrder() was passing { order_id } object instead of string ID (SDK expects getOrder(id))
- UUID orderId no longer pointlessly parseInt'd (always 0, real ID via string interface)
- unrealizedPnL aggregation uses Decimal to prevent float drift
- Remove unused isFilled variable in modifyOrder
- Add 11 Alpaca paper e2e tests (account, clock, quote, order lifecycle)
- Add 3 unit tests for fixes (UUID handling, call signature, precision)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…r e2e

- AccountInfo.realizedPnL → optional (IBKR/CCXT provide it natively, Alpaca doesn't)
- Delete alpaca-pnl.ts, fetchAllFills, getRealizedPnL — was fetching ALL historical
  FILL activities on every getAccount() call, causing ECONNRESET under load
- Delete computeRealizedPnL tests (11 tests removed, net test count stable)
- Add UTA real-broker e2e: full stage→commit→push→sync lifecycle against
  Alpaca paper (AAPL) and Bybit demo (ETH perp) — both passing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
IBroker.provider had inconsistent semantics: Alpaca filled "alpaca",
CcxtBroker filled exchange name ("bybit"). No clear definition existed.

- Remove provider from IBroker, UTA, AccountManager, MockBroker
- Add IBroker<TMeta = unknown> with optional meta field
- CcxtBroker: implements IBroker<CcxtBrokerMeta>, meta.exchange = "bybit"
- AlpacaBroker: uses literal 'alpaca' for contract helpers
- AccountManager.resolve(): id-only matching (provider fallback removed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
aliceId is now "{utaId}|{nativeKey}" (e.g. "alpaca-paper|META",
"bybit-main|ETH/USDT:USDT"). UTA owns construction and parsing;
brokers resolve contracts via symbol/localSymbol only.

- UTA: stampAliceId() wraps all broker output (positions, quotes, search)
- UTA: parseAliceId() extracts nativeKey for broker input (stage ops)
- Broker: no longer constructs aliceId in makeContract/marketToContract
- CCXT contractToCcxt: removed aliceId-first resolution, uses localSymbol
- Alpaca resolveSymbol: removed aliceId parsing, uses symbol directly
- CcxtBroker.closePosition: matches by localSymbol instead of aliceId

Fixes the root cause of AI constructing invalid aliceId "alpaca-paper-META"
(broker.id used as prefix instead of provider).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@luokerenx4 luokerenx4 merged commit cd72e9d into master Mar 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant