Use `.ib.venues.is_venue_open()` in `.feed`
In `.ib.feed.stream_quotes()` specifically that is since time-range checking code was moved to the new sub-mod. Deats, - drop import of old `is_current_time_in_range()` from `._util` - change `get_bars()` sig: `end_dt`/`start_dt` to `datetime|None` - comment-out `breakpoint()` in `open_history_client()` Styling, - add multiline style to conditionals and tuple unpacks - fix type annotation: `Contract|None` vs `Contract | None` - fix backticks in comment: `ib_insync` vs `ib_async` (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codecont_hist_fixes
parent
ba575d93ea
commit
f502851999
|
|
@ -69,9 +69,9 @@ from .api import (
|
||||||
Contract,
|
Contract,
|
||||||
RequestError,
|
RequestError,
|
||||||
)
|
)
|
||||||
|
from .venues import is_venue_open
|
||||||
from ._util import (
|
from ._util import (
|
||||||
data_reset_hack,
|
data_reset_hack,
|
||||||
is_current_time_in_range,
|
|
||||||
)
|
)
|
||||||
from .symbols import get_mkt_info
|
from .symbols import get_mkt_info
|
||||||
|
|
||||||
|
|
@ -203,7 +203,8 @@ async def open_history_client(
|
||||||
latency = time.time() - query_start
|
latency = time.time() - query_start
|
||||||
if (
|
if (
|
||||||
not timedout
|
not timedout
|
||||||
# and latency <= max_timeout
|
# and
|
||||||
|
# latency <= max_timeout
|
||||||
):
|
):
|
||||||
count += 1
|
count += 1
|
||||||
mean += latency / count
|
mean += latency / count
|
||||||
|
|
@ -219,8 +220,10 @@ async def open_history_client(
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
end_dt
|
end_dt
|
||||||
and head_dt
|
and
|
||||||
and end_dt <= head_dt
|
head_dt
|
||||||
|
and
|
||||||
|
end_dt <= head_dt
|
||||||
):
|
):
|
||||||
raise DataUnavailable(
|
raise DataUnavailable(
|
||||||
f'First timestamp is {head_dt}\n'
|
f'First timestamp is {head_dt}\n'
|
||||||
|
|
@ -278,7 +281,7 @@ async def open_history_client(
|
||||||
start_dt
|
start_dt
|
||||||
):
|
):
|
||||||
# TODO! rm this once we're more confident it never hits!
|
# TODO! rm this once we're more confident it never hits!
|
||||||
breakpoint()
|
# breakpoint()
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f'OHLC-bars array start is gt `start_dt` limit !!\n'
|
f'OHLC-bars array start is gt `start_dt` limit !!\n'
|
||||||
f'start_dt: {start_dt}\n'
|
f'start_dt: {start_dt}\n'
|
||||||
|
|
@ -298,7 +301,7 @@ async def open_history_client(
|
||||||
# TODO: it seems like we can do async queries for ohlc
|
# TODO: it seems like we can do async queries for ohlc
|
||||||
# but getting the order right still isn't working and I'm not
|
# but getting the order right still isn't working and I'm not
|
||||||
# quite sure why.. needs some tinkering and probably
|
# quite sure why.. needs some tinkering and probably
|
||||||
# a lookthrough of the ``ib_insync`` machinery, for eg. maybe
|
# a lookthrough of the `ib_insync` machinery, for eg. maybe
|
||||||
# we have to do the batch queries on the `asyncio` side?
|
# we have to do the batch queries on the `asyncio` side?
|
||||||
yield (
|
yield (
|
||||||
get_hist,
|
get_hist,
|
||||||
|
|
@ -421,14 +424,13 @@ _failed_resets: int = 0
|
||||||
|
|
||||||
|
|
||||||
async def get_bars(
|
async def get_bars(
|
||||||
|
|
||||||
proxy: MethodProxy,
|
proxy: MethodProxy,
|
||||||
fqme: str,
|
fqme: str,
|
||||||
timeframe: int,
|
timeframe: int,
|
||||||
|
|
||||||
# blank to start which tells ib to look up the latest datum
|
# blank to start which tells ib to look up the latest datum
|
||||||
end_dt: str = '',
|
end_dt: datetime|None = None,
|
||||||
start_dt: str|None = '',
|
start_dt: datetime|None = None,
|
||||||
|
|
||||||
# TODO: make this more dynamic based on measured frame rx latency?
|
# TODO: make this more dynamic based on measured frame rx latency?
|
||||||
# how long before we trigger a feed reset (seconds)
|
# how long before we trigger a feed reset (seconds)
|
||||||
|
|
@ -482,7 +484,8 @@ async def get_bars(
|
||||||
dt_duration,
|
dt_duration,
|
||||||
) = await proxy.bars(
|
) = await proxy.bars(
|
||||||
fqme=fqme,
|
fqme=fqme,
|
||||||
# XXX TODO! lol we're not using this..
|
# XXX TODO! LOL we're not using this and IB dun
|
||||||
|
# support it anyway..
|
||||||
# start_dt=start_dt,
|
# start_dt=start_dt,
|
||||||
end_dt=end_dt,
|
end_dt=end_dt,
|
||||||
sample_period_s=timeframe,
|
sample_period_s=timeframe,
|
||||||
|
|
@ -734,7 +737,7 @@ async def _setup_quote_stream(
|
||||||
# '294', # Trade rate / minute
|
# '294', # Trade rate / minute
|
||||||
# '295', # Vlm rate / minute
|
# '295', # Vlm rate / minute
|
||||||
),
|
),
|
||||||
contract: Contract | None = None,
|
contract: Contract|None = None,
|
||||||
|
|
||||||
) -> trio.abc.ReceiveChannel:
|
) -> trio.abc.ReceiveChannel:
|
||||||
'''
|
'''
|
||||||
|
|
@ -756,7 +759,12 @@ async def _setup_quote_stream(
|
||||||
# XXX since this is an `asyncio.Task`, we must use
|
# XXX since this is an `asyncio.Task`, we must use
|
||||||
# tractor.pause_from_sync()
|
# tractor.pause_from_sync()
|
||||||
|
|
||||||
caccount_name, client = get_preferred_data_client(accts2clients)
|
(
|
||||||
|
_account_name,
|
||||||
|
client,
|
||||||
|
) = get_preferred_data_client(
|
||||||
|
accts2clients,
|
||||||
|
)
|
||||||
contract = (
|
contract = (
|
||||||
contract
|
contract
|
||||||
or
|
or
|
||||||
|
|
@ -1091,14 +1099,9 @@ async def stream_quotes(
|
||||||
)
|
)
|
||||||
|
|
||||||
# is venue active rn?
|
# is venue active rn?
|
||||||
venue_is_open: bool = any(
|
venue_is_open: bool = is_venue_open(
|
||||||
is_current_time_in_range(
|
con_deats=details,
|
||||||
start_dt=sesh.start,
|
|
||||||
end_dt=sesh.end,
|
|
||||||
)
|
)
|
||||||
for sesh in details.tradingSessions()
|
|
||||||
)
|
|
||||||
|
|
||||||
init_msg = FeedInit(mkt_info=mkt)
|
init_msg = FeedInit(mkt_info=mkt)
|
||||||
|
|
||||||
# NOTE, tell sampler (via config) to skip vlm summing for dst
|
# NOTE, tell sampler (via config) to skip vlm summing for dst
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue