Skip to content
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

more functions are not provided #594

Open
vadinabronin opened this issue Jul 30, 2024 · 3 comments
Open

more functions are not provided #594

vadinabronin opened this issue Jul 30, 2024 · 3 comments

Comments

@vadinabronin
Copy link

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
Copy link
Author

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
Copy link
Owner

adshao commented Jul 30, 2024

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
Copy link
Author

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 {}

}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants