Repository navigation
fix: preserve Topstep fill metadata and persist Questrade token rotation - #21
Open
aintelegator wants to merge 3 commits into
Open
aintelegator wants to merge 3 commits into
aintelegator wants to merge 3 commits into
Conversation
added 3 commits
October 7, 2026 12:27
Expose native fill and instrument identity, a deterministic tie-break key, and reported gross P&L. Preserve UTC fractional precision, report explicit zero costs, combine fee components, and reject unsuccessful or malformed responses. Signed-off-by: Alexey Intelegator <alexey.intelegator@email.com>
Prefer account-scoped execution IDs and reserve exact matches before consuming legacy millisecond occurrences. Compare fractional timestamps without losing precision or misordering mixed fraction lengths in FIFO stats. Signed-off-by: Alexey Intelegator <alexey.intelegator@email.com>
Update connection credentials immediately after single-use refresh-token exchange and await the persistence callback before further IO. Propagate callback failures and retain rotatedCredentials for direct adapter consumers without the callback. Signed-off-by: Alexey Intelegator <alexey.intelegator@email.com>
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.
Topstep fills currently lose native identity and timestamp precision, omit separately returned commissions, and can turn failed searches into empty positions/history. Questrade can also lose a replacement single-use refresh token when a later account/history request fails. This PR preserves the fill metadata and delivers Questrade rotation before subsequent requests.
Changes
Trade.executionId,instrumentId,executionTieBreak, andreportedGrossPnl. Topstep preserves full contract IDs and all timestamp fraction digits while normalizing offsets to UTC; the parser only passes milliseconds toDate.parse.feespluscommissions, preserve explicit zero costs, and expose provider-reported gross realized P&L. Omit the whole fee when either component is negative because its meaning is unspecified.success: falseresponses at HTTP 200 and malformed non-object/array bodies with typed errors. Failed searches abort the snapshot rather than producing empty history or false position-closure events.FetchContext.onCredentialsRotated. Questrade awaits it immediately after exchange;connect()updates in-memory credentials before invoking persistence. Callback failures stop further requests. Direct consumers without a callback retainrotatedCredentialson success.Returned provider accounts remain separate and automatically discovered. The commits separate Topstep/schema work, sync/stats handling, and Questrade rotation. Documentation, the Topstep conformance vector, and synthetic regression tests are included; no generated bundles, source maps, dependencies, or version bump are included.
Compatibility and limits
executionTieBreakis a deterministic numeric ID key, not a documented chronological sequence. Provider array order remains intact; stats preserves input order for exact timestamp ties.executedAtabsent. Timestamp-based external consumers must account for the preserved fractional precision. Legacy fills indistinguishable at millisecond precision remain ambiguous during migration.feesand optionalcommissions. Its official fee breakdown lists fees and commissions as separate additive costs, supporting this mapping. The API schema does not explicitly define their accounting relationship; no live fill/statement reconciliation was performed.brokerFeefield is omitted; combined costs use the existingfeefield.Validation
pnpm check: typecheck and 296 tests passed (20 files).pnpm build: ESM, CJS, and declaration builds passed.git diff --checkpassed.Validated locally on Node 26.10.0; the upstream CI matrix is Node 18/20/22. Tests use synthetic provider data and no live broker credentials.
AI assistance
This contribution was AI-assisted using OpenAI Codex for implementation, tests, documentation, and review. The contributor also independently reviewed the changes and re-ran typecheck and tests. All commits include the repository-required DCO sign-off.