improve logging

This commit is contained in:
c9s 2020-10-19 22:26:43 +08:00
parent 366036a35b
commit d68564de28

View File

@ -85,6 +85,7 @@ func (environ *Environment) Connect(ctx context.Context) error {
for n := range environ.sessions {
// avoid using the placeholder variable for the session because we use that in the callbacks
var session = environ.sessions[n]
var log = log.WithField("session", n)
loadedSymbols := make(map[string]struct{})
for _, s := range session.Subscriptions {
@ -131,8 +132,6 @@ func (environ *Environment) Connect(ctx context.Context) error {
session.marketDataStores[symbol] = marketDataStore
}
log.Infof("loaded symbol: %+v", loadedSymbols)
log.Infof("querying balances...")
balances, err := session.Exchange.QueryAccountBalances(ctx)
if err != nil {
@ -158,6 +157,11 @@ func (environ *Environment) Connect(ctx context.Context) error {
}
})
if len(session.Subscriptions) == 0 {
log.Warnf("no subscriptions, exchange session %s will not be connected", session.Name)
continue
}
log.Infof("connecting session %s...", session.Name)
if err := session.Stream.Connect(ctx); err != nil {
return err