mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
add onStart callbacks
This commit is contained in:
parent
4061f2aef0
commit
e311a182fa
|
@ -489,6 +489,8 @@ func (environ *Environment) Connect(ctx context.Context) error {
|
|||
if err := session.Stream.Connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
session.Stream.EmitStart()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -4,6 +4,16 @@ package types
|
|||
|
||||
import ()
|
||||
|
||||
func (stream *StandardStream) OnStart(cb func()) {
|
||||
stream.startCallbacks = append(stream.startCallbacks, cb)
|
||||
}
|
||||
|
||||
func (stream *StandardStream) EmitStart() {
|
||||
for _, cb := range stream.startCallbacks {
|
||||
cb()
|
||||
}
|
||||
}
|
||||
|
||||
func (stream *StandardStream) OnConnect(cb func()) {
|
||||
stream.connectCallbacks = append(stream.connectCallbacks, cb)
|
||||
}
|
||||
|
@ -105,6 +115,8 @@ func (stream *StandardStream) EmitBookSnapshot(book OrderBook) {
|
|||
}
|
||||
|
||||
type StandardStreamEventHub interface {
|
||||
OnStart(cb func())
|
||||
|
||||
OnConnect(cb func())
|
||||
|
||||
OnDisconnect(cb func())
|
||||
|
|
|
@ -23,6 +23,8 @@ var KLineChannel = Channel("kline")
|
|||
type StandardStream struct {
|
||||
Subscriptions []Subscription
|
||||
|
||||
startCallbacks []func()
|
||||
|
||||
connectCallbacks []func()
|
||||
|
||||
disconnectCallbacks []func()
|
||||
|
|
Loading…
Reference in New Issue
Block a user