products

package
v0.77.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDataSourceSpecAndBindingAreRequired is returned when the definition of the
	// data source spec or its binding is missing from the future definition.
	ErrDataSourceSpecAndBindingAreRequired = errors.New("a data source spec and spec binding are required")

	// ErrDataSourceSettlementDataNotSet is returned when the data source has not set the settlement data.
	ErrDataSourceSettlementDataNotSet = errors.New("settlement data is not set")

	// ErrSettlementDataDecimalsNotSupportedByAsset is returned when the decimal data decimal places
	// are more than the asset decimals.
	ErrSettlementDataDecimalsNotSupportedByAsset = errors.New("settlement data decimals not suported by market asset")
)
View Source
var (
	ErrDataPointAlreadyExistsAtTime = errors.New("data-point already exists at timestamp")
	ErrDataPointIsTooOld            = errors.New("data-point is too old")
)
View Source
var (
	// ErrNilProduct signals the product passed in the constructor was nil.
	ErrNilProduct = errors.New("nil product")
	// ErrUnimplementedProduct signal that the product passed to the
	// constructor was not nil, but the code as no knowledge of it.
	ErrUnimplementedProduct = errors.New("unimplemented product")
)
View Source
var ErrNoStateProvidedForPerpsWithSnapshot = errors.New("no state provided to restore perps from a snapshot")

Functions

func NewCachedTWAP added in v0.73.0

func NewCachedTWAP(log *logging.Logger, t int64, auctions *auctionIntervals) *cachedTWAP

func NewCachedTWAPFromSnapshot added in v0.74.0

func NewCachedTWAPFromSnapshot(
	log *logging.Logger,
	t int64,
	auctions *auctionIntervals,
	state *snapshotpb.TWAPData,
	points []*snapshotpb.DataPoint,
) *cachedTWAP

Types

type Broker added in v0.73.0

type Broker interface {
	Send(e events.Event)
	SendBatch(es []events.Event)
}

type CompositePriceOracle added in v0.74.0

type CompositePriceOracle struct {
	// contains filtered or unexported fields
}

func NewCompositePriceOracle added in v0.74.0

func NewCompositePriceOracle(ctx context.Context, oracleEngine OracleEngine, oracleSpec *datasource.Spec, binding *datasource.SpecBindingForCompositePrice, cb spec.OnMatchedData) (*CompositePriceOracle, error)

func (*CompositePriceOracle) GetData added in v0.74.0

func (cpo *CompositePriceOracle) GetData(data common.Data) (*num.Numeric, error)

func (*CompositePriceOracle) GetDecimals added in v0.74.0

func (cpo *CompositePriceOracle) GetDecimals() int64

func (*CompositePriceOracle) UnsubAll added in v0.74.0

func (cpo *CompositePriceOracle) UnsubAll(ctx context.Context)

type Future

type Future struct {
	SettlementAsset string
	QuoteName       string
	// contains filtered or unexported fields
}

Future represent a Future as describe by the market framework.

func NewFuture

func NewFuture(ctx context.Context, log *logging.Logger, f *types.Future, oe OracleEngine, assetDP uint32) (*Future, error)

func (*Future) GetAsset

func (f *Future) GetAsset() string

GetAsset return the asset used by the future.

func (Future) GetCurrentPeriod added in v0.73.0

func (_ Future) GetCurrentPeriod() uint64

func (*Future) GetData added in v0.73.0

func (f *Future) GetData(t int64) *types.ProductData

func (*Future) GetMarginIncrease added in v0.73.0

func (f *Future) GetMarginIncrease(_ int64) num.Decimal

func (*Future) IsTradingTerminated

func (f *Future) IsTradingTerminated() bool

IsTradingTerminated - returns true when the oracle has signalled terminated market.

func (*Future) NotifyOnSettlementData added in v0.58.0

func (f *Future) NotifyOnSettlementData(listener func(context.Context, *num.Numeric))

func (*Future) NotifyOnTradingTerminated

