mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
Merge pull request #1458 from c9s/feature/xdepthmaker
FIX: [xdepthmaker] final fix
This commit is contained in:
commit
98468feb73
|
@ -565,7 +565,7 @@ func (environ *Environment) RecordPosition(position *types.Position, trade types
|
|||
return
|
||||
}
|
||||
|
||||
// set profit info to position
|
||||
// guard: set profit info to position if the strategy info is empty
|
||||
if profit != nil {
|
||||
if position.Strategy == "" && profit.Strategy != "" {
|
||||
position.Strategy = profit.Strategy
|
||||
|
@ -576,10 +576,12 @@ func (environ *Environment) RecordPosition(position *types.Position, trade types
|
|||
}
|
||||
}
|
||||
|
||||
log.Infof("recordPosition: position = %s, trade = %+v, profit = %+v", position.Base.String(), trade, profit)
|
||||
if profit != nil {
|
||||
if err := environ.PositionService.Insert(position, trade, profit.Profit); err != nil {
|
||||
log.WithError(err).Errorf("can not insert position record")
|
||||
}
|
||||
|
||||
if err := environ.ProfitService.Insert(*profit); err != nil {
|
||||
log.WithError(err).Errorf("can not insert profit record: %+v", profit)
|
||||
}
|
||||
|
|
19
pkg/exchange/bitget/debug.go
Normal file
19
pkg/exchange/bitget/debug.go
Normal 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()
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
@ -432,13 +436,22 @@ func (s *Stream) handleOrderTradeEvent(m OrderTradeEvent) {
|
|||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// The bitget support only snapshot on orders channel, so we use snapshot as update to emit data.
|
||||
if m.actionType != ActionTypeSnapshot {
|
||||
continue
|
||||
}
|
||||
|
||||
s.StandardStream.EmitOrderUpdate(globalOrder)
|
||||
|
||||
if globalOrder.Status == types.OrderStatusPartiallyFilled {
|
||||
if order.TradeId == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
debugf("received Trade: %+v", order.Trade)
|
||||
|
||||
switch globalOrder.Status {
|
||||
case types.OrderStatusPartiallyFilled, types.OrderStatusFilled:
|
||||
trade, err := order.toGlobalTrade()
|
||||
if err != nil {
|
||||
if tradeLogLimiter.Allow() {
|
||||
|
@ -446,6 +459,7 @@ func (s *Stream) handleOrderTradeEvent(m OrderTradeEvent) {
|
|||
}
|
||||
continue
|
||||
}
|
||||
|
||||
s.StandardStream.EmitTradeUpdate(trade)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,6 +249,16 @@ func (s *Strategy) InstanceID() string {
|
|||
return fmt.Sprintf("%s:%s", ID, s.Symbol)
|
||||
}
|
||||
|
||||
func (s *Strategy) Initialize() error {
|
||||
if s.CrossExchangeMarketMakingStrategy == nil {
|
||||
s.CrossExchangeMarketMakingStrategy = &CrossExchangeMarketMakingStrategy{}
|
||||
}
|
||||
|
||||
s.bidPriceHeartBeat = types.NewPriceHeartBeat(priceUpdateTimeout)
|
||||
s.askPriceHeartBeat = types.NewPriceHeartBeat(priceUpdateTimeout)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
|
||||
makerSession, hedgeSession, err := selectSessions2(sessions, s.MakerExchange, s.HedgeExchange)
|
||||
if err != nil {
|
||||
|
@ -325,12 +335,6 @@ func (s *Strategy) Defaults() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) Initialize() error {
|
||||
s.bidPriceHeartBeat = types.NewPriceHeartBeat(priceUpdateTimeout)
|
||||
s.askPriceHeartBeat = types.NewPriceHeartBeat(priceUpdateTimeout)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) CrossRun(
|
||||
ctx context.Context, _ bbgo.OrderExecutionRouter,
|
||||
sessions map[string]*bbgo.ExchangeSession,
|
||||
|
@ -340,7 +344,6 @@ func (s *Strategy) CrossRun(
|
|||
return err
|
||||
}
|
||||
|
||||
s.CrossExchangeMarketMakingStrategy = &CrossExchangeMarketMakingStrategy{}
|
||||
if err := s.CrossExchangeMarketMakingStrategy.Initialize(ctx, s.Environment, makerSession, hedgeSession, s.Symbol, ID, s.InstanceID()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user