Use `ppfmt()` in EMS and guard `brokerd_msg` set
Replace all `pformat()` calls with `ppfmt()` from `tractor.devx.pformat` and drop the `pprint` import. Guard `status_msg.brokerd_msg = msg` with an `if not` check to avoid clobbering a value already set by earlier processing. Also, - Add `!r` to `broker` in a couple log msgs. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codepy_codestyling
parent
5387538ba9
commit
c5fa262474
|
|
@ -26,7 +26,6 @@ from collections import (
|
||||||
from contextlib import asynccontextmanager as acm
|
from contextlib import asynccontextmanager as acm
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from math import isnan
|
from math import isnan
|
||||||
from pprint import pformat
|
|
||||||
from time import time_ns
|
from time import time_ns
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import (
|
from typing import (
|
||||||
|
|
@ -43,6 +42,7 @@ import trio
|
||||||
from trio_typing import TaskStatus
|
from trio_typing import TaskStatus
|
||||||
import tractor
|
import tractor
|
||||||
from tractor import trionics
|
from tractor import trionics
|
||||||
|
from tractor.devx.pformat import ppfmt
|
||||||
|
|
||||||
from ._util import (
|
from ._util import (
|
||||||
log, # sub-sys logger
|
log, # sub-sys logger
|
||||||
|
|
@ -490,7 +490,7 @@ async def open_brokerd_dialog(
|
||||||
msg = BrokerdPosition(**msg)
|
msg = BrokerdPosition(**msg)
|
||||||
log.info(
|
log.info(
|
||||||
f'loading pp for {brokermod.__name__}:\n'
|
f'loading pp for {brokermod.__name__}:\n'
|
||||||
f'{pformat(msg.to_dict())}',
|
f'{ppfmt(msg.to_dict())}',
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: state any mismatch here?
|
# TODO: state any mismatch here?
|
||||||
|
|
@ -840,7 +840,7 @@ async def translate_and_relay_brokerd_events(
|
||||||
|
|
||||||
brokerd_msg: dict[str, Any]
|
brokerd_msg: dict[str, Any]
|
||||||
async for brokerd_msg in brokerd_trades_stream:
|
async for brokerd_msg in brokerd_trades_stream:
|
||||||
fmsg = pformat(brokerd_msg)
|
fmsg = ppfmt(brokerd_msg)
|
||||||
log.info(
|
log.info(
|
||||||
f'Rx brokerd trade msg:\n'
|
f'Rx brokerd trade msg:\n'
|
||||||
f'{fmsg}'
|
f'{fmsg}'
|
||||||
|
|
@ -1039,7 +1039,8 @@ async def translate_and_relay_brokerd_events(
|
||||||
)
|
)
|
||||||
|
|
||||||
status_msg.reqid = reqid # THIS LINE IS CRITICAL!
|
status_msg.reqid = reqid # THIS LINE IS CRITICAL!
|
||||||
status_msg.brokerd_msg = msg
|
if not status_msg.brokerd_msg:
|
||||||
|
status_msg.brokerd_msg = msg
|
||||||
status_msg.src = msg.broker_details['name']
|
status_msg.src = msg.broker_details['name']
|
||||||
|
|
||||||
if not status_msg.req:
|
if not status_msg.req:
|
||||||
|
|
@ -1072,7 +1073,7 @@ async def translate_and_relay_brokerd_events(
|
||||||
else: # open
|
else: # open
|
||||||
# relayed from backend but probably not handled so
|
# relayed from backend but probably not handled so
|
||||||
# just log it
|
# just log it
|
||||||
log.info(f'{broker} opened order {msg}')
|
log.info(f'{broker!r} opened order {msg}')
|
||||||
|
|
||||||
# BrokerdFill
|
# BrokerdFill
|
||||||
case {
|
case {
|
||||||
|
|
@ -1185,7 +1186,7 @@ async def translate_and_relay_brokerd_events(
|
||||||
}:
|
}:
|
||||||
msg = (
|
msg = (
|
||||||
f'Unhandled broker status for dialog {reqid}:\n'
|
f'Unhandled broker status for dialog {reqid}:\n'
|
||||||
f'{pformat(brokerd_msg)}'
|
f'{ppfmt(brokerd_msg)}'
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
oid := book._ems2brokerd_ids.inverse.get(reqid)
|
oid := book._ems2brokerd_ids.inverse.get(reqid)
|
||||||
|
|
@ -1194,7 +1195,7 @@ async def translate_and_relay_brokerd_events(
|
||||||
# clearable limits..
|
# clearable limits..
|
||||||
if status_msg := book._active.get(oid):
|
if status_msg := book._active.get(oid):
|
||||||
msg += (
|
msg += (
|
||||||
f'last status msg: {pformat(status_msg)}\n\n'
|
f'last status msg: {ppfmt(status_msg)}\n\n'
|
||||||
f'this msg:{fmsg}\n'
|
f'this msg:{fmsg}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1233,7 +1234,7 @@ async def process_client_order_cmds(
|
||||||
async for cmd in client_order_stream:
|
async for cmd in client_order_stream:
|
||||||
log.info(
|
log.info(
|
||||||
f'Received order cmd:\n'
|
f'Received order cmd:\n'
|
||||||
f'{pformat(cmd)}\n'
|
f'{ppfmt(cmd)}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
# CAWT DAMN we need struct support!
|
# CAWT DAMN we need struct support!
|
||||||
|
|
@ -1398,8 +1399,8 @@ async def process_client_order_cmds(
|
||||||
# handle relaying the ems side responses back to
|
# handle relaying the ems side responses back to
|
||||||
# the client/cmd sender from this request
|
# the client/cmd sender from this request
|
||||||
log.info(
|
log.info(
|
||||||
f'Sending live order to {broker}:\n'
|
f'Sending live order to {broker!r}:\n'
|
||||||
f'{pformat(msg)}'
|
f'{ppfmt(msg)}'
|
||||||
)
|
)
|
||||||
|
|
||||||
await brokerd_order_stream.send(msg)
|
await brokerd_order_stream.send(msg)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue