mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
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:
commit
a3df61dca4
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user