Repository navigation
fix(executions): accept IBKR overnight fills dated to the next day #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // US 23/5: an overnight fill's execution time keeps its local date in the trades UI. | ||
| import assert from "node:assert/strict"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { executionClock } from "../web/strategy-switch-console/frontend/src/pages/performance/executionClock.ts"; | ||
|
|
||
| assert.equal(executionClock("2026-10-23T09:31:00", "2026-10-23"), "09:31:00", "same-day fill shows only the clock"); | ||
| assert.equal(executionClock("2026-10-22T20:30:00", "2026-10-23"), "2026-10-22 20:30:00", "overnight fill keeps its local date"); | ||
| assert.equal(executionClock("2026-10-23T09:31:00", null), "09:31:00", "no trade date: clock only"); | ||
|
|
||
| const tabs = readFileSync(new URL("../web/strategy-switch-console/frontend/src/pages/performance/PerformanceTabs.tsx", import.meta.url), "utf8"); | ||
| assert.equal((tabs.match(/executionClock\(row\.local_time, row\.trade_date\)/g) || []).length, 2, "table and card both use executionClock"); | ||
| assert.doesNotMatch(tabs, /row\.local_time\.slice\(11\)/, "no view drops the local date"); | ||
| console.log("console_execution_clock_validation: PASS (overnight fills keep their local execution date)"); |
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
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
33 changes: 33 additions & 0 deletions
33
web/strategy-switch-console/application/account_facts/trade_date_boundary.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // US 23/5 trade-date boundary shared by broker-execution consumers. | ||
| // | ||
| // IBKR dates fills from 20:00 ET to midnight on the following day, so an overnight | ||
| // execution's local wall time falls on the evening before its trade date. A | ||
| // local time may therefore differ from its trade date only in that shape: it is | ||
| // on the calendar day immediately before the trade date, at or after 20:00, and | ||
| // stated in US Eastern time. A null time zone is read as Eastern, the Flex default | ||
| // assumed by the producer; any other explicit zone keeps the same-day rule. | ||
| // Every other mismatch stays invalid. | ||
|
|
||
| export const TRADE_DATE_BOUNDARY = "20:00:00"; | ||
| const EASTERN = "America/New_York"; | ||
|
|
||
| function strictDayMs(value) { | ||
| if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null; | ||
| const ms = Date.parse(`${value}T00:00:00Z`); | ||
| return Number.isFinite(ms) && new Date(ms).toISOString().slice(0, 10) === value ? ms : null; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} localDay YYYY-MM-DD of the local wall time | ||
| * @param {string} timeText HH:MM:SS of the local wall time | ||
| * @param {string} tradeDate YYYY-MM-DD broker trade date | ||
| * @param {string|null|undefined} timeZone record time zone, null when unstated | ||
| */ | ||
| export function localTimeMatchesTradeDate(localDay, timeText, tradeDate, timeZone = null) { | ||
| const localMs = strictDayMs(localDay); | ||
| const tradeMs = strictDayMs(tradeDate); | ||
| if (localMs === null || tradeMs === null) return false; | ||
| if (localMs === tradeMs) return true; | ||
| if (timeZone !== null && timeZone !== undefined && timeZone !== EASTERN) return false; | ||
| return tradeMs - localMs === 86_400_000 && typeof timeText === "string" && timeText >= TRADE_DATE_BOUNDARY; | ||
| } |
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
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
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
10 changes: 10 additions & 0 deletions
10
web/strategy-switch-console/frontend/src/pages/performance/executionClock.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * Clock text for a broker execution row. A US 23/5 overnight fill is booked on the | ||
| * next trade date (IBKR dates 20:00 ET to midnight fills to the following day), so | ||
| * when the local date differs from the trade date the local date is kept, so the | ||
| * execution time is never shown a day late. | ||
| */ | ||
| export function executionClock(localTime: string, tradeDate: string | null | undefined): string { | ||
| const localDay = localTime.slice(0, 10); | ||
| return tradeDate && localDay !== tradeDate ? `${localDay} ${localTime.slice(11)}` : localTime.slice(11); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.