xdepthmaker: add hedgeMaxOrderQuantity protection

This commit is contained in:
c9s 2024-09-25 15:52:23 +08:00
parent b3d58a9e05
commit 6a5ab424c9
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -207,6 +207,8 @@ type Strategy struct {
HedgeStrategy HedgeStrategy `json:"hedgeStrategy"`
HedgeMaxOrderQuantity fixedpoint.Value `json:"hedgeMaxOrderQuantity"`
FullReplenishInterval types.Duration `json:"fullReplenishInterval"`
OrderCancelWaitTime types.Duration `json:"orderCancelWaitTime"`
@ -599,6 +601,11 @@ func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) error {
quantity := pos.Abs()
if s.HedgeMaxOrderQuantity.Sign() > 0 {
s.logger.Infof("hedgeMaxOrderQuantity is set to %s, limiting the given quantity %s", s.HedgeMaxOrderQuantity.String(), quantity.String())
quantity = fixedpoint.Min(s.HedgeMaxOrderQuantity, quantity)
}
switch s.HedgeStrategy {
case HedgeStrategyMarket:
return s.executeHedgeMarket(ctx, side, quantity)