Documentation ¶
Index ¶
- func CalcVWAP(vwap *num.Uint, pos int64, addVolume int64, addPrice *num.Uint) *num.Uint
- 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) GetPartiesLowestOpenInterestForEpoch() map[string]uint64
- func (e *Engine) GetPartiesTradedVolumeForEpoch() (out map[string]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) MarkDistressed(closed []string) ([]string, []string)
- 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) ValidateAmendOrder(order *types.Order, newOrder *types.Order) error
- func (e *Engine) ValidateOrder(order *types.Order) error
- type MarketPosition
- func (p *MarketPosition) AmendOrder(log *logging.Logger, originalOrder, newOrder *types.Order)
- func (p MarketPosition) AverageEntryPrice() *num.Uint
- func (p MarketPosition) Buy() int64
- func (p MarketPosition) BuySumProduct() *num.Uint
- func (p MarketPosition) Clone() *MarketPosition
- func (p *MarketPosition) Closed() bool
- func (p MarketPosition) OrderReducesExposure(ord *types.Order) bool
- func (p MarketPosition) OrderReducesOnlyExposure(ord *types.Order) (reduce bool, extraSize uint64)
- func (p MarketPosition) Party() string
- func (p MarketPosition) Price() *num.Uint
- func (p *MarketPosition) RegisterOrder(log *logging.Logger, order *types.Order)
- func (p MarketPosition) Sell() int64
- func (p MarketPosition) SellSumProduct() *num.Uint
- 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) UpdateInPlaceOnTrades(log *logging.Logger, traderSide types.Side, trades []*types.Trade, ...) *MarketPosition
- func (p *MarketPosition) UpdateOnOrderChange(log *logging.Logger, side types.Side, price *num.Uint, sizeChange uint64, ...)
- func (p MarketPosition) VWBuy() *num.Uint
- func (p MarketPosition) VWSell() *num.Uint
- func (p MarketPosition) ValidateOrderRegistration(s uint64, side types.Side) error
- 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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) GetPartiesLowestOpenInterestForEpoch ¶ added in v0.73.0
GetPartiesLowestOpenInterestForEpoch will return a map of parties and minimal open interest for the epoch, it is meant to be called at the end of the epoch, and will reset the lowest open interest of the party to the latest open interest recored for the epoch.
func (*Engine) GetPartiesTradedVolumeForEpoch ¶ added in v0.73.0
GetPartiesTradedVolumeForEpoch will return a map of parties and their traded volume recorded during this epoch.
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) MarkDistressed ¶ added in v0.71.0
MarkDistressed - mark any distressed parties as such, returns the IDs of the parties who weren't distressed before.
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 ¶
func (e *Engine) Update(ctx context.Context, trade *types.Trade, passiveOrder, aggressiveOrder *types.Order) []events.MarketPosition
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) ValidateAmendOrder ¶ added in v0.73.7
ValidateAmendOrder checks that replace the given order with a new order will no cause issues with position tracking.
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) AverageEntryPrice ¶ added in v0.74.0
func (p MarketPosition) AverageEntryPrice() *num.Uint
AverageEntryPrice returns the volume weighted average price.
func (MarketPosition) Buy ¶
func (p MarketPosition) Buy() int64
Buy will returns the potential buys for a given position.
func (MarketPosition) BuySumProduct ¶ added in v0.70.0
func (p MarketPosition) BuySumProduct() *num.Uint
BuySumProduct - get sum of size * price of party's buy orders.
func (MarketPosition) Clone ¶
func (p MarketPosition) Clone() *MarketPosition
func (*MarketPosition) Closed ¶ added in v0.63.0
func (p *MarketPosition) Closed() bool
func (MarketPosition) OrderReducesExposure ¶ added in v0.69.0
func (p MarketPosition) OrderReducesExposure(ord *types.Order) bool
func (MarketPosition) OrderReducesOnlyExposure ¶ added in v0.70.0
func (p MarketPosition) OrderReducesOnlyExposure(ord *types.Order) (reduce bool, extraSize uint64)
OrderReducesOnlyExposure returns true if the order reduce the position and the extra size if it was to flip the position side.
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(log *logging.Logger, order *types.Order)
func (MarketPosition) Sell ¶
func (p MarketPosition) Sell() int64
Sell returns the potential sells for the position.
func (MarketPosition) SellSumProduct ¶ added in v0.70.0
func (p MarketPosition) SellSumProduct() *num.Uint
SellSumProduct - get sum of size * price of party's sell orders.
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) UpdateInPlaceOnTrades ¶ added in v0.74.0
func (p *MarketPosition) UpdateInPlaceOnTrades(log *logging.Logger, traderSide types.Side, trades []*types.Trade, order *types.Order) *MarketPosition
UpdateInPlaceOnTrades takes a clone of the receiver position, and updates it with the position from the given trades.
func (*MarketPosition) UpdateOnOrderChange ¶ added in v0.70.0
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.
func (MarketPosition) ValidateOrderRegistration ¶ added in v0.73.7
func (p MarketPosition) ValidateOrderRegistration(s uint64, side types.Side) error
ValidateOrder returns an error is the order is so large that the position engine does not have the precision to register it.
type SnapshotEngine ¶
type SnapshotEngine struct { *Engine // contains filtered or unexported fields }
func NewSnapshotEngine ¶
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) 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