func (f *Future) NotifyOnTradingTerminated(listener func(context.Context, bool))

func (*Future) RestoreSettlementData added in v0.68.0

func (f *Future) RestoreSettlementData(settleData *num.Numeric)

func (*Future) ScaleSettlementDataToDecimalPlaces added in v0.58.0

func (f *Future) ScaleSettlementDataToDecimalPlaces(price *num.Numeric, dp uint32) (*num.Uint, error)

func (*Future) Serialize added in v0.73.0

func (f *Future) Serialize() *snapshotpb.Product

func (*Future) Settle

func (f *Future) Settle(entryPriceInAsset, settlementData *num.Uint, netFractionalPosition num.Decimal) (amt *types.FinancialAmount, neg bool, rounding num.Decimal, err error)

Settle a position against the future.

func (*Future) SubmitDataPoint added in v0.73.0

func (f *Future) SubmitDataPoint(_ context.Context, _ *num.Uint, _ int64) error

func (*Future) Unsubscribe

func (f *Future) Unsubscribe(ctx context.Context)

func (*Future) UnsubscribeSettlementData added in v0.58.0

func (f *Future) UnsubscribeSettlementData(ctx context.Context)

func (*Future) UnsubscribeTradingTerminated added in v0.55.0

func (f *Future) UnsubscribeTradingTerminated(ctx context.Context)

func (*Future) Update added in v0.73.0

func (f *Future) Update(ctx context.Context, pp interface{}, oe OracleEngine) error

func (*Future) UpdateAuctionState added in v0.74.0

func (f *Future) UpdateAuctionState(_ context.Context, _ bool)

func (*Future) Value

func (f *Future) Value(markPrice *num.Uint) (*num.Uint, error)

Value - returns the nominal value of a unit given a current mark price.

type OracleEngine

type OracleEngine interface {
	ListensToSigners(dscommon.Data) bool
	Subscribe(context.Context, spec.Spec, spec.OnMatchedData) (spec.SubscriptionID, spec.Unsubscriber, error)
	Unsubscribe(context.Context, spec.SubscriptionID)
}

OracleEngine ...

type Perpetual added in v0.73.0

type Perpetual struct {
	// contains filtered or unexported fields
}

Perpetual represents a Perpetual as describe by the market framework.

func NewPerpetual added in v0.73.0

func NewPerpetual(ctx context.Context, log *logging.Logger, p *types.Perps, marketID string, ts TimeService, oe OracleEngine, broker Broker, assetDP uint32) (*Perpetual, error)

func NewPerpetualFromSnapshot added in v0.73.0

func NewPerpetualFromSnapshot(
	ctx context.Context,
	log *logging.Logger,
	p *types.Perps,
	marketID string,
	ts TimeService,
	oe OracleEngine,
	broker Broker,
	state *snapshotpb.Perps,
	assetDP uint32,
) (*Perpetual, error)

func (*Perpetual) GetAsset added in v0.73.0

func (p *Perpetual) GetAsset() string

GetAsset return the asset used by the future.

func (Perpetual) GetCurrentPeriod added in v0.73.0

func (p Perpetual) GetCurrentPeriod() uint64

func (*Perpetual) GetData added in v0.73.0

func (p *Perpetual) GetData(t int64) *types.ProductData

func (*Perpetual) GetMarginIncrease added in v0.73.0

func (p *Perpetual) GetMarginIncrease(t int64) num.Decimal

GetMarginIncrease returns the estimated extra margin required to account for the next funding payment for a party with a position of +1.

func (*Perpetual) IsTradingTerminated added in v0.73.0

func (p *Perpetual) IsTradingTerminated() bool

IsTradingTerminated - returns true when the oracle has signalled terminated market.

func (*Perpetual) NotifyOnSettlementData added in v0.73.0

func (p *Perpetual) NotifyOnSettlementData(listener func(context.Context, *num.Numeric))

NotifyOnSettlementData for a perpetual this will be the funding payment being sent to the listener.

