fix: declare OmsEngine-delegated methods on MainEngine - #39
Open
Dhiyaahaq33 wants to merge 1 commit into
Open
Conversation
Fixes 51bitquant#30. get_tick/get_position/get_account/get_contract/ get_all_positions/get_all_accounts/get_all_contracts/ get_all_active_orders/get_active_order were only ever assigned onto MainEngine instances at runtime by OmsEngine.add_function(), never declared on the class itself. That's why IDEs/static analyzers flag "Unresolved attribute reference" for e.g. get_contract at engine.py:820 even though the code runs fine. Add proper method declarations on MainEngine that delegate to the "oms" engine via get_engine(), matching OmsEngine's existing method signatures. OmsEngine's instance-level assignment still takes precedence at runtime (confirmed via manual test), so behavior is unchanged - this only makes the attribute visible to tooling and adds a safe fallback if get_contract etc. are ever called before OmsEngine has registered.
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
Fixes #30 —
Unresolved attribute reference 'get_contract' for class MainEngine.This is not a runtime crash:
OmsEngine.add_function()assignsget_tick/get_position/get_account/get_contract/get_all_positions/get_all_accounts/get_all_contracts/get_all_active_orders/get_active_orderdirectly onto
MainEngineinstances at runtime, so calls likeself.main_engine.get_contract(...)(engine.py:820 and a couple othercall sites) do work at runtime. But since these attributes are never
declared on the
MainEngineclass itself, static analyzers/IDEs (e.g.PyCharm, which is what raises "Unresolved attribute reference") can't
see them.
This PR adds proper method declarations for all nine of these on
MainEngine, delegating to the"oms"engine via the existingget_engine()lookup, with the same signaturesOmsEnginealreadyuses. This is purely additive:
OmsEngine.add_function()is untouched, so its instance-levelassignment still takes precedence at runtime exactly as before
(verified — see Testing).
ever called before
OmsEnginehas been added, in which case theynow return
None/[]viaget_engine()'s existing "Missing Engine"log path instead of raising
AttributeError.Testing
Since this module has no exchange/network dependency at construction
time, I was able to import and run it directly:
MainEngine()and calledget_contract,get_tick,get_all_contracts— all resolve withoutAttributeError.get_contractis still bound toOmsEngine.get_contractat the instance level after construction (i.e. the existing
monkey-patch still wins), proving behavior is unchanged.