bitget: add more debug logs for orderEvent and tradeEvent

This commit is contained in:
c9s 2023-12-18 16:31:04 +08:00
parent 92aa7652d5
commit 841229518a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 26 additions and 17 deletions

View File

@ -0,0 +1,19 @@
package bitget
import "github.com/c9s/bbgo/pkg/util"
type LogFunction func(msg string, args ...interface{})
var debugf LogFunction
func getDebugFunction() LogFunction {
if v, ok := util.GetEnvVarBool("DEBUG_BITGET"); ok && v {
return log.Infof
}
return func(msg string, args ...interface{}) {}
}
func init() {
debugf = getDebugFunction()
}

View File

@ -14,7 +14,6 @@ import (
"github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi"
v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
)
const (
@ -64,22 +63,6 @@ var (
kLineRateLimiter = rate.NewLimiter(rate.Every(time.Second/10), 5)
)
type LogFunction func(msg string, args ...interface{})
var debugf LogFunction
func getDebugFunction() LogFunction {
if v, ok := util.GetEnvVarBool("DEBUG_BITGET"); ok && v {
return log.Infof
}
return func(msg string, args ...interface{}) {}
}
func init() {
debugf = getDebugFunction()
}
type Exchange struct {
key, secret, passphrase string

View File

@ -424,7 +424,11 @@ func (s *Stream) handleOrderTradeEvent(m OrderTradeEvent) {
return
}
debugf("received OrderTradeEvent: %+v", m)
for _, order := range m.Orders {
debugf("received Order: %+v", order)
globalOrder, err := order.toGlobalOrder()
if err != nil {
if orderLogLimiter.Allow() {
@ -437,12 +441,15 @@ func (s *Stream) handleOrderTradeEvent(m OrderTradeEvent) {
if m.actionType != ActionTypeSnapshot {
continue
}
s.StandardStream.EmitOrderUpdate(globalOrder)
if order.TradeId == 0 {
continue
}
debugf("received Trade: %+v", order.Trade)
switch globalOrder.Status {
case types.OrderStatusPartiallyFilled, types.OrderStatusFilled:
trade, err := order.toGlobalTrade()