code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/party_cancels_stop_orders.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 steps 17 18 import ( 19 "context" 20 21 "code.vegaprotocol.io/vega/core/integration/stubs" 22 "code.vegaprotocol.io/vega/core/types" 23 24 "github.com/cucumber/godog" 25 ) 26 27 func PartiesCancelTheFollowingStopOrders( 28 broker *stubs.BrokerStub, 29 exec Execution, 30 table *godog.Table, 31 ) error { 32 for _, r := range parseCancelStopOrderTable(table) { 33 row := cancelStopOrderRow{row: r} 34 35 party := row.Party() 36 var err error 37 38 order, err := broker.GetStopByReference(party, row.Reference()) 39 if err != nil { 40 return errOrderNotFound(row.Reference(), party, err) 41 } 42 cancel := types.StopOrdersCancellation{ 43 OrderID: order.StopOrder.Id, 44 MarketID: order.StopOrder.MarketId, 45 } 46 err = exec.CancelStopOrder(context.Background(), &cancel, party) 47 48 err = checkExpectedError(row, err, nil) 49 if err != nil { 50 return err 51 } 52 } 53 54 return nil 55 } 56 57 func PartyCancelsAllTheirStopOrders( 58 exec Execution, 59 partyID string, 60 ) error { 61 cancel := types.StopOrdersCancellation{ 62 OrderID: "", 63 MarketID: "", 64 } 65 _ = exec.CancelStopOrder(context.Background(), &cancel, partyID) 66 return nil 67 } 68 69 func PartyCancelsAllTheirStopOrdersForTheMarket( 70 exec Execution, 71 partyID string, 72 marketID string, 73 ) error { 74 cancel := types.StopOrdersCancellation{ 75 OrderID: "", 76 MarketID: marketID, 77 } 78 _ = exec.CancelStopOrder(context.Background(), &cancel, partyID) 79 return nil 80 } 81 82 type cancelStopOrderRow struct { 83 row RowWrapper 84 } 85 86 func parseCancelStopOrderTable(table *godog.Table) []RowWrapper { 87 return StrictParseTable(table, []string{ 88 "party", 89 "reference", 90 }, []string{ 91 "error", 92 }) 93 } 94 95 func (r cancelStopOrderRow) Party() string { 96 return r.row.MustStr("party") 97 } 98 99 func (r cancelStopOrderRow) Reference() string { 100 return r.row.Str("reference") 101 } 102 103 func (r cancelStopOrderRow) Error() string { 104 return r.row.Str("error") 105 } 106 107 func (r cancelStopOrderRow) ExpectError() bool { 108 return r.row.HasColumn("error") 109 }