Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom event with msgbus example #2400

Conversation

stefansimik
Copy link
Contributor

@stefansimik stefansimik commented Mar 3, 2025

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

  • Is that valid approach or is there some reason to inherit from nautilus_trader.core.Data?
  • Or what if we don't inherit from anything at all - I tested it and the strategy still works!

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

@stefansimik stefansimik force-pushed the example_custom_event_with_msgbus branch from 6d9f6dd to a7224d7 Compare March 3, 2025 12:09
@faysou
Copy link
Collaborator

faysou commented Mar 3, 2025

I suppose serialisation allows a message to be transported between nodes, but it's true that for simple cases and if you use the message bus directly there's no need for added complexity. Maybe @cjdsellers can comment on this.

@cjdsellers cjdsellers changed the title Add new example: Custom event with msgbus Add custom event with msgbus example Mar 3, 2025
@cjdsellers cjdsellers merged commit 10e8e65 into nautechsystems:develop Mar 3, 2025
12 checks passed
@stefansimik stefansimik deleted the example_custom_event_with_msgbus branch March 3, 2025 21:51
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.

3 participants