diff --git a/pkg/strategy/xdepthmaker/strategy.go b/pkg/strategy/xdepthmaker/strategy.go index 855de24ce..7a8d80c4c 100644 --- a/pkg/strategy/xdepthmaker/strategy.go +++ b/pkg/strategy/xdepthmaker/strategy.go @@ -49,7 +49,10 @@ type CrossExchangeMarketMakingStrategy struct { Position *types.Position `json:"position,omitempty" persistence:"position"` ProfitStats *types.ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"` CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty" persistence:"covered_position"` - mu sync.Mutex + + core.ConverterManager + + mu sync.Mutex MakerOrderExecutor, HedgeOrderExecutor *bbgo.GeneralOrderExecutor } @@ -107,6 +110,10 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize( s.makerMarket.Symbol, strategyID, instanceID, s.Position) + + // update converter manager + s.MakerOrderExecutor.TradeCollector().ConverterManager = s.ConverterManager + s.MakerOrderExecutor.BindEnvironment(environ) s.MakerOrderExecutor.BindProfitStats(s.ProfitStats) s.MakerOrderExecutor.Bind() @@ -122,6 +129,9 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize( s.HedgeOrderExecutor.BindEnvironment(environ) s.HedgeOrderExecutor.BindProfitStats(s.ProfitStats) s.HedgeOrderExecutor.Bind() + + s.HedgeOrderExecutor.TradeCollector().ConverterManager = s.ConverterManager + s.HedgeOrderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) { // bbgo.Sync(ctx, s) }) @@ -148,8 +158,6 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize( type Strategy struct { *CrossExchangeMarketMakingStrategy - *core.ConverterManager - Environment *bbgo.Environment Symbol string `json:"symbol"` diff --git a/pkg/types/position.go b/pkg/types/position.go index 589fa2a2b..d0b37f031 100644 --- a/pkg/types/position.go +++ b/pkg/types/position.go @@ -19,16 +19,19 @@ const ( PositionClosed = PositionType("Closed") ) +// ExchangeFee stores the exchange fee rate type ExchangeFee struct { MakerFeeRate fixedpoint.Value TakerFeeRate fixedpoint.Value } +// PositionRisk stores the position risk data type PositionRisk struct { - Leverage fixedpoint.Value `json:"leverage"` - LiquidationPrice fixedpoint.Value `json:"liquidationPrice"` + Leverage fixedpoint.Value `json:"leverage,omitempty"` + LiquidationPrice fixedpoint.Value `json:"liquidationPrice,omitempty"` } +// Position stores the position data type Position struct { Symbol string `json:"symbol" db:"symbol"` BaseCurrency string `json:"baseCurrency" db:"base"` @@ -281,8 +284,14 @@ type FuturesPosition struct { ExchangeFeeRates map[ExchangeName]ExchangeFee `json:"exchangeFeeRates"` // Futures data fields - Isolated bool `json:"isolated"` - UpdateTime int64 `json:"updateTime"` + // ------------------- + // Isolated margin mode + Isolated bool `json:"isolated"` + + // UpdateTime is the time when the position is updated + UpdateTime int64 `json:"updateTime"` + + // PositionRisk stores the position risk data PositionRisk *PositionRisk }