https://github.com/orijtech/wsu
Websockets Utilities
https://github.com/orijtech/wsu
Last synced: 5 months ago
JSON representation
Websockets Utilities
- Host: GitHub
- URL: https://github.com/orijtech/wsu
- Owner: orijtech
- License: apache-2.0
- Created: 2017-09-03T07:46:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-10T02:00:13.000Z (over 8 years ago)
- Last Synced: 2024-06-20T16:32:56.376Z (almost 2 years ago)
- Language: Go
- Size: 13.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wsu [](https://godoc.org/github.com/orijtech/wsu)
Websockets Utilities
## Client connection
Sample to get the latest 10000 Bitcoin-USD exchange events from GDAX/Coinbase
```go
package main
import (
"log"
"github.com/orijtech/wsu"
)
func main() {
conn, err := wsu.NewClientConnection(&wsu.ClientSetup{
URL: "wss://ws-feed.gdax.com",
})
if err != nil {
log.Fatal(err)
}
defer conn.Close()
conn.Send(&wsu.Message{
Frame: []byte(`{"type": "subscribe", "product_ids": ["BTC-USD"]}`),
})
for i := 0; i < 10000; i++ {
msg, ok := conn.Receive()
if !ok {
break
}
log.Printf("#%d: TimeAt: (%v) Sequence #%d Frame: %s", i, msg.TimeAt, msg.Sequence, msg.Frame)
}
}
```