code.vegaprotocol.io/vega@v0.79.0/core/matching/marketorders_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 TestOrderBook_MarketOrderFOKNotFilledResponsePrice(t *testing.T) { 28 market := "testMarket" 29 book := getTestOrderBook(t, market) 30 defer book.Finish() 31 order := types.Order{ 32 MarketID: market, 33 Party: "A", 34 Side: types.SideBuy, 35 Size: 10, 36 Remaining: 10, 37 TimeInForce: types.OrderTimeInForceFOK, 38 Type: types.OrderTypeMarket, 39 } 40 confirm, err := book.SubmitOrder(&order) 41 assert.NoError(t, err) 42 43 // Verify that the response price for the unfilled order is zero 44 assert.NotEqual(t, (*types.OrderConfirmation)(nil), confirm) 45 assert.Equal(t, uint64(0), confirm.Order.Price.Uint64()) 46 } 47 48 func TestOrderBook_MarketOrderIOCNotFilledResponsePrice(t *testing.T) { 49 market := "testMarket" 50 book := getTestOrderBook(t, market) 51 defer book.Finish() 52 order := types.Order{ 53 MarketID: market, 54 Party: "A", 55 Side: types.SideBuy, 56 Size: 10, 57 Remaining: 10, 58 TimeInForce: types.OrderTimeInForceIOC, 59 Type: types.OrderTypeMarket, 60 } 61 confirm, err := book.SubmitOrder(&order) 62 assert.NoError(t, err) 63 64 // Verify that the response price for the unfilled order is zero 65 assert.NotEqual(t, (*types.OrderConfirmation)(nil), confirm) 66 assert.Equal(t, uint64(0), confirm.Order.Price.Uint64()) 67 } 68 69 func TestOrderBook_MarketOrderFOKPartiallyFilledResponsePrice(t *testing.T) { 70 market := "testMarket" 71 book := getTestOrderBook(t, market) 72 defer book.Finish() 73 order := types.Order{ 74 MarketID: market, 75 Party: "A", 76 Side: types.SideSell, 77 Price: num.NewUint(100), 78 OriginalPrice: num.NewUint(100), 79 Size: 6, 80 Remaining: 6, 81 TimeInForce: types.OrderTimeInForceGTC, 82 Type: types.OrderTypeLimit, 83 } 84 _, err := book.SubmitOrder(&order) 85 assert.NoError(t, err) 86 87 order = types.Order{ 88 MarketID: market, 89 Party: "A", 90 Side: types.SideBuy, 91 Size: 10, 92 Remaining: 10, 93 TimeInForce: types.OrderTimeInForceFOK, 94 Type: types.OrderTypeMarket, 95 } 96 confirm, err := book.SubmitOrder(&order) 97 assert.NoError(t, err) 98 99 // Verify that the response price for the unfilled order is zero 100 assert.NotEqual(t, (*types.OrderConfirmation)(nil), confirm) 101 assert.Equal(t, uint64(0), confirm.Order.Price.Uint64()) 102 103 // Nothing was filled 104 assert.Equal(t, uint64(10), confirm.Order.Remaining) 105 106 // No orders 107 assert.Nil(t, confirm.Trades) 108 assert.Nil(t, confirm.PassiveOrdersAffected) 109 } 110 111 func TestOrderBook_MarketOrderIOCPartiallyFilledResponsePrice(t *testing.T) { 112 market := "testMarket" 113 book := getTestOrderBook(t, market) 114 defer book.Finish() 115 order := types.Order{ 116 MarketID: market, 117 Party: "A", 118 Side: types.SideSell, 119 Price: num.NewUint(100), 120 OriginalPrice: num.NewUint(100), 121 Size: 6, 122 Remaining: 6, 123 TimeInForce: types.OrderTimeInForceGTC, 124 Type: types.OrderTypeLimit, 125 } 126 _, err := book.SubmitOrder(&order) 127 assert.NoError(t, err) 128 129 order2 := types.Order{ 130 MarketID: market, 131 Party: "B", 132 Side: types.SideBuy, 133 Size: 10, 134 Remaining: 10, 135 TimeInForce: types.OrderTimeInForceIOC, 136 Type: types.OrderTypeMarket, 137 } 138 confirm, err := book.SubmitOrder(&order2) 139 assert.NoError(t, err) 140 141 // Verify that the response price for the unfilled order is zero 142 assert.NotEqual(t, (*types.OrderConfirmation)(nil), confirm) 143 assert.Equal(t, uint64(0), confirm.Order.Price.Uint64()) 144 145 // Something was filled 146 assert.Equal(t, uint64(4), confirm.Order.Remaining) 147 148 // One order 149 assert.Equal(t, 1, len(confirm.Trades)) 150 assert.Equal(t, 1, len(confirm.PassiveOrdersAffected)) 151 }