func (*Perpetual) NotifyOnTradingTerminated added in v0.73.0

func (p *Perpetual) NotifyOnTradingTerminated(listener func(context.Context, bool))

func (*Perpetual) RestoreSettlementData added in v0.73.0

func (p *Perpetual) RestoreSettlementData(settleData *num.Numeric)

func (*Perpetual) ScaleSettlementDataToDecimalPlaces added in v0.73.0

func (p *Perpetual) ScaleSettlementDataToDecimalPlaces(price *num.Numeric, dp uint32) (*num.Uint, error)

func (*Perpetual) Serialize added in v0.73.0

func (p *Perpetual) Serialize() *snapshotpb.Product

func (*Perpetual) Settle added in v0.73.0

func (p *Perpetual) Settle(entryPriceInAsset, settlementData *num.Uint, netFractionalPosition num.Decimal) (amt *types.FinancialAmount, neg bool, rounding num.Decimal, err error)

Settle a position against the perpetual.

func (*Perpetual) SubmitDataPoint added in v0.73.0

func (p *Perpetual) SubmitDataPoint(ctx context.Context, price *num.Uint, t int64) error

SubmitDataPoint this will add a data point produced internally by the core node.

func (*Perpetual) UnsubscribeSettlementData added in v0.73.0

func (p *Perpetual) UnsubscribeSettlementData(ctx context.Context)

func (*Perpetual) UnsubscribeTradingTerminated added in v0.73.0

func (p *Perpetual) UnsubscribeTradingTerminated(ctx context.Context)

func (*Perpetual) Update added in v0.73.0

func (p *Perpetual) Update(ctx context.Context, pp interface{}, oe OracleEngine) error

func (*Perpetual) UpdateAuctionState added in v0.74.0

func (p *Perpetual) UpdateAuctionState(ctx context.Context, enter bool)

func (*Perpetual) Value added in v0.73.0

func (p *Perpetual) Value(markPrice *num.Uint) (*num.Uint, error)

Value - returns the nominal value of a unit given a current mark price.

type Product

type Product interface {
	Settle(*num.Uint, *num.Uint, num.Decimal) (amt *types.FinancialAmount, neg bool, rounding num.Decimal, err error)
	Value(markPrice *num.Uint) (*num.Uint, error)
	GetAsset() string
	IsTradingTerminated() bool
	ScaleSettlementDataToDecimalPlaces(price *num.Numeric, dp uint32) (*num.Uint, error)
	NotifyOnTradingTerminated(listener func(context.Context, bool))
	NotifyOnSettlementData(listener func(context.Context, *num.Numeric))
	Update(ctx context.Context, pp interface{}, oe OracleEngine) error
	UnsubscribeTradingTerminated(ctx context.Context)
	UnsubscribeSettlementData(ctx context.Context)
	RestoreSettlementData(*num.Numeric)
	UpdateAuctionState(context.Context, bool)

	// tell the product about an internal data-point such as a the current mark-price
	SubmitDataPoint(context.Context, *num.Uint, int64) error

	// snapshot specific
	Serialize() *snapshotpb.Product
	GetMarginIncrease(int64) num.Decimal
	GetData(t int64) *types.ProductData
	GetCurrentPeriod() uint64
}

Product is the interface provided by all product in vega.

func New

func New(ctx context.Context, log *logging.Logger, pp interface{}, marketID string, ts TimeService, oe OracleEngine, broker Broker, assetDP uint32) (Product, error)

New instance a new product from a Market framework product configuration.

func NewFromSnapshot added in v0.73.0

func NewFromSnapshot(
	ctx context.Context,
	log *logging.Logger,
	pp interface{},
	marketID string,
	ts TimeService,
	oe OracleEngine,
	broker Broker,
	state *snapshotpb.Product,
	assetDP uint32,
) (Product, error)

New instance a new product from a Market framework product configuration.

type TimeService added in v0.74.2

type TimeService interface {
	GetTimeNow() time.Time
}

TimeService ...

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL