Merge pull request #1311 from bailantaotao/edwin/add-on-raw-message-callback

FEATURE: emit regardless of whether there is an error or not on subscription.
This commit is contained in:
bailantaotao 2023-09-20 11:33:33 +08:00 committed by GitHub
commit a3df61dca4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -44,6 +44,16 @@ func (s *StandardStream) EmitAuth() {
}
}
func (s *StandardStream) OnRawMessage(cb func(raw []byte)) {
s.rawMessageCallbacks = append(s.rawMessageCallbacks, cb)
}
func (s *StandardStream) EmitRawMessage(raw []byte) {
for _, cb := range s.rawMessageCallbacks {
cb(raw)
}
}
func (s *StandardStream) OnTradeUpdate(cb func(trade Trade)) {
s.tradeUpdateCallbacks = append(s.tradeUpdateCallbacks, cb)
}
@ -183,6 +193,8 @@ type StandardStreamEventHub interface {
OnAuth(cb func())
OnRawMessage(cb func(raw []byte))
OnTradeUpdate(cb func(trade Trade))
OnOrderUpdate(cb func(order Order))

View File

@ -100,6 +100,8 @@ type StandardStream struct {
authCallbacks []func()
rawMessageCallbacks []func(raw []byte)
// private trade update callbacks
tradeUpdateCallbacks []func(trade Trade)
@ -260,6 +262,8 @@ func (s *StandardStream) Read(ctx context.Context, conn *websocket.Conn, cancel
continue
}
s.EmitRawMessage(message)
if debugRawMessage {
log.Info(string(message))
}