code.vegaprotocol.io/vega@v0.79.0/core/execution/future/reference_price_moves.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package future 17 18 import ( 19 "context" 20 21 "code.vegaprotocol.io/vega/core/execution/common" 22 "code.vegaprotocol.io/vega/core/types" 23 ) 24 25 func (m *Market) checkForReferenceMoves( 26 ctx context.Context, orderUpdates []*types.Order, forceUpdate bool, 27 ) { 28 if m.as.InAuction() { 29 return 30 } 31 32 newBestBid, _ := m.getBestStaticBidPrice() 33 newBestAsk, _ := m.getBestStaticAskPrice() 34 newMidBuy, _ := m.getStaticMidPrice(types.SideBuy) 35 newMidSell, _ := m.getStaticMidPrice(types.SideSell) 36 37 // Look for a move 38 var changes uint8 39 if !forceUpdate { 40 if newMidBuy.NEQ(m.lastMidBuyPrice) || newMidSell.NEQ(m.lastMidSellPrice) { 41 changes |= common.PriceMoveMid 42 } 43 if newBestBid.NEQ(m.lastBestBidPrice) { 44 changes |= common.PriceMoveBestBid 45 } 46 if newBestAsk.NEQ(m.lastBestAskPrice) { 47 changes |= common.PriceMoveBestAsk 48 } 49 } else { 50 changes = common.PriceMoveAll 51 } 52 53 // now we can start all special order repricing... 54 orderUpdates = m.repriceAllSpecialOrders(ctx, changes, orderUpdates) 55 56 // Update the last price values 57 // no need to clone the prices, they're not used in calculations anywhere in this function 58 m.lastMidBuyPrice = newMidBuy 59 m.lastMidSellPrice = newMidSell 60 m.lastBestBidPrice = newBestBid 61 m.lastBestAskPrice = newBestAsk 62 63 // now we had new orderUpdates while processing those, 64 // that would means someone got distressed, so some order 65 // got uncrossed, so we need to check all these again. 66 // we do not use the forceUpdate field here as it's 67 // not required that prices moved though 68 if len(orderUpdates) > 0 { 69 m.checkForReferenceMoves(ctx, orderUpdates, false) 70 } 71 }