code.vegaprotocol.io/vega@v0.79.0/core/matching/can_uncross_test.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 matching
    17  
    18  import (
    19  	"testing"
    20  
    21  	"code.vegaprotocol.io/vega/core/types"
    22  	"code.vegaprotocol.io/vega/libs/num"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func TestBidAndAskPresentAfterAuction(t *testing.T) {
    28  	market := "market"
    29  	book := getTestOrderBook(t, market)
    30  	defer book.Finish()
    31  
    32  	// start an auction
    33  	_ = book.EnterAuction()
    34  
    35  	orders := []types.Order{
    36  		{
    37  			MarketID:    market,
    38  			Party:       "party-1",
    39  			Side:        types.SideBuy,
    40  			Price:       num.NewUint(2000),
    41  			Size:        5,
    42  			Remaining:   5,
    43  			TimeInForce: types.OrderTimeInForceGTC,
    44  			Type:        types.OrderTypeLimit,
    45  		},
    46  		{
    47  			MarketID:    market,
    48  			Party:       "party-1",
    49  			Side:        types.SideSell,
    50  			Price:       num.NewUint(2000),
    51  			Size:        5,
    52  			Remaining:   5,
    53  			TimeInForce: types.OrderTimeInForceGTC,
    54  			Type:        types.OrderTypeLimit,
    55  		},
    56  		{
    57  			MarketID:    market,
    58  			Party:       "party-1",
    59  			Side:        types.SideBuy,
    60  			Price:       num.NewUint(1900),
    61  			Size:        5,
    62  			Remaining:   5,
    63  			TimeInForce: types.OrderTimeInForceGTC,
    64  			Type:        types.OrderTypeLimit,
    65  		},
    66  		{
    67  			MarketID:    market,
    68  			Party:       "party-1",
    69  			Side:        types.SideSell,
    70  			Price:       num.NewUint(1950),
    71  			Size:        5,
    72  			Remaining:   5,
    73  			TimeInForce: types.OrderTimeInForceGTC,
    74  			Type:        types.OrderTypeLimit,
    75  		},
    76  	}
    77  
    78  	for _, order := range orders {
    79  		_, err := book.SubmitOrder(&order)
    80  		assert.NoError(t, err)
    81  	}
    82  
    83  	r := book.GetIndicativePriceAndVolume()
    84  	assert.Equal(t, r.price.Uint64(), uint64(1975))
    85  	assert.Equal(t, int(r.volume), 5)
    86  	assert.Equal(t, r.side, types.SideBuy)
    87  	assert.True(t, book.BidAndAskPresentAfterAuction())
    88  }
    89  
    90  func TestBidAndAskPresentAfterAuctionInverse(t *testing.T) {
    91  	market := "market"
    92  	book := getTestOrderBook(t, market)
    93  	defer book.Finish()
    94  
    95  	// start an auction
    96  	_ = book.EnterAuction()
    97  
    98  	orders := []types.Order{
    99  		{
   100  			MarketID:    market,
   101  			Party:       "party-1",
   102  			Side:        types.SideBuy,
   103  			Price:       num.NewUint(2000),
   104  			Size:        5,
   105  			Remaining:   5,
   106  			TimeInForce: types.OrderTimeInForceGTC,
   107  			Type:        types.OrderTypeLimit,
   108  		},
   109  		{
   110  			MarketID:    market,
   111  			Party:       "party-1",
   112  			Side:        types.SideSell,
   113  			Price:       num.NewUint(2050),
   114  			Size:        5,
   115  			Remaining:   5,
   116  			TimeInForce: types.OrderTimeInForceGTC,
   117  			Type:        types.OrderTypeLimit,
   118  		},
   119  		{
   120  			MarketID:    market,
   121  			Party:       "party-1",
   122  			Side:        types.SideBuy,
   123  			Price:       num.NewUint(1900),
   124  			Size:        5,
   125  			Remaining:   5,
   126  			TimeInForce: types.OrderTimeInForceGTC,
   127  			Type:        types.OrderTypeLimit,
   128  		},
   129  		{
   130  			MarketID:    market,
   131  			Party:       "party-1",
   132  			Side:        types.SideSell,
   133  			Price:       num.NewUint(1900),
   134  			Size:        5,
   135  			Remaining:   5,
   136  			TimeInForce: types.OrderTimeInForceGTC,
   137  			Type:        types.OrderTypeLimit,
   138  		},
   139  	}
   140  
   141  	for _, order := range orders {
   142  		_, err := book.SubmitOrder(&order)
   143  		assert.NoError(t, err)
   144  	}
   145  
   146  	r := book.GetIndicativePriceAndVolume()
   147  	assert.Equal(t, r.price.Uint64(), uint64(1950))
   148  	assert.Equal(t, int(r.volume), 5)
   149  	assert.Equal(t, r.side, types.SideBuy)
   150  	assert.True(t, book.BidAndAskPresentAfterAuction())
   151  }