mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
scmaker: initialize order executor before we setup risk control
This commit is contained in:
parent
ae3f371551
commit
0426c18757
|
@ -37,8 +37,8 @@ func NewPositionRiskControl(hardLimit, quantity fixedpoint.Value, tradeCollector
|
|||
}
|
||||
|
||||
// ModifiedQuantity returns quantity controlled by position risks
|
||||
// For buy orders, mod quantity = min(hardlimit - position, quanity), limiting by positive position
|
||||
// For sell orders, mod quantity = min(hardlimit - (-position), quanity), limiting by negative position
|
||||
// For buy orders, mod quantity = min(hardLimit - position, quantity), limiting by positive position
|
||||
// For sell orders, mod quantity = min(hardLimit - (-position), quantity), limiting by negative position
|
||||
func (p *PositionRiskControl) ModifiedQuantity(position fixedpoint.Value) (buyQuantity, sellQuantity fixedpoint.Value) {
|
||||
return fixedpoint.Min(p.hardLimit.Sub(position), p.quantity),
|
||||
fixedpoint.Min(p.hardLimit.Add(position), p.quantity)
|
||||
|
|
|
@ -136,6 +136,14 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
s.ProfitStats = types.NewProfitStats(s.Market)
|
||||
}
|
||||
|
||||
s.orderExecutor = bbgo.NewGeneralOrderExecutor(session, s.Symbol, ID, instanceID, s.Position)
|
||||
s.orderExecutor.BindEnvironment(s.Environment)
|
||||
s.orderExecutor.BindProfitStats(s.ProfitStats)
|
||||
s.orderExecutor.Bind()
|
||||
s.orderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
|
||||
bbgo.Sync(ctx, s)
|
||||
})
|
||||
|
||||
if !s.PositionHardLimit.IsZero() && !s.MaxPositionQuantity.IsZero() {
|
||||
log.Infof("positionHardLimit and maxPositionQuantity are configured, setting up PositionRiskControl...")
|
||||
s.positionRiskControl = riskcontrol.NewPositionRiskControl(s.PositionHardLimit, s.MaxPositionQuantity, s.orderExecutor.TradeCollector())
|
||||
|
@ -181,14 +189,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
|
||||
s.liquidityScale = scale
|
||||
|
||||
s.orderExecutor = bbgo.NewGeneralOrderExecutor(session, s.Symbol, ID, instanceID, s.Position)
|
||||
s.orderExecutor.BindEnvironment(s.Environment)
|
||||
s.orderExecutor.BindProfitStats(s.ProfitStats)
|
||||
s.orderExecutor.Bind()
|
||||
s.orderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
|
||||
bbgo.Sync(ctx, s)
|
||||
})
|
||||
|
||||
s.initializeMidPriceEMA(session)
|
||||
s.initializePriceRangeBollinger(session)
|
||||
s.initializeIntensityIndicator(session)
|
||||
|
|
Loading…
Reference in New Issue
Block a user