Skip to content

Commit

Permalink
Merge pull request #11505 from vegaprotocol/trading-mode-fix
Browse files Browse the repository at this point in the history
fix long block auction market state/trading mode
  • Loading branch information
EVODelavega authored Jul 26, 2024
2 parents 9278fc8 + e37021e commit 3c76178
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
18 changes: 11 additions & 7 deletions core/execution/future/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -1507,21 +1507,24 @@ func (m *Market) EnterLongBlockAuction(ctx context.Context, duration int64) {
return
}

m.mkt.State = types.MarketStateSuspended
m.mkt.TradingMode = types.MarketTradingModelLongBlockAuction
if m.as.InAuction() {
effDuration := int(m.timeService.GetTimeNow().UnixNano()/1e9) + int(duration) - int(m.as.ExpiresAt().UnixNano()/1e9)
if effDuration <= 0 {
// auction remaining:
now := m.timeService.GetTimeNow()
aRemaining := int64(m.as.ExpiresAt().Sub(now) / time.Second)
if aRemaining >= duration {
return
}
m.as.ExtendAuctionLongBlock(types.AuctionDuration{Duration: int64(effDuration)})
evt := m.as.AuctionExtended(ctx, m.timeService.GetTimeNow())
if evt != nil {
m.as.ExtendAuctionLongBlock(types.AuctionDuration{
Duration: duration - aRemaining,
})
if evt := m.as.AuctionExtended(ctx, now); evt != nil {
m.broker.Send(evt)
}
} else {
m.as.StartLongBlockAuction(m.timeService.GetTimeNow(), duration)
m.tradableInstrument.Instrument.UpdateAuctionState(ctx, true)
m.mkt.TradingMode = types.MarketTradingModelLongBlockAuction
m.mkt.State = types.MarketStateSuspended
m.enterAuction(ctx)
m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt))
}
Expand Down Expand Up @@ -1707,6 +1710,7 @@ func (m *Market) leaveAuction(ctx context.Context, now time.Time) {
}

m.mkt.State = types.MarketStateActive
// this probably should get the default trading mode from the market definition.
m.mkt.TradingMode = types.MarketTradingModeContinuous
m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt))

Expand Down
16 changes: 9 additions & 7 deletions core/execution/spot/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,20 +497,22 @@ func (m *Market) EnterLongBlockAuction(ctx context.Context, duration int64) {
return
}

m.mkt.State = types.MarketStateSuspended
m.mkt.TradingMode = types.MarketTradingModelLongBlockAuction
if m.as.InAuction() {
effDuration := int(m.timeService.GetTimeNow().UnixNano()/1e9) + int(duration) - int(m.as.ExpiresAt().UnixNano()/1e9)
if effDuration <= 0 {
now := m.timeService.GetTimeNow()
aRemaining := int64(m.as.ExpiresAt().Sub(now) / time.Second)
if aRemaining >= duration {
return
}
m.as.ExtendAuctionLongBlock(types.AuctionDuration{Duration: int64(effDuration)})
evt := m.as.AuctionExtended(ctx, m.timeService.GetTimeNow())
if evt != nil {
m.as.ExtendAuctionLongBlock(types.AuctionDuration{
Duration: duration - aRemaining,
})
if evt := m.as.AuctionExtended(ctx, now); evt != nil {
m.broker.Send(evt)
}
} else {
m.as.StartLongBlockAuction(m.timeService.GetTimeNow(), duration)
m.mkt.TradingMode = types.MarketTradingModelLongBlockAuction
m.mkt.State = types.MarketStateSuspended
m.enterAuction(ctx)
m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt))
}
Expand Down
17 changes: 12 additions & 5 deletions core/integration/features/auctions/0094-PRAC-008.feature
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,27 @@ Feature: When a market's trigger and extension_trigger are set to represent that
| 1000000 | TRADING_MODE_MONITORING_AUCTION | 2810994378 | 1873996252 | 1 | 602 | AUCTION_TRIGGER_LONG_BLOCK |

# move ahead another minute
When the network moves ahead "60" blocks
When the network moves ahead "1" blocks
# This is strange, it looks as though the trade went through at the end of the auction, but in doing so triggered a second auction?
Then the market data for the market "ETH/DEC20" should be:
| mark price | trading mode | target stake | supplied stake | open interest | extension trigger |
| 1000000 | TRADING_MODE_MONITORING_AUCTION | 2810994378 | 1873996252 | 1 | AUCTION_TRIGGER_LONG_BLOCK |

When the network moves ahead "8m50s" with block duration of "2s"
When the network moves ahead "9m50s" with block duration of "2s"
Then the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_LONG_BLOCK_AUCTION" for the market "ETH/DEC19"

# still in auction, but if we move ahead...
When the network moves ahead "150" blocks
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"
When the network moves ahead "11" blocks
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
And the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC20"
# now move further ahead to leave price auction
# We have moved 1 blocks + 9m50s (9m51) + 11 blocks for a total of 10m2s, the total auction duration
# was 602s, or 10m2s. Leaving the auction will trigger an extension of another 61 seconds
# So the total time in auction would be 11m2s. At this point we're still 61s short.
When the network moves ahead "61" blocks
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"
And the following trades should be executed:
| buyer | price | size | seller |
| party5 | 999998 | 1 | party6 |
Expand Down

0 comments on commit 3c76178

Please sign in to comment.