target

package
v0.72.12 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 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")
	// ErrNegativeScalingFactor indicates that a negative scaling factor was supplied to the engine.
	ErrNegativeScalingFactor = errors.New("scaling factor can't be negative")
)

Functions

This section is empty.

Types

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 NewEngine

func NewEngine(parameters types.TargetStakeParameters, oiCalc OpenInterestCalculator, marketID string, positionFactor num.Decimal) *Engine

NewEngine returns a new instance of target stake calculation Engine.

func (*Engine) GetTargetStake

func (e *Engine) GetTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint) (*num.Uint, bool)

GetTargetStake returns target stake based current time, risk factors and the open interest time series constructed by calls to RecordOpenInterest.

func (*Engine) GetTheoreticalTargetStake

func (e *Engine) GetTheoreticalTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint, trades []*types.Trade) (*num.Uint, bool)

GetTheoreticalTargetStake returns target stake based current time, risk factors and the supplied trades without modifying the internal state.

func (*Engine) RecordOpenInterest

func (e *Engine) RecordOpenInterest(oi uint64, now time.Time) error

RecordOpenInterest records open interest history so that target stake can be calculated.

func (*Engine) UpdateParameters

func (e *Engine) UpdateParameters(parameters types.TargetStakeParameters)

func (*Engine) UpdateScalingFactor

func (e *Engine) UpdateScalingFactor(sFactor num.Decimal) error

UpdateScalingFactor updates the scaling factor used in target stake calculation if it's non-negative and returns an error otherwise.

func (*Engine) UpdateTimeWindow

func (e *Engine) UpdateTimeWindow(tWindow time.Duration)

UpdateTimeWindow updates the time windows used in target stake calculation.

type OpenInterestCalculator

type OpenInterestCalculator interface {
	GetOpenInterestGivenTrades(trades []*types.Trade) uint64
}

type SnapshotEngine

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

func NewSnapshotEngine

func NewSnapshotEngine(
	parameters types.TargetStakeParameters,
	oiCalc OpenInterestCalculator,
	marketID string,
	positionFactor num.Decimal,
) *SnapshotEngine

func (*SnapshotEngine) GetState

func (e *SnapshotEngine) GetState(k string) ([]byte, []types.StateProvider, error)

func (*SnapshotEngine) GetTargetStake

func (e *SnapshotEngine) GetTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint) *num.Uint

func (*SnapshotEngine) GetTheoreticalTargetStake

func (e *SnapshotEngine) GetTheoreticalTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint, trades []*types.Trade) *num.Uint

func (*SnapshotEngine) Keys

func (e *SnapshotEngine) Keys() []string

func (*SnapshotEngine) LoadState

func (e *SnapshotEngine) LoadState(_ context.Context, payload *types.Payload) ([]types.StateProvider, error)

func (*SnapshotEngine) Namespace

func (e *SnapshotEngine) Namespace() types.SnapshotNamespace

func (*SnapshotEngine) RecordOpenInterest

func (e *SnapshotEngine) RecordOpenInterest(oi uint64, now time.Time) error

func (*SnapshotEngine) StopSnapshots

func (e *SnapshotEngine) StopSnapshots()

func (*SnapshotEngine) Stopped

func (e *SnapshotEngine) Stopped() bool

func (*SnapshotEngine) UpdateParameters

func (e *SnapshotEngine) UpdateParameters(parameters types.TargetStakeParameters)

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