feat: support IBKR spot FX orders - #105
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #104. This covers CLI layers 2–4 of the issue. It uses
@huskly/ibkr-gateway-client0.18.0 (huskly/ibkr-gateway#106), which runs on@huskly/ibkr-client4.1.0 (huskly/ibkr-client#134).fx preview <pair> <side> <quantity> --limit <price> [--tif DAY|GTC] [--json]andfx submit <preview-id> --confirm [--operator] [--json]. The broker is IBKR only;--broker schwabfails with "FX orders are available for IBKR only."src/forex/:forexPair.tsacceptsUSD.JPY,USD/JPY, andUSDJPY, and refuses bad codes and a pair whose base equals its quote.forexOrder.tsholds the types and the canonical intent schema.forexGatewayAdapter.tsandforexOrderService.tsimplement the flow: LMT only, whole base-currency units,DAY/GTC, and no session.src/orders/singleOrderWorkflow.tsholds the preview store, expiry, content-hash ID, idempotent submit, and recovery. The equity and FX services both use it.src/cli/guardedOrderCommands.tsholds the shared CLI parts (broker flag, side/TIF parsing,--confirm, and warning acknowledgement).fx_order_previewandfx_order_submittake the same inputs as the CLI.formatMoney(value, currencyCode, digits?)is new, andcurrencyFormatUsdis now a wrapper around it.formatForexPriceshows a limit in the quote currency with FX precision, for example¥147.255.ordersshows FX prices and average fills in the quote currency, taken from theBASE.QUOTEleg, and never with$. The Current column stays-for FX; FX quotes are a later layer.CASH. Before this change,orderswould fail once an FX order existed.ordercommands handle these. The shared execution store accepts the FX intent.Fixes found on the way
isOptionIntenttreated every non-STKsingle record as an option, so it would also have claimed FX records. It now matchesOPT/FOPonly.currencyto every preview response. The strict spread-preview schema would have rejected it, so the derivative preview result, schema, and DTO now carrycurrencytoo.Not in scope
STPFX orders and FX quotes inquote --broker ibkr.Tests
test/forex/forexPair.test.ts: valid pairs,USDJPY,USD/JPY, bad codes, and a same-currency pair.test/forex/forexOrderService.test.ts: contract mismatch, bad terms, odd-lot warning, preview expiry, idempotent submit, uncertain-write recovery, and separation from equity records in the shared store.test/cli/forexOrders.test.ts: Schwab rejection, the--jsonDTO shape, JPY price formatting, and input validation.test/mcp/forexOrders.test.ts,test/format.test.ts, and an FX case intest/cli/orders.test.ts.yarn checkpasses (357 tests), andyarn buildpasses.I did not run a live preview. The local gateway credentials fail authentication on
maintoo.