code.vegaprotocol.io/vega@v0.79.0/core/events/order.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 "code.vegaprotocol.io/vega/core/types" 22 "code.vegaprotocol.io/vega/libs/num" 23 ptypes "code.vegaprotocol.io/vega/protos/vega" 24 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 25 ) 26 27 type Order struct { 28 *Base 29 o *ptypes.Order 30 } 31 32 func NewOrderEvent(ctx context.Context, o *types.Order) *Order { 33 order := &Order{ 34 Base: newBase(ctx, OrderEvent), 35 o: o.IntoProto(), 36 } 37 // set to original order price 38 order.o.Price = num.UintToString(o.OriginalPrice) 39 return order 40 } 41 42 func (o Order) IsParty(id string) bool { 43 return o.o.PartyId == id 44 } 45 46 func (o Order) PartyID() string { 47 return o.o.PartyId 48 } 49 50 func (o Order) MarketID() string { 51 return o.o.MarketId 52 } 53 54 func (o *Order) Order() *ptypes.Order { 55 return o.o 56 } 57 58 func (o Order) Proto() ptypes.Order { 59 return *o.o 60 } 61 62 func (o Order) StreamMessage() *eventspb.BusEvent { 63 busEvent := newBusEventFromBase(o.Base) 64 busEvent.Event = &eventspb.BusEvent_Order{ 65 Order: o.o, 66 } 67 68 return busEvent 69 } 70 71 func OrderEventFromStream(ctx context.Context, be *eventspb.BusEvent) *Order { 72 order := &Order{ 73 Base: newBaseFromBusEvent(ctx, OrderEvent, be), 74 o: be.GetOrder(), 75 } 76 return order 77 }