adshao / go-binance

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

"Sleep" at the first operation #508

Open Vladimir-Khm opened 10 months ago

Vladimir-Khm commented 10 months ago

I tried to test ping with this simple code:

package main

import (
    "context"
    "fmt"
    "time"

    binance_connector "github.com/adshao/go-binance/v2"
)

func main() {
    Ping()
}

func Ping() {
    client := binance_connector.NewClient("", "")
    ping := client.NewPingService()

    for i:= 0; i < 20; i++ {
        start := time.Now()
        ping.Do(context.Background())
        fmt.Println(time.Since(start))
    }
}

And I always got results like these: 125.41625ms 5.679ms 9.238927ms 8.646379ms 5.173076ms 5.798899ms 7.397644ms 6.460718ms 4.268116ms 5.672282ms 7.209897ms 6.009768ms 7.882153ms 7.774738ms 6.263361ms 9.195017ms 7.095737ms 5.364541ms 5.901158ms 4.376399ms

The first result was always in many times higher then other 19.

Initially I have tasted it separately and couldn't understand why is there such a big number. Code was run on Windows and Ubuntu with the same result and with different versions of go. I think it works not in an appropriate way. The same program with python-binance works fine

xyq-c-cpp commented 1 week ago

I think the first operation is to do many things and then other operations can reuse this. Have you found more things? @Vladimir-Khm