Is there an example for implementing websocket example?
vladblaj opened this issue · 14 comments
Where exactly do I need to handle the update function? Do you simply do it in binance.go for example in subscribeMarketSummaryFeed?
check examples folder. I would say no
yea onUpdate works well for interval but not sure where to handle onUpdate in websockets cause it is not called. Do you simply add you logic in subscribeMarketSummaryFeed?
Nope, that's the wrong way to resolve this ;)
REST and Websocket make no difference in strategy object usage, you do not see it used because it is wrapped by Strategy.Apply
from here
golang-crypto-trading-bot/strategies/websocket.go
Lines 36 to 41 in b0c20d4
So your setup function must call FeedConnect()
to enable websockets, after that just Use the normal Update func
reference on why it works can be extracted from following lines
golang-crypto-trading-bot/exchanges/binance.go
Lines 84 to 92 in b0c20d4
Like from the example
golang-crypto-trading-bot/examples/websocket.go
Lines 39 to 42 in b0c20d4
The fact that is not printed every second may depend on your internet connection. Can you double check that ?
Also try removing the go func()
I solved the issue using channels. It is not printed every second because it is printed hundred of times per second because of the non blocking for. Could you please show me for websocket strategy where exactly is the onUpdate called?.
The secret is the websocket part, the o update is run in the Apply method of Strategy implementation
It is complex to explain, but if you have websockets the population of wrapped structures is done on the fly by the subscribe functions.
I think the question from @vladblaj is still valid.
@saniales in websocket.go, what do you mean by "update is handled by the developer externally" in:
// update is handled by the developer externally, here we just checked for existence.
if !hasUpdateFunc {
_err := errors.New("OnUpdate func cannot be empty")
if hasErrorFunc {
wss.Model.OnError(_err)
} else {
panic(_err)
}
}
Hello @hmedkouri
the update function is decided by the developer strategy, not by the bot itself (the bot only updates the data when the new information comes, but it is up to the strategy, hence the "OnUpdate" function to actually do something)
That is what I meant, do you think we can rephrase it better?
I don't know about your solutions, but I broke my brain.
Just show a working example how to subscribe to changes in summaries and orderbook cache or where I have to put my own for {}
.
Because all my attempts always end up the same way:
- no OnUpdate call
- the bot just says "bye"
Sorry, but there is no crystal clean (for understanding) example of ws strategy.
you have to pass the OnUpdate function as you would do without websockets, nothing changes, you just add the ws connection before initializing the bot