Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leave auction do not trigger leave auction #3363

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion execution/liquidity_provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,6 @@ func TestParkOrderPanicOrderNotFoundInBook(t *testing.T) {

tm.events = nil
t.Run("party place a new order which should unpark the pegged order", func(t *testing.T) {
tm.market.OnChainTimeUpdate(ctx, auctionEnd.Add(10*time.Second))
o := getMarketOrder(tm, now, types.Order_TYPE_LIMIT, types.Order_TIME_IN_FORCE_GTC, "Order02", types.Side_SIDE_SELL, party4, 10, 2400)
conf, err := tm.market.SubmitOrder(ctx, o)
assert.NoError(t, err)
Expand All @@ -1945,6 +1944,7 @@ func TestParkOrderPanicOrderNotFoundInBook(t *testing.T) {
conf2, err := tm.market.SubmitOrder(ctx, o2)
assert.NoError(t, err)
assert.NotNil(t, conf2)
tm.market.OnChainTimeUpdate(ctx, auctionEnd.Add(10*time.Second))
})

t.Run("pegged order is REJECTED", func(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions execution/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,9 @@ func (m *Market) LeaveAuction(ctx context.Context, now time.Time) {
for _, order := range ordersToCancel {
_, err := m.cancelOrder(ctx, order.PartyId, order.Id)
if err != nil {
m.log.Error("Failed to cancel order", logging.String("OrderID", order.Id))
m.log.Panic("Failed to cancel order",
logging.Error(err),
logging.String("OrderID", order.Id))
}
}

Expand Down Expand Up @@ -1374,6 +1376,7 @@ func (m *Market) checkPriceAndGetTrades(ctx context.Context, order *types.Order)
logging.Error(merr))
}
}

if evt := m.as.AuctionExtended(ctx); evt != nil {
m.broker.Send(evt)
}
Expand Down Expand Up @@ -2232,6 +2235,7 @@ func (m *Market) cancelOrder(ctx context.Context, partyID, orderID string) (*typ
m.log.Debug("liquidity update error", logging.Error(err))
}
}

m.checkLiquidity(ctx, nil)
m.commandLiquidityAuction(ctx)

Expand Down Expand Up @@ -3522,9 +3526,7 @@ func (m *Market) commandLiquidityAuction(ctx context.Context) {
// TODO: Need to also get indicative trades and check how they'd impact target stake,
// see https://github.com/vegaprotocol/vega/issues/3047
// If price monitoring doesn't trigger auction than leave it
if m.as.AuctionEnd() && m.matching.BidAndAskPresentAfterAuction() {
m.LeaveAuction(ctx, m.currentTime)
} else if evt := m.as.AuctionExtended(ctx); evt != nil {
if evt := m.as.AuctionExtended(ctx); evt != nil {
m.broker.Send(evt)
}
}
Expand Down
73 changes: 73 additions & 0 deletions integration/features/wrong-position-tracking.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Feature: Test position tracking with auctions

Background:

And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | oracle config |
| ETH/DEC19 | ETH | ETH | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-basic | default-eth-for-future |
And the following network parameters are set:
| market.auction.minimumDuration |
| 1 |
And the oracles broadcast data signed with "0xDEADBEEF":
| name | value |
| prices.ETH.value | 42 |

Scenario:
Given the traders deposit on asset's general account the following amount:
| trader | asset | amount |
| trader0 | ETH | 1000000000 |
| trader1 | ETH | 1000000000 |
| trader2 | ETH | 1000000000 |
| trader3 | ETH | 1000000000 |
| traderlp | ETH | 1000000000 |
| ruser | ETH | 75000 |

# submit our LP
Then the traders submit the following liquidity provision:
| id | party | market id | commitment amount | fee | order side | order reference | order proportion | order offset |
| lp1 | traderlp | ETH/DEC19 | 16000000 | 0.3 | buy | BID | 2 | -10 |
| lp1 | traderlp | ETH/DEC19 | 16000000 | 0.3 | sell | ASK | 13 | 10 |

# get out of auction
When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif | reference |
| trader0 | ETH/DEC19 | buy | 1 | 100000 | 0 | TYPE_LIMIT | TIF_GTC | t0-b-1 |
| trader1 | ETH/DEC19 | sell | 1 | 100000 | 0 | TYPE_LIMIT | TIF_GTC | t1-s-1 |
| trader0 | ETH/DEC19 | buy | 5 | 95000 | 0 | TYPE_LIMIT | TIF_GTC | t0-b-2 |
| trader1 | ETH/DEC19 | sell | 5 | 107000 | 0 | TYPE_LIMIT | TIF_GTC | t1-s-2 |

Then the opening auction period ends for market "ETH/DEC19"
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"

When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif | reference |
| trader1 | ETH/DEC19 | sell | 15 | 107500 | 0 | TYPE_LIMIT | TIF_GTC | t1-s-3 |
| trader0 | ETH/DEC19 | buy | 10 | 107100 | 0 | TYPE_LIMIT | TIF_GTC | t1-b-3 |

And the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC19"

When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif | reference |
| trader3 | ETH/DEC19 | buy | 10 | 107300 | 0 | TYPE_LIMIT | TIF_GTC | t3-b-1 |
| trader1 | ETH/DEC19 | sell | 10 | 107100 | 0 | TYPE_LIMIT | TIF_GTC | t1-s-4 |
| ruser | ETH/DEC19 | buy | 50 | 107500 | 0 | TYPE_LIMIT | TIF_GTC | lp-b-1 |
| trader3 | ETH/DEC19 | buy | 70 | 106000 | 0 | TYPE_LIMIT | TIF_GFA | lp-b-1 |

Then the traders place the following pegged orders:
| trader | market id | side | volume | reference | offset |
| ruser | ETH/DEC19 | buy | 35 | BID | -1000 |
| ruser | ETH/DEC19 | sell | 35 | ASK | 3000 |

When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif | reference |
| trader1 | ETH/DEC19 | sell | 80 | 105000 | 0 | TYPE_LIMIT | TIF_GTC | t1-s-5 |
| trader3 | ETH/DEC19 | buy | 81 | 106000 | 0 | TYPE_LIMIT | TIF_GFA | t3-b-2 |
| trader3 | ETH/DEC19 | buy | 86 | 107000 | 0 | TYPE_LIMIT | TIF_GTC | t3-b-3 |

Then the traders place the following pegged orders:
| trader | market id | side | volume | reference | offset |
| trader0 | ETH/DEC19 | buy | 100 | BID | -5000 |
| trader1 | ETH/DEC19 | sell | 95 | ASK | 1000 |

And time is updated to "2019-11-30T00:01:00Z"
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"