Skip to content

Commit

Permalink
fix: Add missing initialisation for max stop orders in spots
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 committed Apr 16, 2024
1 parent 1d53ad7 commit 359f032
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- [11089](https://github.com/vegaprotocol/vega/issues/11089) - Add tests for proto `enums` persisted to database.
- [11105](https://github.com/vegaprotocol/vega/issues/11105) - Include all paid fees in reward cap.
- [1109](https://github.com/vegaprotocol/core-test-coverage/issues/1109) - Correctly label acceptance coverage for `0042-LIQF-091`.
- [11130](https://github.com/vegaprotocol/vega/issues/11130) - Add missing initialisation for max stop orders in spots.

## 0.75.0

Expand Down
2 changes: 2 additions & 0 deletions core/execution/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ func (e *Engine) propagateSpotInitialNetParams(ctx context.Context, mkt *spot.Ma
mkt.OnMarketLiquidityV2StakeToCCYVolume(e.npv.liquidityV2StakeToCCYVolume)
}

mkt.OnMarketPartiesMaximumStopOrdersUpdate(ctx, e.npv.marketPartiesMaximumStopOrdersUpdate)

e.propagateSLANetParams(ctx, mkt, isRestore)
return nil
}
Expand Down
40 changes: 39 additions & 1 deletion core/execution/engine_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"code.vegaprotocol.io/vega/libs/proto"
"code.vegaprotocol.io/vega/logging"
"code.vegaprotocol.io/vega/protos/vega"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
datapb "code.vegaprotocol.io/vega/protos/vega/data/v1"
snapshot "code.vegaprotocol.io/vega/protos/vega/snapshot/v1"

Expand Down Expand Up @@ -124,6 +125,7 @@ func createEngine(t *testing.T) (*execution.Engine, *gomock.Controller) {
timeService.EXPECT().GetTimeNow().AnyTimes()

collateralService := mocks.NewMockCollateral(ctrl)
collateralService.EXPECT().HasGeneralAccount(gomock.Any(), gomock.Any()).Return(true).AnyTimes()
collateralService.EXPECT().GetPartyMargin(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
collateralService.EXPECT().AssetExists(gomock.Any()).AnyTimes().Return(true)
collateralService.EXPECT().CreateMarketAccounts(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
Expand Down Expand Up @@ -210,6 +212,10 @@ func getSpotMarketConfig() *types.Market {
InfrastructureFee: num.DecimalFromFloat(0.1),
LiquidityFee: num.DecimalFromFloat(0.1),
},
LiquidityFeeSettings: &types.LiquidityFeeSettings{
Method: types.LiquidityFeeMethodConstant,
FeeConstant: num.DecimalFromFloat(0.001),
},
},
LiquiditySLAParams: &types.LiquiditySLAParams{
PriceRange: num.DecimalFromFloat(0.05),
Expand Down Expand Up @@ -504,7 +510,7 @@ func TestValidMarketSnapshot(t *testing.T) {
}

func TestValidSpotMarketSnapshot(t *testing.T) {
ctx := context.Background()
ctx := vgcontext.WithTraceID(context.Background(), hex.EncodeToString([]byte("0deadbeef")))
engine, ctrl := createEngine(t)
defer ctrl.Finish()
assert.NotNil(t, engine)
Expand All @@ -513,6 +519,9 @@ func TestValidSpotMarketSnapshot(t *testing.T) {
err := engine.SubmitSpotMarket(ctx, marketConfig, "", time.Now())
assert.NoError(t, err)

marketConfig.State = types.MarketStateActive
engine.OnTick(ctx, time.Now())

err = engine.SubmitLiquidityProvision(ctx, &types.LiquidityProvisionSubmission{
MarketID: marketConfig.ID,
CommitmentAmount: num.NewUint(1000),
Expand Down Expand Up @@ -580,6 +589,35 @@ func TestValidSpotMarketSnapshot(t *testing.T) {
assert.True(t, bytes.Equal(b, b2))
}
}
submissionProto := &commandspb.StopOrdersSubmission{
FallsBelow: &commandspb.StopOrderSetup{
OrderSubmission: &commandspb.OrderSubmission{
MarketId: marketConfig.ID,
Price: "100",
Size: 20,
Side: vega.Side_SIDE_BUY,
TimeInForce: vega.Order_TIME_IN_FORCE_FOK,
ExpiresAt: 12345,
Type: vega.Order_TYPE_LIMIT,
Reference: "ref_buy",
},
},
RisesAbove: &commandspb.StopOrderSetup{
OrderSubmission: &commandspb.OrderSubmission{
MarketId: marketConfig.ID,
Price: "200",
Size: 10,
Side: vega.Side_SIDE_SELL,
TimeInForce: vega.Order_TIME_IN_FORCE_GFA,
ExpiresAt: 54321,
Type: vega.Order_TYPE_MARKET,
Reference: "ref_sell",
},
},
}

stopSubmission, _ := types.NewStopOrderSubmissionFromProto(submissionProto)
require.NotPanics(t, func() { engine2.SubmitStopOrders(ctx, stopSubmission, "zohar", nil, nil, nil) })
}

func TestValidSettledMarketSnapshot(t *testing.T) {
Expand Down

0 comments on commit 359f032

Please sign in to comment.