code.vegaprotocol.io/vega@v0.79.0/core/events/events.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  	"code.vegaprotocol.io/vega/core/types"
    20  	"code.vegaprotocol.io/vega/libs/num"
    21  )
    22  
    23  // MarketPosition is an event with a change to a position.
    24  type MarketPosition interface {
    25  	Party() string
    26  	Size() int64
    27  	Buy() int64
    28  	Sell() int64
    29  	Price() *num.Uint
    30  	BuySumProduct() *num.Uint
    31  	SellSumProduct() *num.Uint
    32  	VWBuy() *num.Uint
    33  	VWSell() *num.Uint
    34  	AverageEntryPrice() *num.Uint
    35  }
    36  
    37  // TradeSettlement Part of the SettlePosition interface -> traces trades as they happened.
    38  type TradeSettlement interface {
    39  	Size() int64
    40  	Price() *num.Uint
    41  	MarketPrice() *num.Uint
    42  }
    43  
    44  // LossSocialization ...
    45  type LossSocialization interface {
    46  	MarketID() string
    47  	PartyID() string
    48  	AmountLost() int64
    49  }
    50  
    51  // SettlePosition is an event that the settlement buffer will propagate through the system
    52  // used by the plugins (currently only the positions API).
    53  type SettlePosition interface {
    54  	MarketID() string
    55  	Trades() []TradeSettlement
    56  	Margin() (uint64, bool)
    57  	Party() string
    58  	Price() uint64
    59  }
    60  
    61  // FeeTransfer is a transfer initiated after trade occurs.
    62  type FeesTransfer interface {
    63  	// The list of transfers to be made by the collateral
    64  	Transfers() []*types.Transfer
    65  	// The total amount of fees to be paid (all cumulated)
    66  	// per party if all the  transfers are to be executed
    67  	// map is party id -> total amount of fees to be transferred
    68  	TotalFeesAmountPerParty() map[string]*num.Uint
    69  }
    70  
    71  // Transfer is an event passed on by settlement engine, contains position
    72  // and the resulting transfer for the collateral engine to use. We need MarketPosition
    73  // because we can't loose the long/short status of the open positions.
    74  type Transfer interface {
    75  	MarketPosition
    76  	Transfer() *types.Transfer
    77  }
    78  
    79  // Margin is an event with a change to balances after settling e.g. MTM.
    80  type Margin interface {
    81  	MarketPosition
    82  	Asset() string
    83  	MarginBalance() *num.Uint
    84  	OrderMarginBalance() *num.Uint
    85  	GeneralBalance() *num.Uint
    86  	BondBalance() *num.Uint
    87  	MarketID() string
    88  	MarginShortFall() *num.Uint
    89  	// as opposed to the GeneralBalance() which actually returns the available balance (general+bond)
    90  	// this returns the actual balance of the general account
    91  	GeneralAccountBalance() *num.Uint
    92  }
    93  
    94  // Risk is an event that summarizes everything and an eventual update to margin account.
    95  type Risk interface {
    96  	Margin
    97  	Amount() *num.Uint
    98  	Transfer() *types.Transfer // I know, it's included in the Transfer interface, but this is to make it clear that this particular func is masked at this level
    99  	MarginLevels() *types.MarginLevels
   100  }