Skip to content

Fail-soft on unknown template ids + map template 358 (AccountRmsUpdates) - #67

Open
aktiwers wants to merge 1 commit into
rundef:mainfrom
aktiwers:fix/unknown-template-358
Open

Fail-soft on unknown template ids + map template 358 (AccountRmsUpdates)#67
aktiwers wants to merge 1 commit into
rundef:mainfrom
aktiwers:fix/unknown-template-358

Conversation

@aktiwers

Copy link
Copy Markdown

Fixes #66.

The order plant floods the logs with ERROR tracebacks (Unknown template ID: 358) when Rithmic pushes a message type the library does not map. This PR has two parts that stand independently.

1. Fail-soft on unmapped template ids

BasePlant._convert_bytes_to_response raised Exception(f"Unknown template ID: {template_id}") for any template id missing from TEMPLATES_MAP. That exception is caught by the read/process loop and logged via logger.exception(...), so a single recurring unmapped message type produces a full traceback for every message and drowns out real errors.

It now:

  • warns once per template id (dedupe set on the plant instance) and returns None,
  • and the read loops (_process_loop in background_task_mixin.py and the inline loop in _send_and_recv_immediate) skip a None response and continue.

This half is safe regardless of what template 358 actually is — it just stops one unhandled message type from flooding the logs.

2. Map template 358 → AccountRmsUpdates

account_rms_updates_pb2.AccountRmsUpdates is already vendored in protocol_buffers/ but was never registered in TEMPLATES_MAP. This adds:

  • 358: pb.account_rms_updates_pb2.AccountRmsUpdates to TEMPLATES_MAP,
  • a dispatch branch in OrderPlant._process_response firing a new on_account_rms_update client event, mirroring how on_bracket_update (353) is wired.

On the 358 == AccountRmsUpdates mapping: this is verified circumstantially, not from an official Rithmic spec. On a live Rithmic paper session the template-358 frames decode cleanly against AccountRmsUpdates (the RMS fields — auto-liquidation thresholds, buying power, etc. — populate correctly), and 358 sits in the order-plant notification range right after the 350–353 notifications. If you'd rather not commit to the mapping without an official reference, the fail-soft half (part 1) resolves the log-flood on its own and I'm happy to split this into two PRs — just let me know your preference.

Tests

Added tests/test_unknown_template.py (matches the existing plant-mock idiom):

  • an unmapped template id yields a single warning, no raise, None return, and the process loop keeps dispatching subsequent messages;
  • a 358 frame decodes to AccountRmsUpdates and fires on_account_rms_update.

Full suite: 30 passed locally (27 pre-existing + 3 new) via PYTHONPATH=. pytest tests on Python 3.12. No live credentials required — everything runs against the existing offline mocks.

Two related changes to the order plant message handling:

1. Fail-soft on unmapped template ids. `_convert_bytes_to_response` used to
   `raise Exception("Unknown template ID: ...")` for any template id missing
   from `TEMPLATES_MAP`. In the read/process loop that exception is caught and
   logged with a full traceback, so a single recurring unmapped message type
   floods the logs with ERROR tracebacks (see rundef#66). It now warns once per
   template id and returns None; the read loops skip a None response and keep
   going. One unknown message type can no longer drown out real errors.

2. Map template id 358 to AccountRmsUpdates and dispatch it through a new
   `on_account_rms_update` client event, mirroring how 351/352/353 are wired.

Adds tests covering: an unmapped template id yields a single warning and no
raise while the loop continues, and a 358 frame decodes to AccountRmsUpdates
and fires on_account_rms_update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Order plant floods logs with Unknown template ID: 358 once positions are open (unregistered AccountRmsUpdates?)

1 participant