Documentation ¶
Index ¶
- Variables
- type Broker
- type Config
- type Engine
- func (e *Engine) AddTrade(trade *types.Trade)
- func (e *Engine) HasPosition(party string) bool
- func (e *Engine) HasTraded() bool
- func (e *Engine) ReloadConf(cfg Config)
- func (e *Engine) RemoveDistressed(ctx context.Context, evts []events.Margin)
- func (e *Engine) Settle(t time.Time, settlementData *num.Uint) ([]*types.Transfer, *num.Uint, error)
- func (e *Engine) SettleFundingPeriod(ctx context.Context, positions []events.MarketPosition, ...) ([]events.Transfer, *num.Uint)
- func (e *Engine) SettleMTM(ctx context.Context, markPrice *num.Uint, positions []events.MarketPosition) []events.Transfer
- func (e *Engine) Update(positions []events.MarketPosition)
- func (e *Engine) UpdateProduct(product products.Product)
- type MarketPosition
- type Product
- type SnapshotEngine
- func (e *SnapshotEngine) GetState(k string) ([]byte, []types.StateProvider, error)
- func (e *SnapshotEngine) Keys() []string
- func (e *SnapshotEngine) LoadState(_ context.Context, payload *types.Payload) ([]types.StateProvider, error)
- func (e *SnapshotEngine) Namespace() types.SnapshotNamespace
- func (e *SnapshotEngine) StopSnapshots()
- func (e *SnapshotEngine) Stopped() bool
- type TimeService
Constants ¶
This section is empty.
Variables ¶
var ErrPartyDoesNotMatch = errors.New("event party and position party do not match")
Functions ¶
This section is empty.
Types ¶
type Config ¶
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 ¶
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 (*Engine) ReloadConf ¶
ReloadConf update the internal configuration of the settlement engined.
func (*Engine) RemoveDistressed ¶
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) 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 ¶
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