Okx: Integrate websocket book5 processing and add configurable max subscriptions per connection (#1275)

* okx: books 5 (cherry-pick)

* okx: shift types to types file, remove commented code and updated field name to better reflect pushed type

* linter: fix

* remove slowness

* * Introduce function checksubscriptions and shift check of subscriptions to internal websocket package
* Shift Max websocket connection int to Websocket setup (temp) for this use case only.

* glorious: nits

* linter: fix

* websocket: don't try and subscribed with nothing to subscribe to.

* Update exchanges/stream/websocket_test.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
Ryan O'Hara-Reid
2023-10-13 15:54:49 +11:00
committed by GitHub
parent 859c4512fb
commit 773441d5a7
9 changed files with 274 additions and 108 deletions

View File

@@ -106,54 +106,47 @@ func (m *WebsocketRoutineManager) websocketRoutine() {
if err != nil {
log.Errorf(log.WebsocketMgr, "websocket routine manager cannot get exchanges: %v", err)
}
wg := sync.WaitGroup{}
wg.Add(len(exchanges))
for i := range exchanges {
go func(i int) {
defer wg.Done()
if exchanges[i].SupportsWebsocket() {
if m.verbose {
log.Debugf(log.WebsocketMgr,
"Exchange %s websocket support: Yes Enabled: %v",
exchanges[i].GetName(),
common.IsEnabled(exchanges[i].IsWebsocketEnabled()),
)
}
ws, err := exchanges[i].GetWebsocket()
if err != nil {
log.Errorf(
log.WebsocketMgr,
"Exchange %s GetWebsocket error: %s",
exchanges[i].GetName(),
err,
)
return
}
if ws.IsEnabled() {
err = ws.Connect()
if err != nil {
log.Errorf(log.WebsocketMgr, "%v", err)
}
err = m.websocketDataReceiver(ws)
if err != nil {
log.Errorf(log.WebsocketMgr, "%v", err)
}
err = ws.FlushChannels()
if err != nil {
log.Errorf(log.WebsocketMgr, "Failed to subscribe: %v", err)
}
}
} else if m.verbose {
log.Debugf(log.WebsocketMgr,
"Exchange %s websocket support: No",
exchanges[i].GetName(),
)
var wg sync.WaitGroup
for _, exch := range exchanges {
if !exch.SupportsWebsocket() {
if m.verbose {
log.Debugf(log.WebsocketMgr, "Exchange %s websocket support: No",
exch.GetName())
}
}(i)
continue
}
if m.verbose {
log.Debugf(log.WebsocketMgr, "Exchange %s websocket support: Yes Enabled: %v",
exch.GetName(),
common.IsEnabled(exch.IsWebsocketEnabled()))
}
ws, err := exch.GetWebsocket()
if err != nil {
log.Errorf(log.WebsocketMgr, "Exchange %s GetWebsocket error: %s",
exch.GetName(),
err)
continue
}
if !ws.IsEnabled() {
continue
}
wg.Add(1)
go func() {
defer wg.Done()
err = ws.Connect()
if err != nil {
log.Errorf(log.WebsocketMgr, "%v", err)
}
err = m.websocketDataReceiver(ws)
if err != nil {
log.Errorf(log.WebsocketMgr, "%v", err)
}
}()
}
wg.Wait()
}