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

Are global variables the best way to use data outside of the msg in the trading strategy? #16

Open
Phionx opened this issue Jul 3, 2023 · 3 comments
Labels
Question General or specific questions without a direct need to apply a change.

Comments

@Phionx
Copy link

Phionx commented Jul 3, 2023

Hi,

Thanks for creating this awesome package!

What is the recommended way to use data from outside of the msg argument in the trading strategy within on_message?

https://docs.juliahub.com/KrakenEx/C18NY/0.1.0/spot/spot_examples/#Spot-WebSocket-Example

Currently, I am using type-annotated global variables which I access and update within the callback function, but that doesn't seem very performant. Is there a better way?

@btschwertfeger
Copy link
Owner

Hey @Phionx, nice to see that someone is actually using this tool!

To be honest, I haven't tried out much variants for accessing the contents of msg.

Could you provide an example which should be improved - or if you find some more efficient and straightforward way of implementing this (or any other) part - this project is open for contributions and I would be happy involve more developer into this project.

Have a nice day!

@btschwertfeger btschwertfeger added the Question General or specific questions without a direct need to apply a change. label Jul 4, 2023
@Phionx
Copy link
Author

Phionx commented Jul 4, 2023

Thanks for your response @btschwertfeger !

Hm, for example, how would you recommend I use data from previous messages in the trading strategy implemented in on_message?

It seems that currently the trading strategy would only rely on data within the current msg, but perhaps I'm missing something.

(Also, I'd love to contribute to this awesome project, just want to make sure I have a good understanding of the issue! 😄 )

@btschwertfeger
Copy link
Owner

The examples only serve as templates that can be used to implement custom strategies. The msg will always be some message that was sent by the Kraken API. The on_message function can't use return values, since it's a callback used internally - the only way to use/extract information that are stored (… or derived from) within msg is to use global variables like structures or some database that will be updated when some condition for msg is matching.

The on_message function is a kind of trigger that one can use to execute other functions like create_order, ... .

To not only rely on data from msg you can query more information at any time using the other functions provided by this tool - or you fill a database with incoming messages to perform analysis on that, create arrays, use the file system, trigger other functions for some condition.

There are a lot of possibilities. (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question General or specific questions without a direct need to apply a change.
Projects
None yet
Development

No branches or pull requests

2 participants