Split client.py into session, account, orders and push layers (no behaviour change) - #4
Merged
Merged
Conversation
client.py held HTTP plumbing, login and keepalive, account reads, order placement and the Push API in one 1,430-line class. It is now a stack of layers on the same object, one module each: _session.py HTTP, error mapping, login/logout/ping, keepalive, re-login _account.py account discovery, balance, positions, orders, history _orders.py place/modify/cancel/close, IF-THEN SL/TP groups _push.py websocket channels, subscriptions, message routing _state.py the shared attributes, declared once so each layer type-checks client.py DXTradeClient: constructor, repr, context manager Method bodies moved unchanged except one layering fix: the session layer's logout() no longer calls the push layer; _PushLayer.logout() closes the channels and then calls super(), in the same order as before. DXTradeClient, parse_interval and _PushChannel still import from dxtrade_wrapper.client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bogzx
changed the base branch from
improve/2026-10-01-pypi-release-prep
to
main
October 1, 2026 13:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #3. Merge #3 first. If GitHub doesn't retarget this PR automatically after #3 merges, run
gh pr edit 4 --base main.Splits the 1,430-line
client.pyinto layered modules. No behaviour change.Why
client.pywas a single class holding the HTTP plumbing and error mapping, login, keepalive and re-login, account reads, order placement (including IF-THEN SL/TP groups and conditional modify) and the Push API with its channel class. Reviewing or changing any one of these meant reading all of it.What changed
The client is now a stack of layers that all operate on the same object, one module each:
_session.py_SessionLayer_url,_request, error mapping,login/logout/ping, keepalive, re-login,parse_interval_account.py_AccountLayerget_accounts,get_balance,get_positions,get_orders,get_order_history, …_orders.py_OrdersLayerplace_order,modify_order,cancel_order,close_position,close_all,modify_position_sl_tp_push.py_PushLayer,_PushChannel_state.py_ClientStateclient.pyDXTradeClientrepr, context manager; re-exportsparse_intervaland_PushChannellogout()used to calldisconnect_websocket()from the push layer. Now_PushLayer.logout()closes the channels and then callssuper().logout(), in the same order as before.tests/test_session.pypatchestime.sleepthroughdxtrade_wrapper._sessioninstead ofdxtrade_wrapper.client. That patches the same globaltimemodule.Verification
python -m pytest -q: 127 passed, 13 skipped, the same as Prepare 0.2.0 for PyPI: self-contained sdist, settled public API, Trusted Publishing release workflow #3.DXTRADE_SPEC_TESTS=1 pytest tests/test_spec_conformance.py: 13 passed.ruff: clean.mypy dxtrade_wrapper: no issues in 9 files.client.py:is_authenticated,_ws_connected) have byte-identical source;logout, now split across two layers.examples/offline_demo.pyruns end to end and issues the same 11 requests as before.python -m buildthentwine check --strict: PASSED. The wheel contains all new modules pluspy.typed.🤖 Generated with Claude Code