xdepthmaker: set converter manager

This commit is contained in:
c9s 2024-08-10 15:50:20 +08:00
parent 1ad2bc5f34
commit 473a6bc108
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 24 additions and 7 deletions

View File

@ -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"`

View File

@ -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
}