ib: finally convert ledger processing to use `MktPair`
parent
6008497b89
commit
d1cf90e2ae
|
@ -55,6 +55,8 @@ import pendulum
|
||||||
|
|
||||||
from piker import config
|
from piker import config
|
||||||
from piker.accounting import (
|
from piker.accounting import (
|
||||||
|
dec_digits,
|
||||||
|
digits_to_dec,
|
||||||
Position,
|
Position,
|
||||||
Transaction,
|
Transaction,
|
||||||
open_trade_ledger,
|
open_trade_ledger,
|
||||||
|
@ -73,8 +75,8 @@ from piker.clearing._messages import (
|
||||||
BrokerdFill,
|
BrokerdFill,
|
||||||
BrokerdError,
|
BrokerdError,
|
||||||
)
|
)
|
||||||
from piker.accounting._mktinfo import (
|
from piker.accounting import (
|
||||||
Symbol,
|
MktPair,
|
||||||
)
|
)
|
||||||
from .api import (
|
from .api import (
|
||||||
_accounts2clients,
|
_accounts2clients,
|
||||||
|
@ -433,7 +435,7 @@ async def update_and_audit_msgs(
|
||||||
# raise ValueError(
|
# raise ValueError(
|
||||||
log.error(
|
log.error(
|
||||||
f'UNEXPECTED POSITION says IB:\n'
|
f'UNEXPECTED POSITION says IB:\n'
|
||||||
'Maybe they LIQUIDATED YOU or your missing ledger records?\n'
|
'Maybe they LIQUIDATED YOU or are missing ledger txs?\n'
|
||||||
f'PIKER:\n{pikerfmtmsg}\n\n'
|
f'PIKER:\n{pikerfmtmsg}\n\n'
|
||||||
)
|
)
|
||||||
msgs.append(msg)
|
msgs.append(msg)
|
||||||
|
@ -1203,48 +1205,38 @@ def norm_trade_records(
|
||||||
if asset_type == 'FUT':
|
if asset_type == 'FUT':
|
||||||
# (flex) ledger entries don't have any simple 3-char key?
|
# (flex) ledger entries don't have any simple 3-char key?
|
||||||
symbol = record['symbol'][:3]
|
symbol = record['symbol'][:3]
|
||||||
|
asset_type: str = 'future'
|
||||||
|
|
||||||
|
elif asset_type == 'STK':
|
||||||
|
asset_type: str = 'stock'
|
||||||
|
|
||||||
# try to build out piker fqsn from record.
|
# try to build out piker fqsn from record.
|
||||||
expiry = record.get(
|
expiry = (
|
||||||
'lastTradeDateOrContractMonth') or record.get('expiry')
|
record.get('lastTradeDateOrContractMonth')
|
||||||
|
or record.get('expiry')
|
||||||
|
)
|
||||||
|
|
||||||
if expiry:
|
if expiry:
|
||||||
expiry = str(expiry).strip(' ')
|
expiry = str(expiry).strip(' ')
|
||||||
suffix = f'{exch}.{expiry}'
|
suffix = f'{exch}.{expiry}'
|
||||||
expiry = pendulum.parse(expiry)
|
expiry = pendulum.parse(expiry)
|
||||||
|
|
||||||
# src: str = record['currency']
|
# src: str = record['currency']
|
||||||
|
price_tick: Decimal = digits_to_dec(dec_digits(price))
|
||||||
|
|
||||||
# price_tick_digits = float_digits(price)
|
pair = MktPair.from_fqme(
|
||||||
tick_size = Decimal(
|
fqme=f'{symbol}.{suffix}.ib',
|
||||||
Decimal(10)**Decimal(str(price)).as_tuple().exponent
|
bs_mktid=str(conid),
|
||||||
)
|
_atype=asset_type,
|
||||||
|
|
||||||
# TODO: convert to MktPair!!!
|
|
||||||
pair = Symbol.from_fqsn(
|
|
||||||
fqsn=f'{symbol}.{suffix}.ib',
|
|
||||||
info={
|
|
||||||
'tick_size': tick_size,
|
|
||||||
|
|
||||||
|
price_tick=price_tick,
|
||||||
# NOTE: for "legacy" assets, volume is normally discreet, not
|
# NOTE: for "legacy" assets, volume is normally discreet, not
|
||||||
# a float, but we keep a digit in case the suitz decide
|
# a float, but we keep a digit in case the suitz decide
|
||||||
# to get crazy and change it; we'll be kinda ready
|
# to get crazy and change it; we'll be kinda ready
|
||||||
# schema-wise..
|
# schema-wise..
|
||||||
'lot_tick_size': 0.0,
|
size_tick='1',
|
||||||
|
|
||||||
# TODO: remove when we switching from
|
|
||||||
# ``Symbol`` -> ``MktPair``
|
|
||||||
'asset_type': asset_type,
|
|
||||||
|
|
||||||
# # TODO: figure out a target fin-type name
|
|
||||||
# # set and normalize to that here!
|
|
||||||
# 'dst_type': asset_type.lower(),
|
|
||||||
|
|
||||||
# # starting to use new key naming as in ``MktPair``
|
|
||||||
# # type have drafted...
|
|
||||||
# 'src': src,
|
|
||||||
# 'src_type': 'fiat',
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fqme = pair.fqme
|
fqme = pair.fqme
|
||||||
|
|
||||||
# NOTE: for flex records the normal fields for defining an fqme
|
# NOTE: for flex records the normal fields for defining an fqme
|
||||||
|
|
Loading…
Reference in New Issue