Skip to content

Commit

Permalink
Merge pull request #3647 from vegaprotocol/feature/lp-pegged-orders-f…
Browse files Browse the repository at this point in the history
…ix-entering-auction

ensure lp order are not submitted if entering auction
  • Loading branch information
EVODelavega committed Jun 24, 2021
2 parents 2327da4 + 07fec96 commit 6a502e0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
13 changes: 13 additions & 0 deletions execution/liquidity_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func (m *Market) updateAndCreateLPOrders(

mktID := m.GetID()
asset, _ := m.mkt.GetAsset()
var enteredAuction bool
for _, order := range newOrders {
// before we submit orders, we check if the party was pending
// and save the amount of the margin balance.
Expand Down Expand Up @@ -291,6 +292,12 @@ func (m *Market) updateAndCreateLPOrders(
logging.Order(*order))
}

// did we enter auction
if m.as.InAuction() {
enteredAuction = true
break
}

orderUpdates = append(orderUpdates, orderUpdts...)
faultyLPs[order.PartyId] = false
}
Expand Down Expand Up @@ -351,6 +358,12 @@ func (m *Market) updateAndCreateLPOrders(
_ = m.equityShares.Shares(m.liquidity.GetInactiveParties())
}

// if we are in an option, there's nothing to be done with these
// updates specifically, let's just return
if enteredAuction {
orderUpdates = nil
}

return orderUpdates, nil
}

Expand Down
2 changes: 2 additions & 0 deletions execution/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ func (m *Market) LeaveAuction(ctx context.Context, now time.Time) {
m.broker.Send(endEvt)

m.checkForReferenceMoves(ctx, updatedOrders, true)
m.checkLiquidity(ctx, nil)
m.commandLiquidityAuction(ctx)

m.updateLiquidityFee(ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion execution/reference_price_moves.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func (o OrderReferenceCheck) HasMoved(changes uint8) bool {
func (m *Market) checkForReferenceMoves(
ctx context.Context, orderUpdates []*types.Order, forceUpdate bool,
) {

if m.as.InAuction() {
return
}

newBestBid, _ := m.getBestStaticBidPrice()
newBestAsk, _ := m.getBestStaticAskPrice()
newMidBuy, _ := m.getStaticMidPrice(types.Side_SIDE_BUY)
Expand Down
32 changes: 24 additions & 8 deletions execution/special_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (m *Market) repricePeggedOrders(
func (m *Market) reSubmitPeggedOrders(
ctx context.Context,
toSubmitOrders []*types.Order,
) []*types.Order {
) (_ []*types.Order, enteredAuction bool) {
updatedOrders := []*types.Order{}

// Reinsert all the orders
Expand All @@ -83,13 +83,19 @@ func (m *Market) reSubmitPeggedOrders(
m.log.Panic("submitting pegged orders after a reprice should never trade",
logging.Order(*order))
}

if m.as.InAuction() {
enteredAuction = true
return
}

if err == nil {
updatedOrders = append(updatedOrders, conf.Order)
}
updatedOrders = append(updatedOrders, updts...)
}

return updatedOrders
return updatedOrders, false
}

func (m *Market) repriceAllSpecialOrders(
Expand Down Expand Up @@ -121,15 +127,12 @@ func (m *Market) repriceAllSpecialOrders(
for _, order := range lpOrders {
// Remove order if any volume remains,
// otherwise it's already been popped by the matching engine.
cancellation, err := m.matching.CancelOrder(order)
cancellation, err := m.cancelOrder(ctx, order.PartyId, order.Id)
if cancellation == nil || err != nil {
m.log.Panic("could not remove liquidity order from the book",
logging.Order(*order),
logging.Error(err))
}

// Remove it from the trader position
_ = m.position.UnregisterOrder(order)
}

// now no lp orders are in the book anymore,
Expand All @@ -138,7 +141,12 @@ func (m *Market) repriceAllSpecialOrders(
// let's do it now
var updatedPegged []*types.Order
if needsPeggedUpdates {
updatedPegged = m.reSubmitPeggedOrders(ctx, toSubmit)
var enteredAuction bool
updatedPegged, enteredAuction = m.reSubmitPeggedOrders(ctx, toSubmit)
if enteredAuction {
// returning nil will stop reference price moves updates
return nil
}
}

orderUpdates = append(orderUpdates, parked...)
Expand Down Expand Up @@ -244,7 +252,7 @@ func (m *Market) updateLPOrders(

// these order were actually cancelled, just send the event
if _, ok := cancelIDs[order.Id]; ok {
cancelEvts = append(cancelEvts, events.NewOrderEvent(ctx, order))
// cancelEvts = append(cancelEvts, events.NewOrderEvent(ctx, order))
// these orders were submitted exactly the same before,
// so there's no reason we would not be able to submit
// let's panic if an issue happen
Expand All @@ -260,6 +268,14 @@ func (m *Market) updateLPOrders(
logging.Order(*order))
}
}

// if an auction has been started, we just break now
if m.as.InAuction() {
// enteredAuction = true
// auctionFrom = i
// break
return nil
}
}

// send cancel events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Feature: Replicate issue 3528, where price monitoring continuously extended liqu
When the network moves ahead "290" blocks
Then the market data for the market "ETH/DEC21" should be:
| mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | auction end |
| 1020 | TRADING_MODE_CONTINUOUS | 1 | 1010 | 1030 | 3162 | 10000 | 31 | 0 |
| 1030 | TRADING_MODE_CONTINUOUS | 1 | 1020 | 1040 | 3090 | 10000 | 30 | 0 |

Scenario: Enter liquidity auction, extended by trades at liq. auction end, multiple trades -> still a single extension

Expand Down Expand Up @@ -235,7 +235,7 @@ Feature: Replicate issue 3528, where price monitoring continuously extended liqu
When the network moves ahead "290" blocks
Then the market data for the market "ETH/DEC21" should be:
| mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | auction end |
| 1020 | TRADING_MODE_CONTINUOUS | 1 | 1010 | 1030 | 3162 | 10000 | 31 | 0 |
| 1030 | TRADING_MODE_CONTINUOUS | 1 | 1020 | 1040 | 3090 | 10000 | 30 | 0 |

Scenario: When in liquidity auction, we should only trigger price extension once

Expand Down

0 comments on commit 6a502e0

Please sign in to comment.