liquidity

package
v0.76.4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLiquidityProvisionDoesNotExist  = errors.New("liquidity provision does not exist")
	ErrLiquidityProvisionAlreadyExists = errors.New("liquidity provision already exists")
	ErrCommitmentAmountIsZero          = errors.New("commitment amount is zero")
)
View Source
var DefaultSLAParameters = types.LiquiditySLAParams{
	PriceRange:                  num.MustDecimalFromString("0.05"),
	CommitmentMinTimeFraction:   num.MustDecimalFromString("0.95"),
	PerformanceHysteresisEpochs: 1,
	SlaCompetitionFactor:        num.MustDecimalFromString("0.90"),
}
View Source
var ErrPartyHaveNoLiquidityProvision = errors.New("party have no liquidity provision")

Functions

func NewSliceRing

func NewSliceRing[T any](size uint64) *sliceRing[T]

Types

type AuctionState

type AuctionState interface {
	InAuction() bool
	IsOpeningAuction() bool
}

type Broker

type Broker interface {
	Send(e events.Event)
	SendBatch(evts []events.Event)
}

Broker - event bus (no mocks needed).

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 (e *Engine) AmendLiquidityProvision(
	ctx context.Context,
	lpa *types.LiquidityProvisionAmendment,
	party string,
	isCancel bool,
) (bool, error)

func (*Engine) ApplyPendingProvisions

func (e *Engine) ApplyPendingProvisions(ctx context.Context, now time.Time) Provisions

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

func (e *Engine) CalculateSuppliedStake() *num.Uint

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

func (e *Engine) CalculateSuppliedStakeWithoutPending() *num.Uint

CalculateSuppliedStakeWithoutPending returns the sum of commitment amounts from all the liquidity providers. Does not include pending commitments.

func (*Engine) CanAmend

func (e *Engine) CanAmend(lps *types.LiquidityProvisionAmendment, party string, shouldValidate bool) error

func (*Engine) CancelLiquidityProvision

func (e *Engine) CancelLiquidityProvision(ctx context.Context, party string) error

CancelLiquidityProvision removes a parties commitment of liquidity Returns the liquidityOrders if any.

func (*Engine) EndBlock

func (e *Engine) EndBlock(markPrice *num.Uint, midPrice *num.Uint, positionFactor num.Decimal)

func (*Engine) GetAverageLiquidityScores

func (e *Engine) GetAverageLiquidityScores() map[string]num.Decimal

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 (e *Engine) GetLastFeeDistributionTime() time.Time

func (*Engine) GetLegacyOrders added in v0.73.0

func (e *Engine) GetLegacyOrders() (orders []string)

func (*Engine) IsLiquidityProvider

func (e *Engine) IsLiquidityProvider(party string) bool

IsLiquidityProvider returns true if the party hold any liquidity commitment.

func (*Engine) IsProbabilityOfTradingInitialised added in v0.73.0

func (e *Engine) IsProbabilityOfTradingInitialised() bool

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 (e *Engine) OnMaximumLiquidityFeeFactorLevelUpdate(f num.Decimal)

func (*Engine) OnMinProbabilityOfTradingLPOrdersUpdate

func (e *Engine) OnMinProbabilityOfTradingLPOrdersUpdate(v num.Decimal)

func (*Engine) OnNonPerformanceBondPenaltyMaxUpdate

func (e *Engine) OnNonPerformanceBondPenaltyMaxUpdate(nonPerformanceBondPenaltyMax num.Decimal)

func (*Engine) OnNonPerformanceBondPenaltySlopeUpdate

func (e *Engine) OnNonPerformanceBondPenaltySlopeUpdate(nonPerformanceBondPenaltySlope num.Decimal)

func (*Engine) OnProbabilityOfTradingTauScalingUpdate

func (e *Engine) OnProbabilityOfTradingTauScalingUpdate(v num.Decimal)

func (*Engine) OnProvidersFeeCalculationTimeStep added in v0.73.0

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

func (*Engine) OnStakeToCcyVolumeUpdate

func (e *Engine) OnStakeToCcyVolumeUpdate(stakeToCcyVolume num.Decimal)

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 (e *Engine) ReadyForFeesAllocation(now time.Time) bool

func (*Engine) RegisterAllocatedFeesPerParty added in v0.73.0

func (e *Engine) RegisterAllocatedFeesPerParty(feesPerParty map[string]*num.Uint)

func (*Engine) RejectLiquidityProvision

func (e *Engine) RejectLiquidityProvision(ctx context.Context, party string) error

RejectLiquidityProvision removes a parties commitment of liquidity.

func (*Engine) ResetAverageLiquidityScores

func (e *Engine) ResetAverageLiquidityScores()

func (*Engine) ResetFeeAllocationPeriod added in v0.73.0

func (e *Engine) ResetFeeAllocationPeriod(t time.Time)

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 (e *Engine) SetGetStaticPricesFunc(f func() (num.Decimal, num.Decimal, error))

func (*Engine) StopLiquidityProvision

func (e *Engine) StopLiquidityProvision(ctx context.Context, party string) error

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 (e *Engine) UpdateAverageLiquidityScores(bestBid, bestAsk num.Decimal, minLpPrice, maxLpPrice *num.Uint)

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 IDGen

type IDGen interface {
	NextID() string
}

IDGen is an id generator for orders.

type OrderBook

type OrderBook interface {
	GetOrdersPerParty(party string) []*types.Order
	GetBestStaticBidPrice() (*num.Uint, error)
	GetBestStaticAskPrice() (*num.Uint, error)
	GetIndicativePrice() *num.Uint
	GetLastTradedPrice() *num.Uint
}

type Orders

type Orders []*types.Order

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 PartyOrders struct {
	Party  string
	Orders []*types.Order
}

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) FeeForWeightedAverage added in v0.74.0

func (l ProvisionsPerParty) FeeForWeightedAverage() 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 SlaPenalty struct {
	Fee, Bond num.Decimal
}

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 (*SnapshotablePendingProvisions) Len added in v0.73.0

func (*SnapshotablePendingProvisions) Set added in v0.73.0

func (SnapshotablePendingProvisions) Slice added in v0.73.0

type SnapshotableProvisionsPerParty

type SnapshotableProvisionsPerParty struct {
	ProvisionsPerParty
}

func (*SnapshotableProvisionsPerParty) Delete

func (s *SnapshotableProvisionsPerParty) Delete(key string)

func (*SnapshotableProvisionsPerParty) Get

func (*SnapshotableProvisionsPerParty) Set

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
}

type TimeService

type TimeService interface {
	GetTimeNow() time.Time
}

TimeService provide the time of the vega node using the tm time.

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