-
Notifications
You must be signed in to change notification settings - Fork 661
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
How to re-run websocket if it down #384
Comments
cc @adshao |
Can we use |
This is my err log:
|
In another way, we could add one boolean arg to check whether it should continue when it occurs an error. |
It's impossible to break the loop if we use |
@Icarus9913 your errHandler function should "handle" the error. If you want to reconnect immediately, just reconnect it while handling error. Here is an example function:
|
I used it with a channel wrapper, when it disconnects I use a backoff retry: func (b *Binance) CandlesSubscription(ctx context.Context, pair, period string) (chan model.Candle, chan error) {
ccandle := make(chan model.Candle)
cerr := make(chan error)
go func() {
ba := &backoff.Backoff{
Min: 100 * time.Millisecond,
Max: 1 * time.Second,
}
for {
done, _, err := binance.WsKlineServe(pair, period, func(event *binance.WsKlineEvent) {
ba.Reset()
candle := CandleFromWsKline(pair, event.Kline)
ccandle <- candle
}, func(err error) {
cerr <- err
})
if err != nil {
cerr <- err
close(cerr)
close(ccandle)
return
}
select {
case <-ctx.Done():
close(cerr)
close(ccandle)
return
case <-done:
time.Sleep(ba.Duration())
}
}
}()
return ccandle, cerr
} The final usage will looks like: candles, _ := binance.CandlesSubscription(ctx, "BTCUSDT", "1h")
for candle := range candles {
// your logic here
} |
No response for a long time, close this issue |
I found you use for loop to traverse. But once it meet err the whole websokcetTick will down.
In this situation, how can we run it gain?
go-binance/v2/futures/websocket.go
Lines 54 to 63 in 7742592
The text was updated successfully, but these errors were encountered: