Add custom event with msgbus example #2400
Merged
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.
Pull Request
New tutorial style example for beginners -Hhow to use: Custom event with msgbus.
Thing to note:
I have used standard
@dataclass
and it works without visible problems.Is that OK, or is there any motivation and benefits using
@customdataclass
instead.As it is now in the example, probably no data are serialized (they live just in memory),
so this implementation looks like a quick & easy way how to publish/subscribe data/events,
when there is no need for serialization... (or is it always required to handle serialization in all cases?)
I got some hints from @faysou , that
@customdataclass
should be used to allow serializationlike here: https://nautilustrader.io/docs/nightly/concepts/data/#option-greeks-example,
but is this increased complexity always required, or is it completely OK use this lightweight
version and having simple code, when we don't expect any serialization in our strategy?
In this example, I inherited from
nautilus_trader.core.message.Event
.nautilus_trader.core.Data
?Just asking, to understand if there are some strong requirements (or reasonable recommendations) how to interact with msgbus, or we can simply publish/subscribe to the msgbus what-ever object we want (no need for any subclass).
After testing it, it looks there is really no need to subclass anything and strategy still works great! 😊
Type of change
New example added.
How has this change been tested?
✅ Strategy generates expected output in Terminal
✅ pre-commit passed