bbgo: add session connection notification

This commit is contained in:
c9s 2021-12-30 17:18:04 +08:00
parent 8995ce2824
commit cfc66dc13e
2 changed files with 14 additions and 4 deletions

View File

@ -322,6 +322,16 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
// forward trade updates and order updates to the order executor
session.UserDataStream.OnTradeUpdate(session.OrderExecutor.EmitTradeUpdate)
session.UserDataStream.OnOrderUpdate(session.OrderExecutor.EmitOrderUpdate)
if len(session.Notifiability.notifiers) > 0 {
session.UserDataStream.OnDisconnect(func() {
session.Notifiability.Notify("session %s user data stream disconnected", session.Name)
})
session.UserDataStream.OnConnect(func() {
session.Notifiability.Notify("session %s user data stream connected", session.Name)
})
}
session.Account.BindStream(session.UserDataStream)
// if metrics mode is enabled, we bind the callbacks to update metrics

View File

@ -49,10 +49,10 @@ var defaultDialer = &websocket.Dialer{
// - the re-connector calls connect() to create the new connection object, go to the 1 step.
// When stream.Close() is called, a close message must be written to the websocket connection.
const readTimeout = 3 * time.Minute
const writeTimeout = 15 * time.Second
const pingInterval = readTimeout / 3
const listenKeyKeepAliveInterval = 10 * time.Minute
const readTimeout = 1 * time.Minute
const writeTimeout = 5 * time.Second
const pingInterval = readTimeout / 2
const listenKeyKeepAliveInterval = 30 * time.Minute
const reconnectCoolDownPeriod = 15 * time.Second
func init() {