Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
update deps, workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
larscom committed Apr 1, 2024
1 parent e27c112 commit 7faafa3
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 117 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
- run: make build
Expand Down
5 changes: 2 additions & 3 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ replace github.com/larscom/go-bitvavo/v2 => ../

require (
github.com/joho/godotenv v1.5.1
github.com/larscom/go-bitvavo/v2 v2.2.0
github.com/larscom/go-bitvavo/v2 v2.0.0
)

require (
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/dolthub/maphash v0.1.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mhmtszr/concurrent-swiss-map v1.0.6 // indirect
github.com/orsinium-labs/enum v1.3.0 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/smallnest/safemap v0.0.0-20221221063619-2e3a9fa0ff20 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
)
14 changes: 2 additions & 12 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM=
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ=
github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand All @@ -22,24 +18,18 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mhmtszr/concurrent-swiss-map v1.0.6 h1:buAXz0eIWJm0ogPWJGKXdONOzk7aW1Qi0/qzPhZMvGE=
github.com/mhmtszr/concurrent-swiss-map v1.0.6/go.mod h1:F6QETL48Qn7jEJ3ZPt7EqRZjAAZu7lRQeQGIzXuUIDc=
github.com/orsinium-labs/enum v1.3.0 h1:OsIMdDbY06X4N4urfk/ysMATuByK3I8troJ754XphDM=
github.com/orsinium-labs/enum v1.3.0/go.mod h1:Qj5IK2pnElZtkZbGDxZMjpt7SUsn4tqE5vRelmWaBbc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/smallnest/safemap v0.0.0-20221221063619-2e3a9fa0ff20 h1:TSS9XXTYReYgYncCGCmk5hKYrq+m/2zMWzDfn2B6DkQ=
github.com/smallnest/safemap v0.0.0-20221221063619-2e3a9fa0ff20/go.mod h1:utWAg2jafYmELXFuUaJsT+8tClaCEumLPN0exPk9pzI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
24 changes: 0 additions & 24 deletions examples/ws/ticker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ package main

import (
"log"
"os"
"runtime/trace"
"time"

"github.com/larscom/go-bitvavo/v2"
)

