How Strategy Overrides Affect vn.py Trade Callbacks
Summary
This short forum exchange explains why a vn.py CTA strategy receives trade notifications through only one `on_trade` method when both the base template and the strategy define that callback. The strategy inherits from the template, and defining `on_trade` again in the subclass overrides the inherited method. As a result, the subclass method handles the callback; the base implementation is not automatically called as a second handler.
The practical lesson is to account for method overriding when organizing trade-event processing. If both the base class behavior and custom strategy behavior are needed, the developer must explicitly arrange for both to run, such as by calling the parent implementation from the override or delegating work to shared handlers. The exchange does not provide code for that arrangement, discuss callback ordering, or cover other vn.py event types, so those details require separate documentation.
Key ideas
- A strategy subclass that defines `on_trade` overrides the template’s inherited method.
- The base and strategy callbacks do not both run automatically as separate handlers.
- Developers who need both behaviors must explicitly invoke or delegate to the base behavior.
- The discussion is limited to trade callbacks and does not describe implementation details.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.