adshao / go-binance

A Go SDK for Binance API
MIT License
1.53k stars 677 forks source link

more functions are not provided #594

Open vadinabronin opened 1 month ago

vadinabronin commented 1 month ago

where is websocket api? I expected it to be a fully-ready library and not a kit for a build-it-yourself constructor, well, was it really that hard to add all the functions? I constantly find some holes, this is not there, that is not there. That's why I have to spend time implementing it myself, because you must agree that libraries are needed so that the user himself implements as little as possible

vadinabronin commented 1 month ago

Guys, there shouldn't be such hack work, if you implement it, then implement everything that is there, and please, don't dump it on non-users

adshao commented 1 month ago

Hi @vadinabronin , we are open source contributors who work on this project in our spare time. If you are interested, you could contribute to this project like us. I would appreciate it if you could submit a PR to implement this feature, thank you.

vadinabronin commented 1 month ago

I would be glad to send a PR, the problem is that the server does not send pings every 3 minutes as stated in the documentation, I am attaching an example of code that does not work, here the server does not send pings and the websocket turns off after 10 minutes - ```package main

import ( "log" "time"

"github.com/gorilla/websocket"

)

const ( baseURL = "wss://ws-api.binance.com:443/ws-api/v3" )

func readMessages(ws *websocket.Conn) { for { messageType, msg, err := ws.ReadMessage() if err != nil { log.Printf("Error reading message: %v", err) return }

    switch messageType {
    case websocket.PongMessage:
        log.Printf("Received pong: %s", string(msg))
    case websocket.PingMessage:
        log.Printf("Received ping: %s", string(msg))
        err = ws.WriteMessage(websocket.PongMessage, msg)
        if err != nil {
            log.Printf("Error writing pong message: %v", err)
            return
        }
    default:
        log.Printf("Received message: %s", string(msg))
    }
}

}

func sendPings(ws websocket.Conn) { for { time.Sleep(3 time.Minute) // Отправка пинга каждые 3 минуты err := ws.WriteMessage(websocket.PingMessage, []byte{}) if err != nil { log.Printf("Error sending ping: %v", err) return } log.Println("Sent ping") } }

func main() { ws, _, err := websocket.DefaultDialer.Dial(baseURL, nil) if err != nil { log.Fatalf("Error connecting to websocket: %v", err) } defer ws.Close()

log.Println("Connected to websocket")

go readMessages(ws)
go sendPings(ws) // Запускаем отправку пингов

// Бесконечный цикл для поддержания работы программы
select {}

}```