Documentation ¶
Index ¶
- Variables
- func NewSliceRing[T any](size uint64) *sliceRing[T]
- type AuctionState
- type Broker
- type Config
- type Engine
- func (e *Engine) AmendLiquidityProvision(ctx context.Context, lpa *types.LiquidityProvisionAmendment, party string, ...) (bool, error)
- func (e *Engine) ApplyPendingProvisions(ctx context.Context, now time.Time) Provisions
- func (e *Engine) CalculateSLAPenalties(now time.Time) SlaPenalties
- func (e *Engine) CalculateSuppliedStake() *num.Uint
- func (e *Engine) CalculateSuppliedStakeWithoutPending() *num.Uint
- func (e *Engine) CanAmend(lps *types.LiquidityProvisionAmendment, party string, shouldValidate bool) error
- func (e *Engine) CancelLiquidityProvision(ctx context.Context, party string) error
- func (e *Engine) EndBlock(markPrice *num.Uint, midPrice *num.Uint, positionFactor num.Decimal)
- func (e *Engine) GetAverageLiquidityScores() map[string]num.Decimal
- func (e *Engine) GetCurrentLiquidityScores(bestBid, bestAsk num.Decimal, minLpPrice, maxLpPrice *num.Uint) (map[string]num.Decimal, num.Decimal)
- func (e *Engine) GetLastFeeDistributionTime() time.Time
- func (e *Engine) GetLegacyOrders() (orders []string)
- func (e *Engine) IsLiquidityProvider(party string) bool
- func (e *Engine) IsProbabilityOfTradingInitialised() bool
- func (e *Engine) LiquidityProviderSLAStats(now time.Time) []*types.LiquidityProviderSLA
- func (e *Engine) LiquidityProvisionByPartyID(partyID string) *types.LiquidityProvision
- func (e *Engine) OnMaximumLiquidityFeeFactorLevelUpdate(f num.Decimal)
- func (e *Engine) OnMinProbabilityOfTradingLPOrdersUpdate(v num.Decimal)
- func (e *Engine) OnNonPerformanceBondPenaltyMaxUpdate(nonPerformanceBondPenaltyMax num.Decimal)
- func (e *Engine) OnNonPerformanceBondPenaltySlopeUpdate(nonPerformanceBondPenaltySlope num.Decimal)
- func (e *Engine) OnProbabilityOfTradingTauScalingUpdate(v num.Decimal)
- func (e *Engine) OnProvidersFeeCalculationTimeStep(d time.Duration)
- func (e *Engine) OnStakeToCcyVolumeUpdate(stakeToCcyVolume num.Decimal)
- func (e *Engine) PaidLiquidityFeesStats() *types.PaidLiquidityFeesStats
- func (e *Engine) PendingProvision() Provisions
- func (e *Engine) PendingProvisionByPartyID(party string) *types.LiquidityProvision
- func (e *Engine) ProvisionsPerParty() ProvisionsPerParty
- func (e *Engine) ReadyForFeesAllocation(now time.Time) bool
- func (e *Engine) RegisterAllocatedFeesPerParty(feesPerParty map[string]*num.Uint)
- func (e *Engine) RejectLiquidityProvision(ctx context.Context, party string) error
- func (e *Engine) ResetAverageLiquidityScores()
- func (e *Engine) ResetFeeAllocationPeriod(t time.Time)
- func (e *Engine) ResetSLAEpoch(now time.Time, markPrice *num.Uint, midPrice *num.Uint, ...)
- func (e *Engine) SetGetStaticPricesFunc(f func() (num.Decimal, num.Decimal, error))
- func (e *Engine) StopLiquidityProvision(ctx context.Context, party string) error
- func (e *Engine) SubmitLiquidityProvision(ctx context.Context, lps *types.LiquidityProvisionSubmission, party string, ...) (bool, error)
- func (e *Engine) UpdateAverageLiquidityScores(bestBid, bestAsk num.Decimal, minLpPrice, maxLpPrice *num.Uint)
- func (e *Engine) UpdateMarketConfig(model RiskModel, monitor PriceMonitor)
- func (e *Engine) UpdatePartyCommitment(partyID string, newCommitment *num.Uint) (*types.LiquidityProvision, error)
- func (e *Engine) UpdateSLAParameters(slaParams *types.LiquiditySLAParams)
- func (e *Engine) ValidateLiquidityProvisionAmendment(lp *types.LiquidityProvisionAmendment) error
- func (e *Engine) ValidateLiquidityProvisionSubmission(lp *types.LiquidityProvisionSubmission, zeroCommitmentIsValid bool) (err error)
- type IDGen
- type OrderBook
- type Orders
- type PartyOrders
- type PriceMonitor
- type Provisions
- type ProvisionsPerParty
- type RiskModel
- type SlaPenalties
- type SlaPenalty
- type SnapshotEngine
- type SnapshotablePendingProvisions
- func (s *SnapshotablePendingProvisions) Delete(key string)
- func (s *SnapshotablePendingProvisions) Get(key string) (*types.LiquidityProvision, bool)
- func (s *SnapshotablePendingProvisions) Len() int
- func (s *SnapshotablePendingProvisions) Set(lp *types.LiquidityProvision)
- func (s SnapshotablePendingProvisions) Slice() Provisions
- type SnapshotableProvisionsPerParty
- type StateVarEngine
- type TimeService
Constants ¶
This section is empty.
Variables ¶
var ( ErrLiquidityProvisionDoesNotExist = errors.New("liquidity provision does not exist") ErrLiquidityProvisionAlreadyExists = errors.New("liquidity provision already exists") ErrCommitmentAmountIsZero = errors.New("commitment amount is zero") )
var DefaultSLAParameters = types.LiquiditySLAParams{ PriceRange: num.MustDecimalFromString("0.05"), CommitmentMinTimeFraction: num.MustDecimalFromString("0.95"), PerformanceHysteresisEpochs: 1, SlaCompetitionFactor: num.MustDecimalFromString("0.90"), }
var ErrPartyHaveNoLiquidityProvision = errors.New("party have no liquidity provision")
Functions ¶
func NewSliceRing ¶
Types ¶
type AuctionState ¶
type Config ¶
type Config struct {
Level cfgencoding.LogLevel `long:"log-level"`
}
Config represents the configuration of the Liquidity service.
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig creates an instance of the package specific configuration, given a pointer to a logger instance to be used for logging within the package.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine handles Liquidity provision.
func NewEngine ¶
func NewEngine(config Config, log *logging.Logger, timeService TimeService, broker Broker, riskModel RiskModel, priceMonitor PriceMonitor, orderBook OrderBook, auctionState AuctionState, asset string, marketID string, stateVarEngine StateVarEngine, positionFactor num.Decimal, slaParams *types.LiquiditySLAParams, ) *Engine
NewEngine returns a new Liquidity Engine.
func (*Engine) AmendLiquidityProvision ¶
func (*Engine) ApplyPendingProvisions ¶
func (*Engine) CalculateSLAPenalties ¶
func (e *Engine) CalculateSLAPenalties(now time.Time) SlaPenalties
CalculateSLAPenalties should be called at the and of epoch to calculate SLA penalties based on LP performance in the epoch.
func (*Engine) CalculateSuppliedStake ¶
CalculateSuppliedStake returns the sum of commitment amounts from all the liquidity providers. Includes pending commitment if they are greater then the original one.
func (*Engine) CalculateSuppliedStakeWithoutPending ¶
CalculateSuppliedStakeWithoutPending returns the sum of commitment amounts from all the liquidity providers. Does not include pending commitments.
func (*Engine) CancelLiquidityProvision ¶
CancelLiquidityProvision removes a parties commitment of liquidity Returns the liquidityOrders if any.
func (*Engine) GetAverageLiquidityScores ¶
func (*Engine) GetCurrentLiquidityScores ¶
func (e *Engine) GetCurrentLiquidityScores(bestBid, bestAsk num.Decimal, minLpPrice, maxLpPrice *num.Uint) (map[string]num.Decimal, num.Decimal)
GetCurrentLiquidityScores returns volume-weighted probability of trading per each LP's deployed orders.
func (*Engine) GetLastFeeDistributionTime ¶ added in v0.73.0
func (*Engine) GetLegacyOrders ¶ added in v0.73.0
func (*Engine) IsLiquidityProvider ¶
IsLiquidityProvider returns true if the party hold any liquidity commitment.
func (*Engine) IsProbabilityOfTradingInitialised ¶ added in v0.73.0
func (*Engine) LiquidityProviderSLAStats ¶ added in v0.73.0
func (e *Engine) LiquidityProviderSLAStats(now time.Time) []*types.LiquidityProviderSLA
func (*Engine) LiquidityProvisionByPartyID ¶
func (e *Engine) LiquidityProvisionByPartyID(partyID string) *types.LiquidityProvision
LiquidityProvisionByPartyID returns the LP associated to a Party if any. If not, it returns nil.
func (*Engine) OnMaximumLiquidityFeeFactorLevelUpdate ¶
func (*Engine) OnMinProbabilityOfTradingLPOrdersUpdate ¶
func (*Engine) OnNonPerformanceBondPenaltyMaxUpdate ¶
func (*Engine) OnNonPerformanceBondPenaltySlopeUpdate ¶
func (*Engine) OnProbabilityOfTradingTauScalingUpdate ¶
func (*Engine) OnProvidersFeeCalculationTimeStep ¶ added in v0.73.0
func (*Engine) OnStakeToCcyVolumeUpdate ¶
func (*Engine) PaidLiquidityFeesStats ¶ added in v0.73.0
func (e *Engine) PaidLiquidityFeesStats() *types.PaidLiquidityFeesStats
func (*Engine) PendingProvision ¶
func (e *Engine) PendingProvision() Provisions
func (*Engine) PendingProvisionByPartyID ¶
func (e *Engine) PendingProvisionByPartyID(party string) *types.LiquidityProvision
func (*Engine) ProvisionsPerParty ¶
func (e *Engine) ProvisionsPerParty() ProvisionsPerParty
ProvisionsPerParty returns the registered a map of party-id -> LiquidityProvision.
func (*Engine) ReadyForFeesAllocation ¶ added in v0.73.0
func (*Engine) RegisterAllocatedFeesPerParty ¶ added in v0.73.0
func (*Engine) RejectLiquidityProvision ¶
RejectLiquidityProvision removes a parties commitment of liquidity.
func (*Engine) ResetAverageLiquidityScores ¶
func (e *Engine) ResetAverageLiquidityScores()
func (*Engine) ResetFeeAllocationPeriod ¶ added in v0.73.0
func (*Engine) ResetSLAEpoch ¶
func (e *Engine) ResetSLAEpoch( now time.Time, markPrice *num.Uint, midPrice *num.Uint, positionFactor num.Decimal, )
ResetSLAEpoch should be called at the beginning of epoch to reset per epoch performance calculations. Returns a newly added/amended liquidity provisions (pending provisions are automatically applied and the start of a new epoch).
func (*Engine) SetGetStaticPricesFunc ¶
func (*Engine) StopLiquidityProvision ¶
StopLiquidityProvision removes a parties commitment of liquidity Returns the liquidityOrders if any.
func (*Engine) SubmitLiquidityProvision ¶
func (e *Engine) SubmitLiquidityProvision( ctx context.Context, lps *types.LiquidityProvisionSubmission, party string, idgen IDGen, ) (bool, error)
SubmitLiquidityProvision handles a new liquidity provision submission. Returns whether or not submission has been applied immediately.
func (*Engine) UpdateAverageLiquidityScores ¶
func (*Engine) UpdateMarketConfig ¶
func (e *Engine) UpdateMarketConfig(model RiskModel, monitor PriceMonitor)
func (*Engine) UpdatePartyCommitment ¶
func (e *Engine) UpdatePartyCommitment(partyID string, newCommitment *num.Uint) (*types.LiquidityProvision, error)
UpdatePartyCommitment allows to change party commitment. It should be used for synchronizing commitment with bond account.
func (*Engine) UpdateSLAParameters ¶ added in v0.73.0
func (e *Engine) UpdateSLAParameters(slaParams *types.LiquiditySLAParams)
func (*Engine) ValidateLiquidityProvisionAmendment ¶
func (e *Engine) ValidateLiquidityProvisionAmendment(lp *types.LiquidityProvisionAmendment) error
func (*Engine) ValidateLiquidityProvisionSubmission ¶
func (e *Engine) ValidateLiquidityProvisionSubmission( lp *types.LiquidityProvisionSubmission, zeroCommitmentIsValid bool, ) (err error)
type Orders ¶
Orders provides convenience functions to a slice of *veaga/proto.Orders.
func (Orders) ByParty ¶
func (ords Orders) ByParty() []PartyOrders
ByParty returns the orders grouped by it's PartyID.
type PartyOrders ¶
type PriceMonitor ¶
type PriceMonitor interface {
GetValidPriceRange() (num.WrappedDecimal, num.WrappedDecimal)
}
PriceMonitor provides the range of valid prices, that is prices that wouldn't trade the current trading mode.
type Provisions ¶
type Provisions []*types.LiquidityProvision
Provisions provides convenience functions to a slice of *vega/proto.LiquidityProvision.
func (Provisions) Get ¶ added in v0.73.0
func (pp Provisions) Get(key string) (*types.LiquidityProvision, int)
func (*Provisions) Set ¶ added in v0.73.0
func (pp *Provisions) Set(lp *types.LiquidityProvision)
type ProvisionsPerParty ¶
type ProvisionsPerParty map[string]*types.LiquidityProvision
ProvisionsPerParty maps parties to *types.LiquidityProvision.
func (ProvisionsPerParty) FeeForTarget ¶
func (l ProvisionsPerParty) FeeForTarget(v *num.Uint) num.Decimal
func (ProvisionsPerParty) Slice ¶
func (l ProvisionsPerParty) Slice() Provisions
Slice returns the parties as a slice.
func (ProvisionsPerParty) TotalStake ¶
func (l ProvisionsPerParty) TotalStake() *num.Uint
TotalStake returns the sum of all CommitmentAmount, which corresponds to the total stake of a market.
type RiskModel ¶
type RiskModel interface { ProbabilityOfTrading(currentPrice, orderPrice num.Decimal, minPrice, maxPrice num.Decimal, yFrac num.Decimal, isBid, applyMinMax bool) num.Decimal GetProjectionHorizon() num.Decimal }
RiskModel allows calculation of min/max price range and a probability of trading.
type SlaPenalties ¶
type SlaPenalties struct { AllPartiesHaveFullFeePenalty bool PenaltiesPerParty map[string]*SlaPenalty }
type SlaPenalty ¶
type SnapshotEngine ¶ added in v0.73.0
type SnapshotEngine struct { *Engine // contains filtered or unexported fields }
func NewSnapshotEngine ¶ added in v0.73.0
func NewSnapshotEngine( config Config, log *logging.Logger, timeService TimeService, broker Broker, riskModel RiskModel, priceMonitor PriceMonitor, orderBook OrderBook, auctionState AuctionState, asset string, marketID string, stateVarEngine StateVarEngine, positionFactor num.Decimal, slaParams *types.LiquiditySLAParams, ) *SnapshotEngine
func (SnapshotEngine) OnEpochRestore ¶ added in v0.73.0
func (e SnapshotEngine) OnEpochRestore(ep types.Epoch)
func (SnapshotEngine) StopSnapshots ¶ added in v0.73.0
func (e SnapshotEngine) StopSnapshots()
func (SnapshotEngine) V1StateProvider ¶ added in v0.73.0
func (e SnapshotEngine) V1StateProvider() types.StateProvider
func (SnapshotEngine) V2StateProvider ¶ added in v0.73.0
func (e SnapshotEngine) V2StateProvider() types.StateProvider
type SnapshotablePendingProvisions ¶ added in v0.73.0
type SnapshotablePendingProvisions struct {
PendingProvisions Provisions
}
func (*SnapshotablePendingProvisions) Delete ¶ added in v0.73.0
func (s *SnapshotablePendingProvisions) Delete(key string)
func (*SnapshotablePendingProvisions) Get ¶ added in v0.73.0
func (s *SnapshotablePendingProvisions) Get(key string) (*types.LiquidityProvision, bool)
func (*SnapshotablePendingProvisions) Len ¶ added in v0.73.0
func (s *SnapshotablePendingProvisions) Len() int
func (*SnapshotablePendingProvisions) Set ¶ added in v0.73.0
func (s *SnapshotablePendingProvisions) Set(lp *types.LiquidityProvision)
func (SnapshotablePendingProvisions) Slice ¶ added in v0.73.0
func (s SnapshotablePendingProvisions) Slice() Provisions
type SnapshotableProvisionsPerParty ¶
type SnapshotableProvisionsPerParty struct {
ProvisionsPerParty
}
func (*SnapshotableProvisionsPerParty) Delete ¶
func (s *SnapshotableProvisionsPerParty) Delete(key string)
func (*SnapshotableProvisionsPerParty) Get ¶
func (s *SnapshotableProvisionsPerParty) Get(key string) (*types.LiquidityProvision, bool)
func (*SnapshotableProvisionsPerParty) Set ¶
func (s *SnapshotableProvisionsPerParty) Set(key string, p *types.LiquidityProvision)
type StateVarEngine ¶
type TimeService ¶
TimeService provide the time of the vega node using the tm time.