btschwertfeger / KrakenEx.jl

Julia Package to interact with the Kraken Cryptocurrency Exchange API for both Spot and Futures, REST and Websocket endpoints.
https://btschwertfeger.github.io/KrakenEx.jl/
GNU General Public License v3.0
2 stars 1 forks source link

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

Open Phionx opened 1 year ago

Phionx commented 1 year ago

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 commented 1 year ago

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!

Phionx commented 1 year ago

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 commented 1 year ago

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. (: