Use `con.exchange` as fallback when `con.primaryExchange` is empty
in `has_holiday()` to handle contracts like futures that don't
always set a `primaryExchange`.
Deats,
- extract `con: Contract` from `con_deats.contract` for reuse.
- use `con.primaryExchange or con.exchange` to ensure a valid
exchange code is always passed to the calendar lookup.
- add `Contract` to `TYPE_CHECKING` imports.
(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
Add exchange name translation in `.ib.venues.has_holiday()` to handle
non-standard exchange codes when looking up holiday gaps..
Deats,
- add an ad-hoc lookup dict to remap an IB `Contract.primaryExchange` val
which doesn't exist in the `exchange_calendars`'s alias set.
- use `.get()` with fallback to map `exch` to new `std_exch` and pass
that to `xcals.get_calendar()`.
- add the case i just caught, `'ARCA'` -> `'ARCX'` to the table when i loaded
the `gld.arca.ib` market..
(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
Migrate the IB broker backend to use `ib_async` (the actively maintained
fork) instead of the now stale, original `ib_insync` lib.
Deats,
- update `pyproject.toml` dep: drop `ib-insync` pin, add
`ib-async>=2.1.0`.
- update lock file with `ib-async` and its new `aeventkit` dep (which
i guess replaces `eventkit`).
- obvi, change all `ib_insync` imports to `ib_async` across `.ib.*`.
- update docs and select internal comments referencing the original lib.
Also,
- drop unused `ledger_dict` init in `_flex_reports.load_flex_trades()`.
- fix union type annot style: `dict | None` -> `dict|None`.
- strip `.tzinfo` from `lastTimeStamp` in `normalize()` to avoid
IPC codec issues with `ib_async`'s `timezone.utc` injection.
- pop `'defaults'` from ticker data dict in `normalize()` to avoid
non-serializable `timezone` objects and warning-log in such
cases.
(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
Integrate `exchange_calendars` lib to detect market holidays in
gap-checking logic via new `.ib.venues.has_holiday()` helper!
The `.ib.venues` impl deats,
- add a new `has_holiday()` using `xcals.get_calendar()` and friends
for sanity checking a venue's holiday closure-gaps.
* final holiday detection-check is basically,
`(cash_gap := (next_open - prev_close)) > period`
- include `time_step_s` param to `is_venue_closure()` for boundary
tolerance checks.
* let's us expand closure-time checks to include `+/-time_step_s`
"off-by-one-`timeframe`-sample" edge case ranges.
- add real docstring to `has_weekend()`.
In `.ib.api` refine usage for ^ changes,
- move `is_venue_open()` call + tz-convert outside gap check
- use a walrus to capture `has_closure_gap` from `is_venue_closure()`
- add a `not has_closure_gap` condition to the
mismatched-duration/short-frame warning block to avoid needless warns.
- keep duration-based "short-frame" log as `.error()` but toss in a bp
so (somone can) umask to figure out wtf is going on..
* we should **never** really hit this path unless there's a valid bug
or data issue with IB/GFIS!
* keep recursion path masked-out just leave a `breakpoint()` for now.
Also some logger updates,
- import `get_logger()` from top-level `piker.log` vs `.ib._util` which
was always kinda wrong..
- change `NonShittyIB._logger` to use `__name__` vs literal.
(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
It was an AI-model draft that we can prolly toss but figured might as
well org it appropriately.
(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
Introduce set of helper-fns for detecting venue open/close status,
session start/end times, and related time-gap detection using
`pendulum`.
Deats,
- add `iter_sessions()` to yield `pendulum.Interval`s from
a `ContractDetails` instance.
- add `is_venue_open()` to check if active at a given time.
- add `is_venue_closure()` to detect valid closure gaps.
- add `sesh_times()` to extract weekday-agnostic open/close times.
- add `has_weekend()` to check for Sat/Sun in interval.
- move in lowlevel `is_current_time_in_range()` for checking a
datetime within a `sesh: pendulum.Interval`.
(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code