Documentation ¶
Index ¶
- Variables
- func NewSliceRing[T any](size uint) *sliceRing[T]
- type AuctionState
- type Broker
- type Config
- type Engine
- func (e *Engine) AmendLiquidityProvision(ctx context.Context, lpa *types.LiquidityProvisionAmendment, party string) error
- func (e *Engine) ApplyPendingProvisions(ctx context.Context, now time.Time) map[string]*types.LiquidityProvision
- 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) 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) IsLiquidityProvider(party string) bool
- func (e *Engine) IsPoTInitialised() bool
- func (e *Engine) LiquidityProvisionByPartyID(partyID string) *types.LiquidityProvision
- func (e *Engine) OnCommitmentMinTimeFractionUpdate(commitmentMinTimeFraction num.Decimal)
- 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) OnPerformanceHysteresisEpochsUpdate(performanceHysteresisEpochs uint)
- func (e *Engine) OnPriceRangeUpdate(priceRange num.Decimal)
- func (e *Engine) OnProbabilityOfTradingTauScalingUpdate(v num.Decimal)
- func (e *Engine) OnSlaCompetitionFactorUpdate(slaCompetitionFactor num.Decimal)
- func (e *Engine) OnStakeToCcyVolumeUpdate(stakeToCcyVolume num.Decimal)
- func (e *Engine) PendingProvision() map[string]*types.LiquidityProvision
- func (e *Engine) PendingProvisionByPartyID(party string) *types.LiquidityProvision
- func (e *Engine) ProvisionsPerParty() ProvisionsPerParty
- func (e *Engine) RejectLiquidityProvision(ctx context.Context, party string) error
- func (e *Engine) ResetAverageLiquidityScores()
- func (e *Engine) ResetSLAEpoch(ctx context.Context, 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 risk.Model, monitor PriceMonitor)
- func (e *Engine) UpdatePartyCommitment(partyID string, newCommitment *num.Uint) (*types.LiquidityProvision, error)
- func (e *Engine) ValidateLiquidityProvisionAmendment(lp *types.LiquidityProvisionAmendment) (err error)
- func (e *Engine) ValidateLiquidityProvisionSubmission(lp *types.LiquidityProvisionSubmission, zeroCommitmentIsValid bool) (err error)
- type IDGen
- type OrderBook
- type Orders
- type PartyOrders
- type PendingProvision
- type PriceMonitor
- type Provisions
- type ProvisionsPerParty
- type RiskModel
- type SlaPenalties
- type SlaPenalty
- type SnapshotableProvisionsPerParty
- type StateVarEngine
- type TargetStateFunc
- 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 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, stakeToCcyVolume num.Decimal, priceRange num.Decimal, commitmentMinTimeFraction num.Decimal, slaCompetitionFactor num.Decimal, nonPerformanceBondPenaltySlope num.Decimal, nonPerformanceBondPenaltyMax num.Decimal, performanceHysteresisEpochs uint, getTargetStake TargetStateFunc, ) *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 ¶
CalculateSuppliedStake returns the sum of commitment amounts from all the liquidity providers. Dost not include pending commitments.
func (*Engine) CanAmend ¶
func (e *Engine) CanAmend( lps *types.LiquidityProvisionAmendment, party string, ) error
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) IsLiquidityProvider ¶
IsLiquidityProvider returns true if the party hold any liquidity commitment.
func (*Engine) IsPoTInitialised ¶
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) OnCommitmentMinTimeFractionUpdate ¶
func (*Engine) OnMaximumLiquidityFeeFactorLevelUpdate ¶
func (*Engine) OnMinProbabilityOfTradingLPOrdersUpdate ¶
func (*Engine) OnNonPerformanceBondPenaltyMaxUpdate ¶
func (*Engine) OnNonPerformanceBondPenaltySlopeUpdate ¶
func (*Engine) OnPerformanceHysteresisEpochsUpdate ¶
func (*Engine) OnPriceRangeUpdate ¶
func (*Engine) OnProbabilityOfTradingTauScalingUpdate ¶
func (*Engine) OnSlaCompetitionFactorUpdate ¶
func (*Engine) OnStakeToCcyVolumeUpdate ¶
func (*Engine) PendingProvision ¶
func (e *Engine) PendingProvision() map[string]*types.LiquidityProvision
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) RejectLiquidityProvision ¶
RejectLiquidityProvision removes a parties commitment of liquidity.
func (*Engine) ResetAverageLiquidityScores ¶
func (e *Engine) ResetAverageLiquidityScores()
func (*Engine) ResetSLAEpoch ¶
func (e *Engine) ResetSLAEpoch( ctx context.Context, 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 risk.Model, 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) ValidateLiquidityProvisionAmendment ¶
func (e *Engine) ValidateLiquidityProvisionAmendment(lp *types.LiquidityProvisionAmendment) (err 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 PendingProvision ¶
type PendingProvision map[string]*types.LiquidityProvision
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.
type ProvisionsPerParty ¶
type ProvisionsPerParty map[string]*types.LiquidityProvision
Provisions is a map of 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 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 TargetStateFunc ¶
type TimeService ¶
TimeService provide the time of the vega node using the tm time.