code.vegaprotocol.io/vega@v0.79.0/core/events/expired_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  // ExpiredOrders contains the market and parties that needed to have their orders closed in order
    25  // to maintain their open positions on the market.
    26  type ExpiredOrders struct {
    27  	*Base
    28  
    29  	pb eventspb.ExpiredOrders
    30  }
    31  
    32  func NewExpiredOrdersEvent(ctx context.Context, marketID string, orders []string) *ExpiredOrders {
    33  	return &ExpiredOrders{
    34  		Base: newBase(ctx, ExpiredOrdersEvent),
    35  		pb: eventspb.ExpiredOrders{
    36  			MarketId: marketID,
    37  			OrderIds: orders,
    38  		},
    39  	}
    40  }
    41  
    42  func (d ExpiredOrders) MarketID() string {
    43  	return d.pb.MarketId
    44  }
    45  
    46  func (d ExpiredOrders) OrderIDs() []string {
    47  	return d.pb.OrderIds
    48  }
    49  
    50  func (d ExpiredOrders) CompositeCount() uint64 {
    51  	return uint64(len(d.pb.OrderIds))
    52  }
    53  
    54  func (d ExpiredOrders) IsMarket(marketID string) bool {
    55  	return d.pb.MarketId == marketID
    56  }
    57  
    58  func (d ExpiredOrders) Proto() eventspb.ExpiredOrders {
    59  	return d.pb
    60  }
    61  
    62  func (d ExpiredOrders) StreamMessage() *eventspb.BusEvent {
    63  	busEvent := newBusEventFromBase(d.Base)
    64  	cpy := d.pb
    65  	busEvent.Event = &eventspb.BusEvent_ExpiredOrders{
    66  		ExpiredOrders: &cpy,
    67  	}
    68  
    69  	return busEvent
    70  }
    71  
    72  func (d ExpiredOrders) StreamMarketMessage() *eventspb.BusEvent {
    73  	return d.StreamMessage()
    74  }
    75  
    76  func ExpiredOrdersEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ExpiredOrders {
    77  	m := be.GetExpiredOrders()
    78  	return &ExpiredOrders{
    79  		Base: newBaseFromBusEvent(ctx, ExpiredOrdersEvent, be),
    80  		pb:   *m,
    81  	}
    82  }