code.vegaprotocol.io/vega@v0.79.0/core/events/funding_period.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 FundingPeriod struct {
    25  	*Base
    26  	p *eventspb.FundingPeriod
    27  }
    28  
    29  func NewFundingPeriodEvent(ctx context.Context, marketID string, seq uint64, start int64, end *int64, fundingPayment, fundingRate, iTWAP, eTWAP *string) *FundingPeriod {
    30  	interval := &FundingPeriod{
    31  		Base: newBase(ctx, FundingPeriodEvent),
    32  		p: &eventspb.FundingPeriod{
    33  			MarketId:       marketID,
    34  			Start:          start,
    35  			End:            end,
    36  			FundingPayment: fundingPayment,
    37  			FundingRate:    fundingRate,
    38  			Seq:            seq,
    39  			InternalTwap:   iTWAP,
    40  			ExternalTwap:   eTWAP,
    41  		},
    42  	}
    43  	return interval
    44  }
    45  
    46  func (p *FundingPeriod) FundingPeriod() *eventspb.FundingPeriod {
    47  	return p.p
    48  }
    49  
    50  func (p FundingPeriod) Proto() eventspb.FundingPeriod {
    51  	return *p.p
    52  }
    53  
    54  func (p FundingPeriod) StreamMessage() *eventspb.BusEvent {
    55  	busEvent := newBusEventFromBase(p.Base)
    56  	busEvent.Event = &eventspb.BusEvent_FundingPeriod{
    57  		FundingPeriod: p.p,
    58  	}
    59  	return busEvent
    60  }
    61  
    62  func FundingPeriodEventFromStream(ctx context.Context, be *eventspb.BusEvent) *FundingPeriod {
    63  	return &FundingPeriod{
    64  		Base: newBaseFromBusEvent(ctx, FundingPeriodEvent, be),
    65  		p:    be.GetFundingPeriod(),
    66  	}
    67  }