Skip to content

fix: declare OmsEngine-delegated methods on MainEngine - #39

Open
Dhiyaahaq33 wants to merge 1 commit into
51bitquant:masterfrom
Dhiyaahaq33:fix-get-contract
Open

fix: declare OmsEngine-delegated methods on MainEngine#39
Dhiyaahaq33 wants to merge 1 commit into
51bitquant:masterfrom
Dhiyaahaq33:fix-get-contract

Conversation

@Dhiyaahaq33

@Dhiyaahaq33 Dhiyaahaq33 commented Jul 19, 2026

Copy link
Copy Markdown

Summary

Fixes #30Unresolved attribute reference 'get_contract' for class MainEngine.

This is not a runtime crash: OmsEngine.add_function() assigns
get_tick/get_position/get_account/get_contract/get_all_positions/
get_all_accounts/get_all_contracts/get_all_active_orders/get_active_order
directly onto MainEngine instances at runtime, so calls like
self.main_engine.get_contract(...) (engine.py:820 and a couple other
call sites) do work at runtime. But since these attributes are never
declared on the MainEngine class 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 existing
get_engine() lookup, with the same signatures OmsEngine already
uses. This is purely additive:

  • OmsEngine.add_function() is untouched, so its instance-level
    assignment still takes precedence at runtime exactly as before
    (verified — see Testing).
  • The new class methods only kick in as a fallback if one of these is
    ever called before OmsEngine has been added, in which case they
    now return None/[] via get_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:

  • Instantiated MainEngine() and called get_contract, get_tick,
    get_all_contracts — all resolve without AttributeError.
  • Confirmed get_contract is still bound to OmsEngine.get_contract
    at the instance level after construction (i.e. the existing
    monkey-patch still wins), proving behavior is unchanged.

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.
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.

Unresolved attribute reference 'get_contract' for class MainEngine

1 participant