Skip to content

Commit

Permalink
xdepthmaker: set converter manager
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Aug 10, 2024
1 parent 1ad2bc5 commit 473a6bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 11 additions & 3 deletions pkg/strategy/xdepthmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand All @@ -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)
})
Expand All @@ -148,8 +158,6 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize(
type Strategy struct {
*CrossExchangeMarketMakingStrategy

*core.ConverterManager

Environment *bbgo.Environment

Symbol string `json:"symbol"`
Expand Down
17 changes: 13 additions & 4 deletions pkg/types/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 473a6bc

Please sign in to comment.