Are global variables the best way to use data outside of the msg in the trading strategy?
Opened this issue · 3 comments
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?
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!
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! 😄 )
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. (: