Documentation ¶
Index ¶
- Variables
- type Engine
- func (e *Engine) GetTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint) (*num.Uint, bool)
- func (e *Engine) GetTheoreticalTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint, trades []*types.Trade) (*num.Uint, bool)
- func (e *Engine) RecordOpenInterest(oi uint64, now time.Time) error
- func (e *Engine) UpdateParameters(parameters types.TargetStakeParameters)
- func (e *Engine) UpdateScalingFactor(sFactor num.Decimal) error
- func (e *Engine) UpdateTimeWindow(tWindow time.Duration)
- type OpenInterestCalculator
- type SnapshotEngine
- func (e *SnapshotEngine) Changed() bool
- func (e *SnapshotEngine) GetState(k string) ([]byte, []types.StateProvider, error)
- func (e *SnapshotEngine) GetTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint) *num.Uint
- func (e *SnapshotEngine) GetTheoreticalTargetStake(rf types.RiskFactor, now time.Time, markPrice *num.Uint, trades []*types.Trade) *num.Uint
- func (e *SnapshotEngine) HasChanged(k string) bool
- func (e *SnapshotEngine) Keys() []string
- func (e *SnapshotEngine) LoadState(_ context.Context, payload *types.Payload) ([]types.StateProvider, error)
- func (e *SnapshotEngine) Namespace() types.SnapshotNamespace
- func (e *SnapshotEngine) RecordOpenInterest(oi uint64, now time.Time) error
- func (e *SnapshotEngine) StopSnapshots()
- func (e *SnapshotEngine) Stopped() bool
- func (e *SnapshotEngine) UpdateParameters(parameters types.TargetStakeParameters)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
UpdateScalingFactor updates the scaling factor used in target stake calculation if it's non-negative and returns an error otherwise.
func (*Engine) UpdateTimeWindow ¶
UpdateTimeWindow updates the time windows used in target stake calculation.
type OpenInterestCalculator ¶
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) Changed ¶
func (e *SnapshotEngine) Changed() bool
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 (*SnapshotEngine) HasChanged ¶
func (e *SnapshotEngine) HasChanged(k string) bool
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)