settlement

package
v0.74.0-preview.5 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPartyDoesNotMatch = errors.New("event party and position party do not match")

Functions

This section is empty.

Types

type Broker

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

Broker - the event bus broker, send events here.

type Config

type Config struct {
	Level encoding.LogLevel `long:"log-level"`
}

Config represent the configuration of the settlement engine.

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 {
	Config
	// contains filtered or unexported fields
}

Engine - the main type (of course).

func New

func New(log *logging.Logger, conf Config, product Product, market string, timeService TimeService, broker Broker, positionFactor num.Decimal) *Engine

New instantiates a new instance of the settlement engine.

func (*Engine) AddTrade

func (e *Engine) AddTrade(trade *types.Trade)

AddTrade - this call is required to get the correct MTM settlement values each change in position has to be calculated using the exact price of the trade.

func (*Engine) HasPosition added in v0.63.0

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

func (*Engine) HasTraded added in v0.63.0

func (e *Engine) HasTraded() bool

func (*Engine) ReloadConf

func (e *Engine) ReloadConf(cfg Config)

ReloadConf update the internal configuration of the settlement engined.

func (*Engine) RemoveDistressed

func (e *Engine) RemoveDistressed(ctx context.Context, evts []events.Margin)

RemoveDistressed - remove whatever settlement data we have for distressed parties they are being closed out, and shouldn't be part of any MTM settlement or closing settlement.

func (*Engine) Settle

func (e *Engine) Settle(t time.Time, settlementData *num.Uint) ([]*types.Transfer, *num.Uint, error)

Settle run settlement over all the positions.

func (*Engine) SettleFundingPeriod added in v0.73.0

func (e *Engine) SettleFundingPeriod(ctx context.Context, positions []events.MarketPosition, fundingPayment *num.Int) ([]events.Transfer, *num.Uint)

SettleFundingPeriod takes positions and a funding-payement and returns a slice of transfers. returns the slice of transfers to perform, and the max remainder on the settlement account due to rounding issues.

func (*Engine) SettleMTM

func (e *Engine) SettleMTM(ctx context.Context, markPrice *num.Uint, positions []events.MarketPosition) []events.Transfer

func (*Engine) Update

func (e *Engine) Update(positions []events.MarketPosition)

Update merely adds positions to the settlement engine, and won't be useful for a MTM settlement this function is mainly used for testing, and should be used with extreme caution as a result perhaps the tests should be refactored to use the Settle call to create positions first.

func (*Engine) UpdateProduct

func (e *Engine) UpdateProduct(product products.Product)

type MarketPosition

type MarketPosition interface {
	Party() string
	Size() int64
	Buy() int64
	Sell() int64
	Price() *num.Uint
	BuySumProduct() *num.Uint
	SellSumProduct() *num.Uint
	VWBuy() *num.Uint
	VWSell() *num.Uint
	ClearPotentials()
	AverageEntryPrice() *num.Uint
}

MarketPosition ...

type Product

type Product interface {
	Settle(*num.Uint, *num.Uint, num.Decimal) (*types.FinancialAmount, bool, num.Decimal, error)
	GetAsset() string
}

Product ...

type SnapshotEngine added in v0.63.0

type SnapshotEngine struct {
	*Engine
	// contains filtered or unexported fields
}

func NewSnapshotEngine added in v0.63.0

func NewSnapshotEngine(log *logging.Logger, conf Config, product Product, market string, timeService TimeService, broker Broker, positionFactor num.Decimal) *SnapshotEngine

func (*SnapshotEngine) GetState added in v0.63.0

func (e *SnapshotEngine) GetState(k string) ([]byte, []types.StateProvider, error)

func (*SnapshotEngine) Keys added in v0.63.0

func (e *SnapshotEngine) Keys() []string

func (*SnapshotEngine) LoadState added in v0.63.0

func (e *SnapshotEngine) LoadState(_ context.Context, payload *types.Payload) ([]types.StateProvider, error)

func (*SnapshotEngine) Namespace added in v0.63.0

func (e *SnapshotEngine) Namespace() types.SnapshotNamespace

func (*SnapshotEngine) StopSnapshots added in v0.63.0

func (e *SnapshotEngine) StopSnapshots()

StopSnapshots is called when the engines respective market no longer exists. We need to stop taking snapshots and communicate to the snapshot engine to remove us as a provider.

func (*SnapshotEngine) Stopped added in v0.63.0

func (e *SnapshotEngine) Stopped() bool

type TimeService

type TimeService interface {
	GetTimeNow() time.Time
}

TimeService.

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