Compare commits
4 Commits
ab1463d942
...
b577180773
Author | SHA1 | Date |
---|---|---|
Tyler Goodlet | b577180773 | |
Tyler Goodlet | f12c452d96 | |
Tyler Goodlet | 3531c2edc1 | |
Tyler Goodlet | 97dd7e766a |
|
@ -100,7 +100,7 @@ async def data_reset_hack(
|
||||||
log.warning(
|
log.warning(
|
||||||
no_setup_msg
|
no_setup_msg
|
||||||
+
|
+
|
||||||
f'REQUIRES A `vnc_addrs: array` ENTRY'
|
'REQUIRES A `vnc_addrs: array` ENTRY'
|
||||||
)
|
)
|
||||||
|
|
||||||
vnc_host, vnc_port = vnc_sockaddr.get(
|
vnc_host, vnc_port = vnc_sockaddr.get(
|
||||||
|
@ -259,7 +259,7 @@ def i3ipc_xdotool_manual_click_hack() -> None:
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
# re-activate and focus original window
|
# re-activate and focus original window
|
||||||
subprocess.call([
|
subprocess.call([
|
||||||
'xdotool',
|
'xdotool',
|
||||||
'windowactivate', '--sync', str(orig_win_id),
|
'windowactivate', '--sync', str(orig_win_id),
|
||||||
|
|
|
@ -287,9 +287,31 @@ class Client:
|
||||||
self.conf = config
|
self.conf = config
|
||||||
|
|
||||||
# NOTE: the ib.client here is "throttled" to 45 rps by default
|
# NOTE: the ib.client here is "throttled" to 45 rps by default
|
||||||
self.ib = ib
|
self.ib: IB = ib
|
||||||
self.ib.RaiseRequestErrors: bool = True
|
self.ib.RaiseRequestErrors: bool = True
|
||||||
|
|
||||||
|
# self._acnt_names: set[str] = {}
|
||||||
|
self._acnt_names: list[str] = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def acnts(self) -> list[str]:
|
||||||
|
# return list(self._acnt_names)
|
||||||
|
return self._acnt_names
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return (
|
||||||
|
f'<{type(self).__name__}('
|
||||||
|
f'ib={self.ib} '
|
||||||
|
f'acnts={self.acnts}'
|
||||||
|
|
||||||
|
# TODO: we need to mask out acnt-#s and other private
|
||||||
|
# infos if we're going to console this!
|
||||||
|
# f' |_.conf:\n'
|
||||||
|
# f' {pformat(self.conf)}\n'
|
||||||
|
|
||||||
|
')>'
|
||||||
|
)
|
||||||
|
|
||||||
async def get_fills(self) -> list[Fill]:
|
async def get_fills(self) -> list[Fill]:
|
||||||
'''
|
'''
|
||||||
Return list of rents `Fills` from trading session.
|
Return list of rents `Fills` from trading session.
|
||||||
|
@ -376,55 +398,63 @@ class Client:
|
||||||
# whatToShow='MIDPOINT',
|
# whatToShow='MIDPOINT',
|
||||||
# whatToShow='TRADES',
|
# whatToShow='TRADES',
|
||||||
)
|
)
|
||||||
log.info(
|
|
||||||
f'REQUESTING {ib_duration_str} worth {bar_size} BARS\n'
|
|
||||||
f'fqme: {fqme}\n'
|
|
||||||
f'global _enters: {_enters}\n'
|
|
||||||
f'kwargs: {pformat(kwargs)}\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
bars = await self.ib.reqHistoricalDataAsync(
|
bars = await self.ib.reqHistoricalDataAsync(
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
query_info: str = (
|
||||||
|
f'REQUESTING IB history BARS\n'
|
||||||
|
f' ------ - ------\n'
|
||||||
|
f'dt_duration: {dt_duration}\n'
|
||||||
|
f'ib_duration_str: {ib_duration_str}\n'
|
||||||
|
f'bar_size: {bar_size}\n'
|
||||||
|
f'fqme: {fqme}\n'
|
||||||
|
f'actor-global _enters: {_enters}\n'
|
||||||
|
f'kwargs: {pformat(kwargs)}\n'
|
||||||
|
)
|
||||||
# tail case if no history for range or none prior.
|
# tail case if no history for range or none prior.
|
||||||
|
# NOTE: there's actually 3 cases here to handle (and
|
||||||
|
# this should be read alongside the implementation of
|
||||||
|
# `.reqHistoricalDataAsync()`):
|
||||||
|
# - a timeout occurred in which case insync internals return
|
||||||
|
# an empty list thing with bars.clear()...
|
||||||
|
# - no data exists for the period likely due to
|
||||||
|
# a weekend, holiday or other non-trading period prior to
|
||||||
|
# ``end_dt`` which exceeds the ``duration``,
|
||||||
|
# - LITERALLY this is the start of the mkt's history!
|
||||||
if not bars:
|
if not bars:
|
||||||
# NOTE: there's actually 3 cases here to handle (and
|
# TODO: figure out wut's going on here.
|
||||||
# this should be read alongside the implementation of
|
|
||||||
# `.reqHistoricalDataAsync()`):
|
|
||||||
# - a timeout occurred in which case insync internals return
|
|
||||||
# an empty list thing with bars.clear()...
|
|
||||||
# - no data exists for the period likely due to
|
|
||||||
# a weekend, holiday or other non-trading period prior to
|
|
||||||
# ``end_dt`` which exceeds the ``duration``,
|
|
||||||
# - LITERALLY this is the start of the mkt's history!
|
|
||||||
|
|
||||||
|
# TODO: is this handy, a sync requester for tinkering
|
||||||
|
# with empty frame cases?
|
||||||
|
# def get_hist():
|
||||||
|
# return self.ib.reqHistoricalData(**kwargs)
|
||||||
|
# import pdbp
|
||||||
|
# pdbp.set_trace()
|
||||||
|
|
||||||
# sync requester for debugging empty frame cases
|
log.critical(
|
||||||
def get_hist():
|
'STUPID IB SAYS NO HISTORY\n\n'
|
||||||
return self.ib.reqHistoricalData(**kwargs)
|
+ query_info
|
||||||
|
)
|
||||||
|
|
||||||
assert get_hist
|
|
||||||
import pdbp
|
|
||||||
pdbp.set_trace()
|
|
||||||
|
|
||||||
return [], np.empty(0), dt_duration
|
|
||||||
# TODO: we could maybe raise ``NoData`` instead if we
|
# TODO: we could maybe raise ``NoData`` instead if we
|
||||||
# rewrite the method in the first case? right now there's no
|
# rewrite the method in the first case?
|
||||||
# way to detect a timeout.
|
# right now there's no way to detect a timeout..
|
||||||
|
return [], np.empty(0), dt_duration
|
||||||
|
|
||||||
# NOTE XXX: ensure minimum duration in bars B)
|
log.info(query_info)
|
||||||
# => we recursively call this method until we get at least
|
# NOTE XXX: ensure minimum duration in bars?
|
||||||
# as many bars such that they sum in aggregate to the the
|
# => recursively call this method until we get at least as
|
||||||
# desired total time (duration) at most.
|
# many bars such that they sum in aggregate to the the
|
||||||
# XXX XXX XXX
|
# desired total time (duration) at most.
|
||||||
# WHY DID WE EVEN NEED THIS ORIGINALLY!?
|
# - if you query over a gap and get no data
|
||||||
# XXX XXX XXX
|
# that may short circuit the history
|
||||||
# - if you query over a gap and get no data
|
|
||||||
# that may short circuit the history
|
|
||||||
if (
|
if (
|
||||||
end_dt
|
# XXX XXX XXX
|
||||||
and False
|
# => WHY DID WE EVEN NEED THIS ORIGINALLY!? <=
|
||||||
|
# XXX XXX XXX
|
||||||
|
False
|
||||||
|
and end_dt
|
||||||
):
|
):
|
||||||
nparr: np.ndarray = bars_to_np(bars)
|
nparr: np.ndarray = bars_to_np(bars)
|
||||||
times: np.ndarray = nparr['time']
|
times: np.ndarray = nparr['time']
|
||||||
|
@ -927,7 +957,10 @@ class Client:
|
||||||
warnset = True
|
warnset = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info(f'Got first quote for {contract}')
|
log.info(
|
||||||
|
'Got first quote for contract\n'
|
||||||
|
f'{contract}\n'
|
||||||
|
)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if timeouterr and raise_on_timeout:
|
if timeouterr and raise_on_timeout:
|
||||||
|
@ -991,8 +1024,12 @@ class Client:
|
||||||
outsideRth=True,
|
outsideRth=True,
|
||||||
|
|
||||||
optOutSmartRouting=True,
|
optOutSmartRouting=True,
|
||||||
|
# TODO: need to understand this setting better as
|
||||||
|
# it pertains to shit ass mms..
|
||||||
routeMarketableToBbo=True,
|
routeMarketableToBbo=True,
|
||||||
|
|
||||||
designatedLocation='SMART',
|
designatedLocation='SMART',
|
||||||
|
|
||||||
# TODO: make all orders GTC?
|
# TODO: make all orders GTC?
|
||||||
# https://interactivebrokers.github.io/tws-api/classIBApi_1_1Order.html#a95539081751afb9980f4c6bd1655a6ba
|
# https://interactivebrokers.github.io/tws-api/classIBApi_1_1Order.html#a95539081751afb9980f4c6bd1655a6ba
|
||||||
# goodTillDate=f"yyyyMMdd-HH:mm:ss",
|
# goodTillDate=f"yyyyMMdd-HH:mm:ss",
|
||||||
|
@ -1120,8 +1157,8 @@ def get_config() -> dict[str, Any]:
|
||||||
names = list(accounts.keys())
|
names = list(accounts.keys())
|
||||||
accts = section['accounts'] = bidict(accounts)
|
accts = section['accounts'] = bidict(accounts)
|
||||||
log.info(
|
log.info(
|
||||||
f'brokers.toml defines {len(accts)} accounts: '
|
f'{path} defines {len(accts)} account aliases:\n'
|
||||||
f'{pformat(names)}'
|
f'{pformat(names)}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
if section is None:
|
if section is None:
|
||||||
|
@ -1188,7 +1225,7 @@ async def load_aio_clients(
|
||||||
try_ports = list(try_ports.values())
|
try_ports = list(try_ports.values())
|
||||||
|
|
||||||
_err = None
|
_err = None
|
||||||
accounts_def = config.load_accounts(['ib'])
|
accounts_def: dict[str, str] = config.load_accounts(['ib'])
|
||||||
ports = try_ports if port is None else [port]
|
ports = try_ports if port is None else [port]
|
||||||
combos = list(itertools.product(hosts, ports))
|
combos = list(itertools.product(hosts, ports))
|
||||||
accounts_found: dict[str, Client] = {}
|
accounts_found: dict[str, Client] = {}
|
||||||
|
@ -1227,7 +1264,9 @@ async def load_aio_clients(
|
||||||
client = Client(ib=ib, config=conf)
|
client = Client(ib=ib, config=conf)
|
||||||
|
|
||||||
# update all actor-global caches
|
# update all actor-global caches
|
||||||
log.info(f"Caching client for {sockaddr}")
|
log.runtime(
|
||||||
|
f'Connected and caching `Client` @ {sockaddr!r}'
|
||||||
|
)
|
||||||
_client_cache[sockaddr] = client
|
_client_cache[sockaddr] = client
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -1242,37 +1281,59 @@ async def load_aio_clients(
|
||||||
OSError,
|
OSError,
|
||||||
) as ce:
|
) as ce:
|
||||||
_err = ce
|
_err = ce
|
||||||
log.warning(
|
message: str = (
|
||||||
f'Failed to connect on {host}:{port} for {i} time with,\n'
|
f'Failed to connect on {host}:{port} after {i} tries with\n'
|
||||||
f'{ib.client.apiError.value()}\n'
|
f'{ib.client.apiError.value()!r}\n\n'
|
||||||
'retrying with a new client id..')
|
'Retrying with a new client id..\n'
|
||||||
|
)
|
||||||
|
log.runtime(message)
|
||||||
|
else:
|
||||||
|
# XXX report loudly if we never established after all
|
||||||
|
# re-tries
|
||||||
|
log.warning(message)
|
||||||
|
|
||||||
# Pre-collect all accounts available for this
|
# Pre-collect all accounts available for this
|
||||||
# connection and map account names to this client
|
# connection and map account names to this client
|
||||||
# instance.
|
# instance.
|
||||||
for value in ib.accountValues():
|
for value in ib.accountValues():
|
||||||
acct_number = value.account
|
acct_number: str = value.account
|
||||||
|
|
||||||
entry = accounts_def.inverse.get(acct_number)
|
acnt_alias: str = accounts_def.inverse.get(acct_number)
|
||||||
if not entry:
|
if not acnt_alias:
|
||||||
|
|
||||||
|
# TODO: should we constuct the below reco-ex from
|
||||||
|
# the existing config content?
|
||||||
|
_, path = config.load(
|
||||||
|
conf_name='brokers',
|
||||||
|
)
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'No section in brokers.toml for account:'
|
'No alias in account section for account!\n'
|
||||||
f' {acct_number}\n'
|
f'Please add an acnt alias entry to your {path}\n'
|
||||||
f'Please add entry to continue using this API client'
|
'For example,\n\n'
|
||||||
|
|
||||||
|
'[ib.accounts]\n'
|
||||||
|
'margin = {accnt_number!r}\n'
|
||||||
|
'^^^^^^ <- you need this part!\n\n'
|
||||||
|
|
||||||
|
'This ensures `piker` will not leak private acnt info '
|
||||||
|
'to console output by default!\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
# surjection of account names to operating clients.
|
# surjection of account names to operating clients.
|
||||||
if acct_number not in accounts_found:
|
if acnt_alias not in accounts_found:
|
||||||
accounts_found[entry] = client
|
accounts_found[acnt_alias] = client
|
||||||
|
# client._acnt_names.add(acnt_alias)
|
||||||
|
client._acnt_names.append(acnt_alias)
|
||||||
|
|
||||||
log.info(
|
if accounts_found:
|
||||||
f'Loaded accounts for client @ {host}:{port}\n'
|
log.info(
|
||||||
f'{pformat(accounts_found)}'
|
f'Loaded accounts for api client\n\n'
|
||||||
)
|
f'{pformat(accounts_found)}\n'
|
||||||
|
)
|
||||||
|
|
||||||
# XXX: why aren't we just updating this directy above
|
# XXX: why aren't we just updating this directy above
|
||||||
# instead of using the intermediary `accounts_found`?
|
# instead of using the intermediary `accounts_found`?
|
||||||
_accounts2clients.update(accounts_found)
|
_accounts2clients.update(accounts_found)
|
||||||
|
|
||||||
# if we have no clients after the scan loop then error out.
|
# if we have no clients after the scan loop then error out.
|
||||||
if not _client_cache:
|
if not _client_cache:
|
||||||
|
@ -1472,7 +1533,7 @@ async def open_aio_client_method_relay(
|
||||||
msg: tuple[str, dict] | dict | None = await from_trio.get()
|
msg: tuple[str, dict] | dict | None = await from_trio.get()
|
||||||
match msg:
|
match msg:
|
||||||
case None: # termination sentinel
|
case None: # termination sentinel
|
||||||
print('asyncio PROXY-RELAY SHUTDOWN')
|
log.info('asyncio `Client` method-proxy SHUTDOWN!')
|
||||||
break
|
break
|
||||||
|
|
||||||
case (meth_name, kwargs):
|
case (meth_name, kwargs):
|
||||||
|
|
|
@ -1183,7 +1183,14 @@ async def deliver_trade_events(
|
||||||
pos
|
pos
|
||||||
and fill
|
and fill
|
||||||
):
|
):
|
||||||
assert fill.commissionReport == cr
|
now_cr: CommissionReport = fill.commissionReport
|
||||||
|
if (now_cr != cr):
|
||||||
|
log.warning(
|
||||||
|
'UhhHh ib updated the commission report mid-fill..?\n'
|
||||||
|
f'was: {pformat(cr)}\n'
|
||||||
|
f'now: {pformat(now_cr)}\n'
|
||||||
|
)
|
||||||
|
|
||||||
await emit_pp_update(
|
await emit_pp_update(
|
||||||
ems_stream,
|
ems_stream,
|
||||||
accounts_def,
|
accounts_def,
|
||||||
|
|
|
@ -671,8 +671,8 @@ async def _setup_quote_stream(
|
||||||
# making them mostly useless and explains why the scanner
|
# making them mostly useless and explains why the scanner
|
||||||
# is always slow XD
|
# is always slow XD
|
||||||
# '293', # Trade count for day
|
# '293', # Trade count for day
|
||||||
'294', # Trade rate / minute
|
# '294', # Trade rate / minute
|
||||||
'295', # Vlm rate / minute
|
# '295', # Vlm rate / minute
|
||||||
),
|
),
|
||||||
contract: Contract | None = None,
|
contract: Contract | None = None,
|
||||||
|
|
||||||
|
@ -915,9 +915,13 @@ async def stream_quotes(
|
||||||
|
|
||||||
if first_ticker:
|
if first_ticker:
|
||||||
first_quote: dict = normalize(first_ticker)
|
first_quote: dict = normalize(first_ticker)
|
||||||
log.info(
|
|
||||||
'Rxed init quote:\n'
|
# TODO: we need a stack-oriented log levels filters for
|
||||||
f'{pformat(first_quote)}'
|
# this!
|
||||||
|
# log.info(message, filter={'stack': 'live_feed'}) ?
|
||||||
|
log.runtime(
|
||||||
|
'Rxed init quote:\n\n'
|
||||||
|
f'{pformat(first_quote)}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
# NOTE: it might be outside regular trading hours for
|
# NOTE: it might be outside regular trading hours for
|
||||||
|
@ -969,7 +973,11 @@ async def stream_quotes(
|
||||||
raise_on_timeout=True,
|
raise_on_timeout=True,
|
||||||
)
|
)
|
||||||
first_quote: dict = normalize(first_ticker)
|
first_quote: dict = normalize(first_ticker)
|
||||||
log.info(
|
|
||||||
|
# TODO: we need a stack-oriented log levels filters for
|
||||||
|
# this!
|
||||||
|
# log.info(message, filter={'stack': 'live_feed'}) ?
|
||||||
|
log.runtime(
|
||||||
'Rxed init quote:\n'
|
'Rxed init quote:\n'
|
||||||
f'{pformat(first_quote)}'
|
f'{pformat(first_quote)}'
|
||||||
)
|
)
|
||||||
|
|
|
@ -31,7 +31,11 @@ from typing import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from bidict import bidict
|
from bidict import bidict
|
||||||
import pendulum
|
from pendulum import (
|
||||||
|
DateTime,
|
||||||
|
parse,
|
||||||
|
from_timestamp,
|
||||||
|
)
|
||||||
from ib_insync import (
|
from ib_insync import (
|
||||||
Contract,
|
Contract,
|
||||||
Commodity,
|
Commodity,
|
||||||
|
@ -66,10 +70,11 @@ tx_sort: Callable = partial(
|
||||||
iter_by_dt,
|
iter_by_dt,
|
||||||
parsers={
|
parsers={
|
||||||
'dateTime': parse_flex_dt,
|
'dateTime': parse_flex_dt,
|
||||||
'datetime': pendulum.parse,
|
'datetime': parse,
|
||||||
# for some some fucking 2022 and
|
|
||||||
# back options records...fuck me.
|
# XXX: for some some fucking 2022 and
|
||||||
'date': pendulum.parse,
|
# back options records.. f@#$ me..
|
||||||
|
'date': parse,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,15 +94,38 @@ def norm_trade(
|
||||||
|
|
||||||
conid: int = str(record.get('conId') or record['conid'])
|
conid: int = str(record.get('conId') or record['conid'])
|
||||||
bs_mktid: str = str(conid)
|
bs_mktid: str = str(conid)
|
||||||
comms = record.get('commission')
|
|
||||||
if comms is None:
|
|
||||||
comms = -1*record['ibCommission']
|
|
||||||
|
|
||||||
price = record.get('price') or record['tradePrice']
|
# NOTE: sometimes weird records (like BTTX?)
|
||||||
|
# have no field for this?
|
||||||
|
comms: float = -1 * (
|
||||||
|
record.get('commission')
|
||||||
|
or record.get('ibCommission')
|
||||||
|
or 0
|
||||||
|
)
|
||||||
|
if not comms:
|
||||||
|
log.warning(
|
||||||
|
'No commissions found for record?\n'
|
||||||
|
f'{pformat(record)}\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
price: float = (
|
||||||
|
record.get('price')
|
||||||
|
or record.get('tradePrice')
|
||||||
|
)
|
||||||
|
if price is None:
|
||||||
|
log.warning(
|
||||||
|
'No `price` field found in record?\n'
|
||||||
|
'Skipping normalization..\n'
|
||||||
|
f'{pformat(record)}\n'
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
# the api doesn't do the -/+ on the quantity for you but flex
|
# the api doesn't do the -/+ on the quantity for you but flex
|
||||||
# records do.. are you fucking serious ib...!?
|
# records do.. are you fucking serious ib...!?
|
||||||
size = record.get('quantity') or record['shares'] * {
|
size: float|int = (
|
||||||
|
record.get('quantity')
|
||||||
|
or record['shares']
|
||||||
|
) * {
|
||||||
'BOT': 1,
|
'BOT': 1,
|
||||||
'SLD': -1,
|
'SLD': -1,
|
||||||
}[record['side']]
|
}[record['side']]
|
||||||
|
@ -128,26 +156,31 @@ def norm_trade(
|
||||||
# otype = tail[6]
|
# otype = tail[6]
|
||||||
# strike = tail[7:]
|
# strike = tail[7:]
|
||||||
|
|
||||||
print(f'skipping opts contract {symbol}')
|
log.warning(
|
||||||
|
f'Skipping option contract -> NO SUPPORT YET!\n'
|
||||||
|
f'{symbol}\n'
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# timestamping is way different in API records
|
# timestamping is way different in API records
|
||||||
dtstr = record.get('datetime')
|
dtstr: str = record.get('datetime')
|
||||||
date = record.get('date')
|
date: str = record.get('date')
|
||||||
flex_dtstr = record.get('dateTime')
|
flex_dtstr: str = record.get('dateTime')
|
||||||
|
|
||||||
if dtstr or date:
|
if dtstr or date:
|
||||||
dt = pendulum.parse(dtstr or date)
|
dt: DateTime = parse(dtstr or date)
|
||||||
|
|
||||||
elif flex_dtstr:
|
elif flex_dtstr:
|
||||||
# probably a flex record with a wonky non-std timestamp..
|
# probably a flex record with a wonky non-std timestamp..
|
||||||
dt = parse_flex_dt(record['dateTime'])
|
dt: DateTime = parse_flex_dt(record['dateTime'])
|
||||||
|
|
||||||
# special handling of symbol extraction from
|
# special handling of symbol extraction from
|
||||||
# flex records using some ad-hoc schema parsing.
|
# flex records using some ad-hoc schema parsing.
|
||||||
asset_type: str = record.get(
|
asset_type: str = (
|
||||||
'assetCategory'
|
record.get('assetCategory')
|
||||||
) or record.get('secType', 'STK')
|
or record.get('secType')
|
||||||
|
or 'STK'
|
||||||
|
)
|
||||||
|
|
||||||
if (expiry := (
|
if (expiry := (
|
||||||
record.get('lastTradeDateOrContractMonth')
|
record.get('lastTradeDateOrContractMonth')
|
||||||
|
@ -357,6 +390,7 @@ def norm_trade_records(
|
||||||
if txn is None:
|
if txn is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# inject txns sorted by datetime
|
||||||
insort(
|
insort(
|
||||||
records,
|
records,
|
||||||
txn,
|
txn,
|
||||||
|
@ -405,7 +439,7 @@ def api_trades_to_ledger_entries(
|
||||||
txn_dict[attr_name] = val
|
txn_dict[attr_name] = val
|
||||||
|
|
||||||
tid = str(txn_dict['execId'])
|
tid = str(txn_dict['execId'])
|
||||||
dt = pendulum.from_timestamp(txn_dict['time'])
|
dt = from_timestamp(txn_dict['time'])
|
||||||
txn_dict['datetime'] = str(dt)
|
txn_dict['datetime'] = str(dt)
|
||||||
acctid = accounts[txn_dict['acctNumber']]
|
acctid = accounts[txn_dict['acctNumber']]
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,10 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
|
||||||
break
|
break
|
||||||
|
|
||||||
ib_client = proxy._aio_ns.ib
|
ib_client = proxy._aio_ns.ib
|
||||||
log.info(f'Using {ib_client} for symbol search')
|
log.info(
|
||||||
|
f'Using API client for symbol-search\n'
|
||||||
|
f'{ib_client}\n'
|
||||||
|
)
|
||||||
|
|
||||||
last = time.time()
|
last = time.time()
|
||||||
async for pattern in stream:
|
async for pattern in stream:
|
||||||
|
@ -294,7 +297,7 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
|
||||||
elif stock_results:
|
elif stock_results:
|
||||||
break
|
break
|
||||||
# else:
|
# else:
|
||||||
await tractor.pause()
|
# await tractor.pause()
|
||||||
|
|
||||||
# # match against our ad-hoc set immediately
|
# # match against our ad-hoc set immediately
|
||||||
# adhoc_matches = fuzzy.extract(
|
# adhoc_matches = fuzzy.extract(
|
||||||
|
@ -522,7 +525,21 @@ async def get_mkt_info(
|
||||||
venue = con.primaryExchange or con.exchange
|
venue = con.primaryExchange or con.exchange
|
||||||
|
|
||||||
price_tick: Decimal = Decimal(str(details.minTick))
|
price_tick: Decimal = Decimal(str(details.minTick))
|
||||||
# price_tick: Decimal = Decimal('0.01')
|
ib_min_tick_gt_2: Decimal = Decimal('0.01')
|
||||||
|
if (
|
||||||
|
price_tick < ib_min_tick_gt_2
|
||||||
|
):
|
||||||
|
# TODO: we need to add some kinda dynamic rounding sys
|
||||||
|
# to our MktPair i guess?
|
||||||
|
# not sure where the logic should sit, but likely inside
|
||||||
|
# the `.clearing._ems` i suppose...
|
||||||
|
log.warning(
|
||||||
|
'IB seems to disallow a min price tick < 0.01 '
|
||||||
|
'when the price is > 2.0..?\n'
|
||||||
|
f'Decreasing min tick precision for {fqme} to 0.01'
|
||||||
|
)
|
||||||
|
# price_tick = ib_min_tick
|
||||||
|
# await tractor.pause()
|
||||||
|
|
||||||
if atype == 'stock':
|
if atype == 'stock':
|
||||||
# XXX: GRRRR they don't support fractional share sizes for
|
# XXX: GRRRR they don't support fractional share sizes for
|
||||||
|
|
Loading…
Reference in New Issue