Documentation ¶
Index ¶
- Variables
- func I64MaxAbs(vals ...int64) int64
- type Broker
- type Config
- type Engine
- func (e *Engine) AmendOrder(ctx context.Context, originalOrder, newOrder *types.Order) *MarketPosition
- func (e *Engine) FlushPositionEvents(ctx context.Context)
- func (e *Engine) GetClosedPositions() []events.MarketPosition
- func (e *Engine) GetOpenInterest() uint64
- func (e *Engine) GetOpenInterestGivenTrades(trades []*types.Trade) uint64
- func (e *Engine) GetOpenPositionCount() uint64
- func (e *Engine) GetPositionByPartyID(partyID string) (*MarketPosition, bool)
- func (e *Engine) GetPositionsByParty(ids ...string) []events.MarketPosition
- func (e *Engine) Hash() []byte
- func (e *Engine) Parties() []string
- func (e *Engine) Positions() []events.MarketPosition
- func (e *Engine) RegisterOrder(ctx context.Context, order *types.Order) *MarketPosition
- func (e *Engine) ReloadConf(cfg Config)
- func (e *Engine) RemoveDistressed(parties []events.MarketPosition) []events.MarketPosition
- func (e *Engine) UnregisterOrder(ctx context.Context, order *types.Order) *MarketPosition
- func (e *Engine) Update(ctx context.Context, trade *types.Trade) []events.MarketPosition
- func (e *Engine) UpdateMarkPrice(markPrice *num.Uint) []events.MarketPosition
- func (e *Engine) UpdateNetwork(ctx context.Context, trade *types.Trade) []events.MarketPosition
- type MarketPosition
- func (p *MarketPosition) AmendOrder(log *logging.Logger, originalOrder, newOrder *types.Order)
- func (p MarketPosition) Buy() int64
- func (p MarketPosition) Clone() *MarketPosition
- func (p *MarketPosition) Closed() bool
- func (p MarketPosition) Party() string
- func (p MarketPosition) Price() *num.Uint
- func (p *MarketPosition) RegisterOrder(order *types.Order)
- func (p MarketPosition) Sell() int64
- func (p *MarketPosition) SetParty(party string)
- func (p MarketPosition) Size() int64
- func (p MarketPosition) String() string
- func (p *MarketPosition) UnregisterOrder(log *logging.Logger, order *types.Order)
- func (p MarketPosition) VWBuy() *num.Uint
- func (p MarketPosition) VWSell() *num.Uint
- type SnapshotEngine
- func (e *SnapshotEngine) AmendOrder(ctx context.Context, originalOrder, newOrder *types.Order) *MarketPosition
- 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) RegisterOrder(ctx context.Context, order *types.Order) *MarketPosition
- func (e *SnapshotEngine) RemoveDistressed(parties []events.MarketPosition) []events.MarketPosition
- func (e *SnapshotEngine) StopSnapshots()
- func (e *SnapshotEngine) Stopped() bool
- func (e *SnapshotEngine) UnregisterOrder(ctx context.Context, order *types.Order) *MarketPosition
- func (e *SnapshotEngine) Update(ctx context.Context, trade *types.Trade) []events.MarketPosition
- func (e *SnapshotEngine) UpdateMarkPrice(markPrice *num.Uint) []events.MarketPosition
- func (e *SnapshotEngine) UpdateNetwork(ctx context.Context, trade *types.Trade) []events.MarketPosition
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPositionNotFound signal that a position was not found for a given party. ErrPositionNotFound = errors.New("position not found") )
Errors.
Functions ¶
Types ¶
type Config ¶
type Config struct { Level encoding.LogLevel `long:"log-level"` StreamPositionVerbose encoding.Bool `long:"log-position-update"` }
Config represents the configuration of the position 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 represents the positions engine.
func (*Engine) AmendOrder ¶
func (e *Engine) AmendOrder(ctx context.Context, originalOrder, newOrder *types.Order) *MarketPosition
AmendOrder unregisters the original order and then registers the newly amended order this method is a quicker way of handling separate unregister+register pairs.
func (*Engine) FlushPositionEvents ¶ added in v0.68.0
func (*Engine) GetClosedPositions ¶ added in v0.63.0
func (e *Engine) GetClosedPositions() []events.MarketPosition
func (*Engine) GetOpenInterest ¶
func (*Engine) GetOpenInterestGivenTrades ¶
func (*Engine) GetOpenPositionCount ¶ added in v0.63.0
GetOpenPositionCount returns the number of open positions in the market.
func (*Engine) GetPositionByPartyID ¶
func (e *Engine) GetPositionByPartyID(partyID string) (*MarketPosition, bool)
GetPositionByPartyID - return current position for a given party, it's used in margin checks during auctions we're not specifying an interface of the return type, and we return a pointer to a copy for the nil.
func (*Engine) GetPositionsByParty ¶ added in v0.56.0
func (e *Engine) GetPositionsByParty(ids ...string) []events.MarketPosition
func (*Engine) Positions ¶
func (e *Engine) Positions() []events.MarketPosition
Positions is just the logic to update buyer, will eventually return the MarketPosition we need to push.
func (*Engine) RegisterOrder ¶
RegisterOrder updates the potential positions for a submitted order, as though the order were already accepted. It returns the updated position. The margins+risk engines need the updated position to determine whether the order should be accepted.
func (*Engine) ReloadConf ¶
ReloadConf update the internal configuration of the positions engine.
func (*Engine) RemoveDistressed ¶
func (e *Engine) RemoveDistressed(parties []events.MarketPosition) []events.MarketPosition
RemoveDistressed Removes positions for distressed parties, and returns the most up to date positions we have.
func (*Engine) UnregisterOrder ¶
UnregisterOrder undoes the actions of RegisterOrder. It is used when an order has been rejected by the Risk Engine, or when an order is amended or canceled.
func (*Engine) Update ¶
Update pushes the previous positions on the channel + the updated open volumes of buyer/seller.
func (*Engine) UpdateMarkPrice ¶
func (e *Engine) UpdateMarkPrice(markPrice *num.Uint) []events.MarketPosition
UpdateMarkPrice update the mark price on all positions and return a slice of the updated positions.
func (*Engine) UpdateNetwork ¶
UpdateNetwork - functionally the same as the Update func, except for ignoring the network party in the trade (whether it be buyer or seller). This could be incorporated into the Update function, but we know when we're adding network trades, and having this check every time is wasteful, and would only serve to add complexity to the Update func, and slow it down.
type MarketPosition ¶
type MarketPosition struct {
// contains filtered or unexported fields
}
MarketPosition represents the position of a party inside a market.
func NewMarketPosition ¶
func NewMarketPosition(party string) *MarketPosition
func (*MarketPosition) AmendOrder ¶
func (p *MarketPosition) AmendOrder(log *logging.Logger, originalOrder, newOrder *types.Order)
AmendOrder unregisters the original order and then registers the newly amended order this method is a quicker way of handling separate unregister+register pairs.
func (MarketPosition) Buy ¶
func (p MarketPosition) Buy() int64
Buy will returns the potential buys for a given position.
func (MarketPosition) Clone ¶
func (p MarketPosition) Clone() *MarketPosition
func (*MarketPosition) Closed ¶ added in v0.63.0
func (p *MarketPosition) Closed() bool
func (MarketPosition) Party ¶
func (p MarketPosition) Party() string
Party returns the party to which this positions is associated.
func (MarketPosition) Price ¶
func (p MarketPosition) Price() *num.Uint
Price returns the current price for this position.
func (*MarketPosition) RegisterOrder ¶
func (p *MarketPosition) RegisterOrder(order *types.Order)
func (MarketPosition) Sell ¶
func (p MarketPosition) Sell() int64
Sell returns the potential sells for the position.
func (*MarketPosition) SetParty ¶
func (p *MarketPosition) SetParty(party string)
func (MarketPosition) Size ¶
func (p MarketPosition) Size() int64
Size returns the current size of the position.
func (MarketPosition) String ¶
func (p MarketPosition) String() string
String returns a string representation of a market.
func (*MarketPosition) UnregisterOrder ¶
func (p *MarketPosition) UnregisterOrder(log *logging.Logger, order *types.Order)
func (MarketPosition) VWBuy ¶
func (p MarketPosition) VWBuy() *num.Uint
VWBuy - get volume weighted buy price for unmatched buy orders.
func (MarketPosition) VWSell ¶
func (p MarketPosition) VWSell() *num.Uint
VWSell - get volume weighted sell price for unmatched sell orders.
type SnapshotEngine ¶
type SnapshotEngine struct { *Engine // contains filtered or unexported fields }
func NewSnapshotEngine ¶
func (*SnapshotEngine) AmendOrder ¶
func (e *SnapshotEngine) AmendOrder(ctx context.Context, originalOrder, newOrder *types.Order) *MarketPosition
func (*SnapshotEngine) GetState ¶
func (e *SnapshotEngine) GetState(k string) ([]byte, []types.StateProvider, error)
func (*SnapshotEngine) Keys ¶
func (e *SnapshotEngine) Keys() []string
func (*SnapshotEngine) LoadState ¶
func (e *SnapshotEngine) LoadState(_ context.Context, payload *types.Payload) ([]types.StateProvider, error)
func (*SnapshotEngine) Namespace ¶
func (e *SnapshotEngine) Namespace() types.SnapshotNamespace
func (*SnapshotEngine) RegisterOrder ¶
func (e *SnapshotEngine) RegisterOrder(ctx context.Context, order *types.Order) *MarketPosition
func (*SnapshotEngine) RemoveDistressed ¶
func (e *SnapshotEngine) RemoveDistressed(parties []events.MarketPosition) []events.MarketPosition
func (*SnapshotEngine) StopSnapshots ¶
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 ¶
func (e *SnapshotEngine) Stopped() bool
func (*SnapshotEngine) UnregisterOrder ¶
func (e *SnapshotEngine) UnregisterOrder(ctx context.Context, order *types.Order) *MarketPosition
func (*SnapshotEngine) Update ¶
func (e *SnapshotEngine) Update(ctx context.Context, trade *types.Trade) []events.MarketPosition
func (*SnapshotEngine) UpdateMarkPrice ¶
func (e *SnapshotEngine) UpdateMarkPrice(markPrice *num.Uint) []events.MarketPosition
func (*SnapshotEngine) UpdateNetwork ¶
func (e *SnapshotEngine) UpdateNetwork(ctx context.Context, trade *types.Trade) []events.MarketPosition