adshao / go-binance

A Go SDK for Binance API
MIT License
1.48k stars 662 forks source link

binance.WebsocketTimeout = time.Second * 5 Not working ! #557

Open QGB opened 2 months ago

QGB commented 2 months ago
var symbols = []string{
"ETHBTC","LTCBTC","BNBBTC","NEOBTC","QTUMETH","EOSETH","SNTETH","BNTETH","GASBTC","BNBETH","BTCUSDT","ETHUSDT","LRCBTC","LRCETH","QTUMBTC","ZRXBTC","KNCBTC","IOTABTC", }

func main() {

    binance.WebsocketTimeout = time.Second * 5

     for _, symbol := range symbols {
        errHandler := func(err error) {
            fmt.Println("err",symbol,err)
        }

        doneC, _, err := binance.WsKlineServe(symbol, "1s", engk.Handle, errHandler)
        if err != nil {
            fmt.Println(time.Now().Format(time.RFC3339),"binance.WsKlineServe",symbol,err)
            // return
        }
        go func(c chan struct{}) {
            <-c
        }(doneC)
    }

// the log is
2024-04-24T08:05:57Z binance.WsKlineServe ETHBTC dial tcp 162.125.32.5:9443: i/o timeout
2024-04-24T08:06:42Z binance.WsKlineServe LTCBTC dial tcp 202.53.137.209:9443: i/o timeout
2024-04-24T08:07:27Z binance.WsKlineServe BNBBTC dial tcp 202.53.137.209:9443: i/o timeout
2024-04-24T08:08:12Z binance.WsKlineServe NEOBTC dial tcp 202.53.137.209:9443: i/o timeout
2024-04-24T08:08:57Z binance.WsKlineServe QTUMETH dial tcp 202.53.137.209:9443: i/o timeout
2024-04-24T08:09:42Z binance.WsKlineServe EOSETH dial tcp 202.53.137.209:9443: i/o timeout
2024-04-24T08:10:27Z binance.WsKlineServe SNTETH dial tcp 202.53.137.209:9443: i/o timeout
2024-04-24T08:11:12Z binance.WsKlineServe BNTETH dial tcp 202.53.137.209:9443: i/o timeout
2024-04-24T08:11:57Z binance.WsKlineServe GASBTC dial tcp 157.240.2.36:9443: i/o timeout
2024-04-24T08:12:42Z binance.WsKlineServe BNBETH dial tcp 157.240.2.36:9443: i/o timeout
2024-04-24T08:13:27Z binance.WsKlineServe BTCUSDT dial tcp 157.240.2.36:9443: i/o timeout

why the wait time more than  5 seconds ?
xyq-c-cpp commented 1 week ago

the default handshake timeout is 45 second, you can see this in code. binance.WebsocketTimeout is for ping and pong timeout.

QGB commented 1 week ago

How to change handshake timeout ?

w3xyq commented 1 week ago

How to change handshake timeout ?

can't change, it is fixed in code. but do you really need to change the handshake timeout?