liquidity

package
v0.72.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 13 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 ErrPartyHaveNoLiquidityProvision = errors.New("party have no liquidity provision")

Functions

func NewSliceRing

func NewSliceRing[T any](size uint) *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,
	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 (e *Engine) AmendLiquidityProvision(
	ctx context.Context,
	lpa *types.LiquidityProvisionAmendment,
	party string,
) error

func (*Engine) ApplyPendingProvisions

func (e *Engine) ApplyPendingProvisions(ctx context.Context, now time.Time) map[string]*types.LiquidityProvision

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

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

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) IsLiquidityProvider

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

IsLiquidityProvider returns true if the party hold any liquidity commitment.

func (*Engine) IsPoTInitialised

func (e *Engine) IsPoTInitialised() bool

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

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) OnPerformanceHysteresisEpochsUpdate

func (e *Engine) OnPerformanceHysteresisEpochsUpdate(performanceHysteresisEpochs uint)

func (*Engine) OnPriceRangeUpdate

func (e *Engine) OnPriceRangeUpdate(priceRange num.Decimal)

func (*Engine) OnProbabilityOfTradingTauScalingUpdate

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

func (*Engine) OnSlaCompetitionFactorUpdate

func (e *Engine) OnSlaCompetitionFactorUpdate(slaCompetitionFactor num.Decimal)

func (*Engine) OnStakeToCcyVolumeUpdate

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

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

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

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 TargetStateFunc

type TargetStateFunc func() *num.Uint

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