mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
Merge pull request #1655 from c9s/c9s/xgap-vol-target
FEATURE: [xgap] add dailyTargetVolume option
This commit is contained in:
commit
e953a04638
|
@ -70,11 +70,12 @@ type Strategy struct {
|
||||||
Quantity fixedpoint.Value `json:"quantity"`
|
Quantity fixedpoint.Value `json:"quantity"`
|
||||||
DryRun bool `json:"dryRun"`
|
DryRun bool `json:"dryRun"`
|
||||||
|
|
||||||
DailyFeeBudgets map[string]fixedpoint.Value `json:"dailyFeeBudgets,omitempty"`
|
DailyFeeBudgets map[string]fixedpoint.Value `json:"dailyFeeBudgets,omitempty"`
|
||||||
DailyMaxVolume fixedpoint.Value `json:"dailyMaxVolume,omitempty"`
|
DailyMaxVolume fixedpoint.Value `json:"dailyMaxVolume,omitempty"`
|
||||||
UpdateInterval types.Duration `json:"updateInterval"`
|
DailyTargetVolume fixedpoint.Value `json:"dailyTargetVolume,omitempty"`
|
||||||
SimulateVolume bool `json:"simulateVolume"`
|
UpdateInterval types.Duration `json:"updateInterval"`
|
||||||
SimulatePrice bool `json:"simulatePrice"`
|
SimulateVolume bool `json:"simulateVolume"`
|
||||||
|
SimulatePrice bool `json:"simulatePrice"`
|
||||||
|
|
||||||
sourceSession, tradingSession *bbgo.ExchangeSession
|
sourceSession, tradingSession *bbgo.ExchangeSession
|
||||||
sourceMarket, tradingMarket types.Market
|
sourceMarket, tradingMarket types.Market
|
||||||
|
@ -380,10 +381,13 @@ func (s *Strategy) placeOrders(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
} else if s.DailyTargetVolume.Sign() > 0 {
|
||||||
|
numOfTicks := (24 * time.Hour) / s.UpdateInterval.Duration()
|
||||||
|
quantity = fixedpoint.NewFromFloat(s.DailyTargetVolume.Float64() / float64(numOfTicks))
|
||||||
|
quantity = quantityJitter(quantity, 0.02)
|
||||||
} else {
|
} else {
|
||||||
// plus a 2% quantity jitter
|
// plus a 2% quantity jitter
|
||||||
jitter := 1.0 + math.Max(0.02, rand.Float64())
|
quantity = quantityJitter(quantity, 0.02)
|
||||||
quantity = quantity.Mul(fixedpoint.NewFromFloat(jitter))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("%s quantity: %f", s.Symbol, quantity.Float64())
|
log.Infof("%s quantity: %f", s.Symbol, quantity.Float64())
|
||||||
|
@ -430,3 +434,8 @@ func (s *Strategy) cancelOrders(ctx context.Context) {
|
||||||
log.WithError(err).Error("cancel order error")
|
log.WithError(err).Error("cancel order error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func quantityJitter(q fixedpoint.Value, rg float64) fixedpoint.Value {
|
||||||
|
jitter := 1.0 + math.Max(rg, rand.Float64())
|
||||||
|
return q.Mul(fixedpoint.NewFromFloat(jitter))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user