feat: resilience layer, streaming indicators, public types & cleanup - #90
Merged
Conversation
- Introduced tests for TTLCache to validate set/get, eviction, expiration, and parameter validation. - Added tests for dispatch table handlers in QuotexAPI to ensure proper event handling and state management. - Created tests for json_utils to verify serialization and deserialization functions. - Implemented tests for the reconnect policy and WebsocketClient to ensure resilience and subscription replay functionality. - Added tests for streaming indicators (SMA, EMA, RSI, Bollinger Bands) to validate their behavior and correctness. - Introduced tests for new public dataclasses in pyquotex.types, including Candle, TradeResult, Balance, ProfileInfo, AssetInfo, and ReconnectPolicy.
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.
Summary
Four orthogonal improvements landed together, each independently testable:
ReconnectPolicy+ auto-reconnect with exponential backoff, a stale-connection watchdog, and transparent subscription replay after every reconnect. Verified live: forced socket close → reconnected in 1.5s withcandle:EURUSD_otc:60subscription preserved._on_message), incremental streaming indicators (deque-based, O(1) per tick instead of O(n²)), opt-in TTL+LRU cache forget_candles(live: 396ms → 0.0ms on cached call), andorjsonreturningbytesdirectly on the hot path.py.typedmarker + frozen dataclasses:Candle,TradeResult,Balance,ProfileInfo,AssetInfo,ReconnectPolicy,Subscription. Re-exported frompyquotex.*so consumers get real autocomplete andmypy --strictcoverage.requirements.txtsynced withpyproject.toml(numpy removed; orjson documented as[fast]extra);OptimizedQuotexMixindeprecated and its two broken methods now delegate to the realTradingMixin;sell_optionpolling replaced withwait_until+ hard timeout (TODO closed).What's new for users
Streaming indicators for live tick loops:
Backward compatibility
Every previously public method/parameter is preserved. The public-surface
regression test (
tests/test_api_surface.py) was regenerated to include the newopt-in
use_cache=Falseparameter, so future shrinks are still caught.*_optimizedmethods continue to work; they now emitDeprecationWarning.ReconnectPolicy(enabled=False).binary_bot.py,trade_bot.py, etc.).Test plan
pytest tests/— 90 / 90 offline tests pass on Python 3.13tests/test_types.py— Candle/TradeResult/Balance/ProfileInfo/AssetInfo/ReconnectPolicy/Subscriptiontests/test_streaming_indicators.py— incremental SMA/EMA/RSI/Bollinger; cross-checked against batch implementationtests/test_cache.py— TTLCache LRU eviction, lazy expiration, containstests/test_json_utils.py— dumps/dumps_bytes/dumps_str roundtrips with both orjson and stdlib pathstests/test_dispatch_table.py— every_h_*control-event handler exercised directlytests/test_reconnect.py— fakeWebsocketClientwithConnectionClosed(1006)to verify backoff, replay, and clean closescripts/snapshot_api_surface.py)scripts/smoke_demo.py):Balance(DEMO): 10448.88 USDget_candles(use_cache=True): first call 396.5 ms → cached call 0.0 msCandle.from_dictconversion on live OHLC data['candle:EURUSD_otc:60']registered automaticallyopen_count=2)s_authorizationre-issued andinstruments/listreplayedasync with Quotex(...)) closes cleanlyFiles of note
pyquotex/types.pyReconnectPolicy/Subscriptionpyquotex/py.typedpyquotex/ws/client.pypyquotex/api.py_control_handlers), subscription tracking helperspyquotex/_api/history.pyget_candles(..., use_cache=True)opt-inpyquotex/_api/trading.pysell_optionmigrated from poll-loop towait_untilpyquotex/_api/realtime.pypyquotex/stable_api.pyreconnect_policy=kwarg +__aenter__/__aexit__pyquotex/utils/streaming_indicators.pyStreamingSMA/EMA/RSI/Bollinger(O(1)/tick)pyquotex/utils/cache.pyTTLCachepyquotex/utils/json_utils.pydumps_byteshot path,HAS_ORJSONflagpyquotex/utils/optimization.pyrequirements.txtpyproject.toml(numpy removed)tests/fixtures/api_surface.jsonscripts/smoke_demo.py