func main() {
file := createTraceFile("trace.out")
defer file.Close()

if err := trace.Start(file); err != nil {
log.Fatal(err)
}
defer trace.Stop()

markets, err := bitvavo.NewHttpClient().GetMarkets()
if err != nil {
log.Fatal(err)
Expand All @@ -35,11 +24,6 @@ func main() {
log.Fatal(err)
}

go func() {
time.Sleep(time.Second * 10)
ws.Ticker().UnsubscribeAll()
}()

// subscribe to all available 'trading' markets
tickerchn, err := ws.Ticker().Subscribe(tradingMarkets)
if err != nil {
Expand All @@ -50,11 +34,3 @@ func main() {
log.Println(tickerEvent)
}
}

func createTraceFile(name string) *os.File {
file, err := os.Create(name)
if err != nil {
log.Fatal(err)
}
return file
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ require (
github.com/goccy/go-json v0.10.2
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.1
github.com/mhmtszr/concurrent-swiss-map v1.0.6
github.com/orsinium-labs/enum v1.3.0
github.com/rs/zerolog v1.32.0
github.com/smallnest/safemap v0.0.0-20221221063619-2e3a9fa0ff20
)

require (
github.com/dolthub/maphash v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
)
14 changes: 2 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM=
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ=
github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand All @@ -20,24 +16,18 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mhmtszr/concurrent-swiss-map v1.0.6 h1:buAXz0eIWJm0ogPWJGKXdONOzk7aW1Qi0/qzPhZMvGE=
github.com/mhmtszr/concurrent-swiss-map v1.0.6/go.mod h1:F6QETL48Qn7jEJ3ZPt7EqRZjAAZu7lRQeQGIzXuUIDc=
github.com/orsinium-labs/enum v1.3.0 h1:OsIMdDbY06X4N4urfk/ysMATuByK3I8troJ754XphDM=
github.com/orsinium-labs/enum v1.3.0/go.mod h1:Qj5IK2pnElZtkZbGDxZMjpt7SUsn4tqE5vRelmWaBbc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/smallnest/safemap v0.0.0-20221221063619-2e3a9fa0ff20 h1:TSS9XXTYReYgYncCGCmk5hKYrq+m/2zMWzDfn2B6DkQ=
github.com/smallnest/safemap v0.0.0-20221221063619-2e3a9fa0ff20/go.mod h1:utWAg2jafYmELXFuUaJsT+8tClaCEumLPN0exPk9pzI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
31 changes: 16 additions & 15 deletions ws/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rs/zerolog/log"

"github.com/larscom/go-bitvavo/v2/types"
"github.com/smallnest/safemap"
csmap "github.com/mhmtszr/concurrent-swiss-map"
)

type OrderEvent struct {
Expand Down Expand Up @@ -125,7 +125,7 @@ type accountEventHandler struct {
authenticated bool
authchn chan bool
writechn chan<- WebSocketMessage
subs *safemap.SafeMap[string, *accountSubscription]
subs *csmap.CsMap[string, *accountSubscription]
}

func newAccountEventHandler(apiKey string, apiSecret string, writechn chan<- WebSocketMessage) *accountEventHandler {
Expand All @@ -134,7 +134,7 @@ func newAccountEventHandler(apiKey string, apiSecret string, writechn chan<- Web
apiSecret: apiSecret,
writechn: writechn,
authchn: make(chan bool),
subs: safemap.New[string, *accountSubscription](),
subs: csmap.Create[string, *accountSubscription](),
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func (a *accountEventHandler) Subscribe(markets []string, buffSize ...uint64) (<
orderinchn := make(chan OrderEvent, size)
fillinchn := make(chan FillEvent, size)

a.subs.Set(market, newAccountSubscription(id, market, orderinchn, orderoutchn, fillinchn, filloutchn))
a.subs.Store(market, newAccountSubscription(id, market, orderinchn, orderoutchn, fillinchn, filloutchn))

go relayMessages(orderinchn, orderoutchn)
go relayMessages(fillinchn, filloutchn)
Expand All @@ -189,7 +189,7 @@ func (a *accountEventHandler) Unsubscribe(markets []string) error {
}

func (a *accountEventHandler) UnsubscribeAll() error {
if err := a.Unsubscribe(a.subs.Keys()); err != nil {
if err := a.Unsubscribe(getSubscriptionKeys(a.subs)); err != nil {
return err
}

Expand All @@ -202,7 +202,7 @@ func (a *accountEventHandler) handleOrderMessage(bytes []byte) {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into OrderEvent")
} else {
market := orderEvent.Market
sub, exist := a.subs.Get(market)
sub, exist := a.subs.Load(market)
if exist {
sub.orderinchn <- *orderEvent
} else {
Expand All @@ -217,7 +217,7 @@ func (a *accountEventHandler) handleFillMessage(bytes []byte) {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into FillEvent")
} else {
market := fillEvent.Market
sub, exist := a.subs.Get(market)
sub, exist := a.subs.Load(market)
if exist {
sub.fillinchn <- *fillEvent
} else {
Expand Down Expand Up @@ -255,7 +255,7 @@ func (a *accountEventHandler) reconnect() {
a.authenticated = false

if err := a.withAuth(func() {
a.writechn <- newWebSocketMessage(actionSubscribe, channelNameAccount, a.subs.Keys())
a.writechn <- newWebSocketMessage(actionSubscribe, channelNameAccount, getSubscriptionKeys(a.subs))
}); err != nil {
log.Err(err).Msg("Failed to reconnect the account websocket")
}
Expand All @@ -275,17 +275,18 @@ func (a *accountEventHandler) withAuth(action func()) error {
}

func (a *accountEventHandler) deleteSubscriptions(
subs *safemap.SafeMap[string, *accountSubscription],
subs *csmap.CsMap[string, *accountSubscription],
markets []string,
) error {
counts := make(map[uuid.UUID]int)
for item := range subs.IterBuffered() {
counts[item.Val.id]++
}
subs.Range(func(key string, value *accountSubscription) (stop bool) {
counts[value.id]++
return false
})

idsWithKeys := make(map[uuid.UUID][]string)
for _, key := range markets {
if sub, found := subs.Get(key); found {
if sub, found := subs.Load(key); found {
idsWithKeys[sub.id] = append(idsWithKeys[sub.id], key)
close(sub.orderinchn)
close(sub.fillinchn)
Expand All @@ -294,13 +295,13 @@ func (a *accountEventHandler) deleteSubscriptions(

for id, keys := range idsWithKeys {
if counts[id] == len(keys) {
if item, found := subs.Get(keys[0]); found {
if item, found := subs.Load(keys[0]); found {
close(item.orderoutchn)
close(item.filloutchn)
}
}
for _, key := range keys {
subs.Remove(key)
subs.Delete(key)
}
}

Expand Down
14 changes: 7 additions & 7 deletions ws/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package ws
import (
"github.com/google/uuid"
"github.com/larscom/go-bitvavo/v2/types"
csmap "github.com/mhmtszr/concurrent-swiss-map"
"github.com/rs/zerolog/log"

"github.com/goccy/go-json"
"github.com/larscom/go-bitvavo/v2/util"
"github.com/smallnest/safemap"
)

type BookEvent struct {
Expand Down Expand Up @@ -44,13 +44,13 @@ func (b *BookEvent) UnmarshalJSON(bytes []byte) error {

type bookEventHandler struct {
writechn chan<- WebSocketMessage
subs *safemap.SafeMap[string, *subscription[BookEvent]]
subs *csmap.CsMap[string, *subscription[BookEvent]]
}

func newBookEventHandler(writechn chan<- WebSocketMessage) *bookEventHandler {
return &bookEventHandler{
writechn: writechn,
subs: safemap.New[string, *subscription[BookEvent]](),
subs: csmap.Create[string, *subscription[BookEvent]](),
}
}

Expand All @@ -69,7 +69,7 @@ func (b *bookEventHandler) Subscribe(markets []string, buffSize ...uint64) (<-ch

for _, market := range markets {
inchn := make(chan BookEvent, size)
b.subs.Set(market, newSubscription(id, market, inchn, outchn))
b.subs.Store(market, newSubscription(id, market, inchn, outchn))
go relayMessages(inchn, outchn)
}

Expand All @@ -91,7 +91,7 @@ func (b *bookEventHandler) Unsubscribe(markets []string) error {
}

func (b *bookEventHandler) UnsubscribeAll() error {
if err := b.Unsubscribe(b.subs.Keys()); err != nil {
if err := b.Unsubscribe(getSubscriptionKeys(b.subs)); err != nil {
return err
}

Expand All @@ -104,7 +104,7 @@ func (b *bookEventHandler) handleMessage(bytes []byte) {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into BookEvent")
} else {
market := bookEvent.Market
sub, exist := b.subs.Get(market)
sub, exist := b.subs.Load(market)
if exist {
sub.inchn <- *bookEvent
} else {
Expand All @@ -114,5 +114,5 @@ func (b *bookEventHandler) handleMessage(bytes []byte) {
}

func (b *bookEventHandler) reconnect() {
b.writechn <- newWebSocketMessage(actionSubscribe, channelNameBook, b.subs.Keys())
b.writechn <- newWebSocketMessage(actionSubscribe, channelNameBook, getSubscriptionKeys(b.subs))
}
Loading

0 comments on commit 7faafa3

Please sign in to comment.