Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
larscom committed Aug 28, 2024
1 parent a115f6c commit 1874b7a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 31 deletions.
104 changes: 73 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@

> GO **thread safe** library (WebSockets / HTTP) for Bitvavo v2 API (see: https://docs.bitvavo.com)
Listen to all events occurring on the Bitvavo platform (tickers, tickers24h, candles, books, trades, orders, fills) using websockets. With the HTTP client you can do things like placing orders or withdraw assets from your account.
Listen to all events occurring on the Bitvavo platform (tickers, tickers24h, candles, books, trades, orders, fills)
using websockets. With the HTTP client you can do things like placing orders or withdraw assets from your account.

## 📒 Features

- WebSocket Listeners -- Read only
- Book
- Candles
- Trades
- Ticker
- Ticker 24h
- Orders/Fills
- Book
- Candles
- Trades
- Ticker
- Ticker 24h
- Orders/Fills
- HTTP Client -- Read / Write
- Market data endpoints
- Account endpoints
- Synchronization endpoints
- Trading endpoints
- Transfer endpoints
- Market data endpoints
- Account endpoints
- Synchronization endpoints
- Trading endpoints
- Transfer endpoints

## 🚀 Installation

Expand All @@ -37,7 +38,9 @@ import "github.com/larscom/bitvavo-go/pkg/bitvavo"

## 👂 WebSocket

For each event on the Bitvavo platform there is a listener available. A listener wraps a websocket connection, you can also implement your own wrapper arround the websocket. The listeners handle everything for you, like resubscribing and reauthenticating when the connection has been lost.
For each event on the Bitvavo platform there is a listener available. A listener wraps a websocket connection, you can
also implement your own wrapper arround the websocket. The listeners handle everything for you, like resubscribing and
reauthenticating when the connection has been lost.

### Public listeners

Expand Down Expand Up @@ -113,34 +116,35 @@ import "github.com/larscom/bitvavo-go/pkg/bitvavo"

func main() {
onMessage := func(data bitvavo.WebSocketEventData, err error) {
if err != nil {
// oh no error!
} else if data.Event == bitvavo.EventBook {
// decode into Book
var book bitvavo.Book
data.Decode(&book)
} else if data.Event == bitvavo.EventCandle {
// decode into Candle
var candle bitvavo.Candle
data.Decode(&candle)
}
// etc
if err != nil {
// oh no error!
} else if data.Event == bitvavo.EventBook {
// decode into Book
var book bitvavo.Book
data.Decode(&book)
} else if data.Event == bitvavo.EventCandle {
// decode into Candle
var candle bitvavo.Candle
data.Decode(&candle)
}
// etc
}

onReconnect := func() {
// gets called when successfully reconnected
}
onReconnect := func() {
// gets called when successfully reconnected
}

ws, err := bitvavo.NewWebSocket(context.Background(), onMessage, onReconnect)
// do stuff with ws
ws, err := bitvavo.NewWebSocket(context.Background(), onMessage, onReconnect)
// do stuff with ws
}
```

## 🌐 HTTP

The HTTP client implements 2 interfaces (PrivateAPI and PublicAPI)

If you need both private and public endpoints you can create a private http client as it includes both public and private endpoints.
If you need both private and public endpoints you can create a private http client as it includes both public and
private endpoints.

### Private and Public endpoints

Expand Down Expand Up @@ -203,6 +207,44 @@ func main() {

```

### Provide HTTP client

You can provide your own http client from the `net/http` package.

```go
package main

import (
"net/http"
"github.com/larscom/bitvavo-go/pkg/bitvavo"
)

func main() {
client := bitvavo.NewPublicHTTPClient(bitvavo.WithHttpClient(http.DefaultClient))
}

```

### Provide window time

You can provide your own window time which specifies the maximum allowed deviation (in milliseconds) between the
timestamp you sent and the server's actual time when processing your request.

The default window time is: `10000` (10 seconds)

```go
package main

import (
"github.com/larscom/bitvavo-go/pkg/bitvavo"
)

func main() {
client := bitvavo.NewPrivateHTTPClient("MY_API_KEY", "MY_API_SECRET", bitvavo.WithWindowTime(5000))
}

```

## 👉🏼 Run example

There is an example that uses the ticker listener for ticker events
Expand Down
1 change: 1 addition & 0 deletions internal/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (w *Socket) readToBuffer(ctx context.Context) {
if err != nil {
_ = w.conn.CloseNow()
if ctx.Err() == nil {
//goland:noinspection ALL
defer w.reconnect(ctx)
}
return
Expand Down

0 comments on commit 1874b7a

Please sign in to comment.