From 473a6bc10896ac75ea17454ac7e69b87a4548d43 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 10 Aug 2024 15:50:20 +0800 Subject: [PATCH] xdepthmaker: set converter manager --- pkg/strategy/xdepthmaker/strategy.go | 14 +++++++++++--- pkg/types/position.go | 17 +++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) 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 }