price

package
v0.78.0-preview.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilRangeProvider signals that nil was supplied in place of RangeProvider.
	ErrNilRangeProvider = errors.New("nil RangeProvider")
	// ErrTimeSequence signals that time sequence is not in a non-decreasing order.
	ErrTimeSequence = errors.New("received a time that's before the last received time")
	// ErrExpiresAtNotSet indicates price monitoring auction is endless somehow.
	ErrExpiresAtNotSet = errors.New("price monitoring auction with no end time")
	// ErrNilPriceMonitoringSettings signals that nil was supplied in place of PriceMonitoringSettings.
	ErrNilPriceMonitoringSettings = errors.New("nil PriceMonitoringSettings")
)

Functions

This section is empty.

Types

type AuctionState

type AuctionState interface {
	// What is the current trading mode of the market, is it in auction
	Mode() types.MarketTradingMode
	InAuction() bool
	// What type of auction are we dealing with
	IsOpeningAuction() bool
	IsPriceAuction() bool
	IsPriceExtension() bool
	IsFBA() bool
	// is it the start/end of the auction
	CanLeave() bool
	AuctionStart() bool
	// start a price-related auction, extend a current auction, or end it
	StartPriceAuction(t time.Time, d *types.AuctionDuration)
	ExtendAuctionPrice(delta types.AuctionDuration)
	SetReadyToLeave()
	// get parameters for current auction
	Start() time.Time
	Duration() types.AuctionDuration // currently not used - might be useful when extending an auction
	ExpiresAt() *time.Time
}

type Engine

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

Engine allows tracking price changes and verifying them against the theoretical levels implied by the RangeProvider (risk model).

func NewMonitor

func NewMonitor(asset, mktID string, riskModel RangeProvider, auctionState AuctionState, settings *types.PriceMonitoringSettings, stateVarEngine StateVarEngine, log *logging.Logger) (*Engine, error)

NewMonitor returns a new instance of PriceMonitoring.

func NewMonitorFromSnapshot

func NewMonitorFromSnapshot(
	marketID string,
	asset string,
	pm *types.PriceMonitor,
	settings *types.PriceMonitoringSettings,
	riskModel RangeProvider,
	auctionState AuctionState,
	stateVarEngine StateVarEngine,
	log *logging.Logger,
) (*Engine, error)

func (*Engine) Changed

func (e *Engine) Changed() bool

func (*Engine) CheckPrice

func (e *Engine) CheckPrice(ctx context.Context, as AuctionState, price *num.Uint, persistent bool, recordPriceHistory bool) bool

CheckPrice checks how current price, volume and time should impact the auction state and modifies it accordingly: start auction, end auction, extend ongoing auction, "true" gets returned if non-persistent order should be rejected.

func (*Engine) GetBounds added in v0.77.0

func (e *Engine) GetBounds() []*types.PriceMonitoringBounds

GetBounds returns a list of valid price ranges per price monitoring trigger. Note these are subject to change as the time progresses.

func (*Engine) GetCurrentBounds

func (e *Engine) GetCurrentBounds() []*types.PriceMonitoringBounds

GetCurrentBounds returns a list of valid price ranges per price monitoring trigger. Note these are subject to change as the time progresses.

func (*Engine) GetHorizonYearFractions

func (e *Engine) GetHorizonYearFractions() []num.Decimal

GetHorizonYearFractions returns horizons of all the triggers specified, expressed as year fraction, sorted in ascending order.

func (*Engine) GetState

func (e *Engine) GetState() *types.PriceMonitor

func (*Engine) GetValidPriceRange

func (e *Engine) GetValidPriceRange() (num.WrappedDecimal, num.WrappedDecimal)

GetValidPriceRange returns the range of prices that won't trigger the price monitoring auction.

func (*Engine) Initialised

func (e *Engine) Initialised() bool

Initialised returns true if the engine already saw at least one price.

func (*Engine) IsBoundFactorsInitialised

func (e *Engine) IsBoundFactorsInitialised() bool

func (*Engine) OnTimeUpdate

func (e *Engine) OnTimeUpdate(now time.Time)

func (*Engine) ResetPriceHistory added in v0.76.0

func (e *Engine) ResetPriceHistory(price *num.Uint)

ResetPriceHistory deletes existing price history and starts it afresh with the supplied value.

func (*Engine) SetMinDuration

func (e *Engine) SetMinDuration(d time.Duration)

func (*Engine) UpdateSettings

func (e *Engine) UpdateSettings(riskModel risk.Model, settings *types.PriceMonitoringSettings, as AuctionState)

type RangeProvider

type RangeProvider interface {
	PriceRange(price, yearFraction, probability num.Decimal) (num.Decimal, num.Decimal)
}

RangeProvider provides the minimum and maximum future price corresponding to the current price level, horizon expressed as year fraction (e.g. 0.5 for 6 months) and probability level (e.g. 0.95 for 95%).

type StateVarEngine

type StateVarEngine interface {
	RegisterStateVariable(asset, market, name string, converter statevar.Converter, startCalculation func(string, statevar.FinaliseCalculation), trigger []statevar.EventType, result func(context.Context, statevar.StateVariableResult) error) error
}

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