code.vegaprotocol.io/vega@v0.79.0/core/events/cancelled_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 events
    17  
    18  import (
    19  	"context"
    20  
    21  	eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
    22  )
    23  
    24  type CancelledOrders struct {
    25  	*Base
    26  	pb eventspb.CancelledOrders
    27  }
    28  
    29  func NewCancelledOrdersEvent(ctx context.Context, marketID, partyID string, orders ...string) *CancelledOrders {
    30  	return &CancelledOrders{
    31  		Base: newBase(ctx, CancelledOrdersEvent),
    32  		pb: eventspb.CancelledOrders{
    33  			MarketId: marketID,
    34  			PartyId:  partyID,
    35  			OrderIds: orders,
    36  		},
    37  	}
    38  }
    39  
    40  func (c CancelledOrders) MarketID() string {
    41  	return c.pb.MarketId
    42  }
    43  
    44  func (c CancelledOrders) IsMarket(mID string) bool {
    45  	return c.pb.MarketId == mID
    46  }
    47  
    48  func (c CancelledOrders) PartyID() string {
    49  	return c.pb.PartyId
    50  }
    51  
    52  func (c CancelledOrders) IsParty(pID string) bool {
    53  	return c.pb.PartyId == pID
    54  }
    55  
    56  func (c CancelledOrders) OrderIDs() []string {
    57  	return c.pb.OrderIds
    58  }
    59  
    60  func (c CancelledOrders) CompositeCount() uint64 {
    61  	return uint64(len(c.pb.OrderIds))
    62  }
    63  
    64  func (c CancelledOrders) Proto() eventspb.CancelledOrders {
    65  	return c.pb
    66  }
    67  
    68  func (c CancelledOrders) StreamMessage() *eventspb.BusEvent {
    69  	busEvent := newBusEventFromBase(c.Base)
    70  	cpy := c.pb
    71  	busEvent.Event = &eventspb.BusEvent_CancelledOrders{
    72  		CancelledOrders: &cpy,
    73  	}
    74  
    75  	return busEvent
    76  }
    77  
    78  func (c CancelledOrders) StreamMarketMessage() *eventspb.BusEvent {
    79  	return c.StreamMessage()
    80  }
    81  
    82  func CancelledOrdersEventFromStream(ctx context.Context, be *eventspb.BusEvent) *CancelledOrders {
    83  	m := be.GetCancelledOrders()
    84  	return &CancelledOrders{
    85  		Base: newBaseFromBusEvent(ctx, CancelledOrdersEvent, be),
    86  		pb:   *m,
    87  	}
    88  }