From cf3a644e635a3979a85971d5bc62178c26eb9f54 Mon Sep 17 00:00:00 2001 From: Elias Van Ootegem Date: Thu, 18 Apr 2024 14:22:05 +0100 Subject: [PATCH] chore: review fixes Signed-off-by: Elias Van Ootegem --- core/execution/liquidation/engine.go | 9 +++++---- protos/sources/vega/markets.proto | 2 +- protos/vega/markets.pb.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/execution/liquidation/engine.go b/core/execution/liquidation/engine.go index a9479ee1dde..71884c8c4e0 100644 --- a/core/execution/liquidation/engine.go +++ b/core/execution/liquidation/engine.go @@ -129,18 +129,19 @@ func (e *Engine) Update(cfg *types.LiquidationStrategy) { } func (e *Engine) OnTick(ctx context.Context, now time.Time, midPrice *num.Uint) (*types.Order, error) { - if e.pos.open == 0 || e.as.InAuction() || e.nextStep.After(now) { + if e.pos.open == 0 || e.as.InAuction() || e.nextStep.After(now) || midPrice.IsZero() { return nil, nil } + one := num.DecimalOne() // get the min/max price from the range based on slippage parameter mpDec := num.DecimalFromUint(midPrice) minP := num.UintZero() - if e.cfg.DisposalSlippage.LessThan(num.DecimalZero()) { - minD := mpDec.Mul(num.DecimalZero().Sub(e.cfg.DisposalSlippage)) + if e.cfg.DisposalSlippage.LessThan(one) { + minD := mpDec.Mul(one.Sub(e.cfg.DisposalSlippage)) minP, _ = num.UintFromDecimal(minD) } - maxD := mpDec.Mul(num.DecimalZero().Add(e.cfg.DisposalSlippage)) + maxD := mpDec.Mul(one.Add(e.cfg.DisposalSlippage)) maxP, _ := num.UintFromDecimal(maxD) minB, maxB := e.pmon.GetValidPriceRange() diff --git a/protos/sources/vega/markets.proto b/protos/sources/vega/markets.proto index 4a801fb3727..5335d966c70 100644 --- a/protos/sources/vega/markets.proto +++ b/protos/sources/vega/markets.proto @@ -414,7 +414,7 @@ message LiquidationStrategy { // Max fraction of the total volume of the orderbook, within liquidity bounds, that the network can use to close its position; range 0 through 1. string max_fraction_consumed = 4; // Decimal > 0 defining the price range within which the network will trade to dispose of its position. Retroactively defaults to 0.1 (10%). - // The value can be > 1, if set to 1.5, the minimum price will be 0 (min(0, mid_price * (1 - 1.))), the maximum price will be mid_price * (1 + 1.5). + // The value can be > 1, if set to 1.5, the minimum price will be 0 (max(0, mid_price * (1 - 1.5))), the maximum price will be mid_price * (1 + 1.5). string disposal_slippage_range = 5; } diff --git a/protos/vega/markets.pb.go b/protos/vega/markets.pb.go index 99e0f6c93c6..f5ffbcfc665 100644 --- a/protos/vega/markets.pb.go +++ b/protos/vega/markets.pb.go @@ -2334,7 +2334,7 @@ type LiquidationStrategy struct { // Max fraction of the total volume of the orderbook, within liquidity bounds, that the network can use to close its position; range 0 through 1. MaxFractionConsumed string `protobuf:"bytes,4,opt,name=max_fraction_consumed,json=maxFractionConsumed,proto3" json:"max_fraction_consumed,omitempty"` // Decimal > 0 defining the price range within which the network will trade to dispose of its position. Retroactively defaults to 0.1 (10%). - // The value can be > 1, if set to 1.5, the minimum price will be 0 (min(0, mid_price * (1 - 1.))), the maximum price will be mid_price * (1 + 1.5). + // The value can be > 1, if set to 1.5, the minimum price will be 0 (max(0, mid_price * (1 - 1.5))), the maximum price will be mid_price * (1 + 1.5). DisposalSlippageRange string `protobuf:"bytes,5,opt,name=disposal_slippage_range,json=disposalSlippageRange,proto3" json:"disposal_slippage_range,omitempty"` }