memclob

package
v0.0.0-...-cc24d94 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlwaysSuccessfulCollatCheckFn

func AlwaysSuccessfulCollatCheckFn(
	subaccountMatchedOrders map[satypes.SubaccountId][]clobtypes.PendingOpenOrder,
) (success bool, successPerUpdate map[satypes.SubaccountId]satypes.UpdateResult)

AlwaysSuccessfulCollatCheckFn is a collateralization check function that always returns success.

func CreateCollatCheckFunction

func CreateCollatCheckFunction(
	t *testing.T,
	collateralCheckCounter *int,
	expectedCollatCheckParams map[int]map[satypes.SubaccountId][]clobtypes.PendingOpenOrder,
	collatCheckFailures map[int]map[satypes.SubaccountId]satypes.UpdateResult,
) (
	collatCheckFn clobtypes.AddOrderToOrderbookCollateralizationCheckFn,
)

CreateCollatCheckFunction creates a collateralization check function that can be used when calling the `PlaceOrder` function on the memclob. It asserts that the passed in parameters to the collateralization check function are correct, and returns the specified collateralization check results. Note that this function takes a pointer parameter representing the number of collateralization checks, and increments it after each performed collateralization check such that the caller can assert the expected number of collateralization checks are performed.

func CreateSimpleCollatCheckFunction

func CreateSimpleCollatCheckFunction(
	t *testing.T,
	collateralCheckCounter *int,
	expectedCollatCheck map[int]CollateralizationCheck,
) (
	collatCheckFn clobtypes.AddOrderToOrderbookCollateralizationCheckFn,
)

CreateSimpleCollatCheckFunction creates a collateralization check function that can be used when calling the `PlaceOrder` function on the memclob. It asserts that the passed in parameters to the collateralization check function are correct, and returns the specified collateralization check results. Note that this function takes a pointer parameter representing the number of collateralization checks, and increments it after each performed collateralization check such that the caller can assert the expected number of collateralization checks are performed.

func HasMessage

func HasMessage(
	offchainUpdates *types.OffchainUpdates,
	orderId types.OrderId,
	messageType types.OffchainUpdateMessageType,
) bool

HasMessage checks if OffchainUpdates contains an message for the given OrderId & OffchainUpdateMessageType. Useful for when we want to verify an update message was added for a specific scenario.

func MessageCountOfType

func MessageCountOfType(
	offchainUpdates *types.OffchainUpdates,
	messageType types.OffchainUpdateMessageType,
) int

MessageCountOfType counts the number of messages in OffchainUpdates of a given type (Place/Remove/Update). Useful for when we want to verify we've added the correct number of messages.

func OrderSideHumanReadable

func OrderSideHumanReadable(isBuy bool) string

OrderSideHumanReadable is a testing observability function that translates the boolean side of an order to a human readable string. For example, passing in `true` represents a buy order, so this function will return `"BUY"`, whereas passing in `false` will return `"SELL"`.

func RequireCancelOrderMessage

func RequireCancelOrderMessage(t *testing.T, ctx sdk.Context, message *msgsender.Message, orderId types.OrderId)

func RequireCancelOrderOffchainUpdate

func RequireCancelOrderOffchainUpdate(
	t *testing.T,
	ctx sdk.Context,
	offchainUpdate *types.OffchainUpdates,
	orderId types.OrderId,
)

Types

type CollateralizationCheck

type CollateralizationCheck struct {
	CollatCheck map[satypes.SubaccountId][]clobtypes.PendingOpenOrder
	Result      map[satypes.SubaccountId]satypes.UpdateResult
}

CollateralizationCheck is a testing utility struct used to represent a collateralization check.

type FakeMemClobKeeper

type FakeMemClobKeeper struct {
	// contains filtered or unexported fields
}

TODO(DEC-1629): Remove FakeMemClobKeeper struct.

func NewFakeMemClobKeeper

func NewFakeMemClobKeeper() *FakeMemClobKeeper

func (*FakeMemClobKeeper) AddOrderToOrderbookCollatCheck

func (f *FakeMemClobKeeper) AddOrderToOrderbookCollatCheck(
	ctx sdk.Context,
	clobPairId types.ClobPairId,
	subaccountOpenOrders map[satypes.SubaccountId][]types.PendingOpenOrder,
) (
	success bool,
	successPerUpdate map[satypes.SubaccountId]satypes.UpdateResult,
)

func (*FakeMemClobKeeper) AddPreexistingStatefulOrder

func (f *FakeMemClobKeeper) AddPreexistingStatefulOrder(
	ctx sdk.Context,
	order *types.Order,
	memclob types.MemClob,
) (
	orderSizeOptimisticallyFilledFromMatchingQuantums satypes.BaseQuantums,
	orderStatus types.OrderStatus,
	offchainUpdates *types.OffchainUpdates,
	err error,
)

func (*FakeMemClobKeeper) CanDeleverageSubaccount

func (f *FakeMemClobKeeper) CanDeleverageSubaccount(
	ctx sdk.Context,
	msg satypes.SubaccountId,
	perpetualId uint32,
) (
	bool,
	bool,
	error,
)

func (*FakeMemClobKeeper) CancelShortTermOrder

func (f *FakeMemClobKeeper) CancelShortTermOrder(
	ctx sdk.Context,
	msgCancelOrder *types.MsgCancelOrder,
) error

func (*FakeMemClobKeeper) CommitState

func (f *FakeMemClobKeeper) CommitState()

Commit simulates `checkState.Commit()`.

func (*FakeMemClobKeeper) DoesLongTermOrderExistInState

func (f *FakeMemClobKeeper) DoesLongTermOrderExistInState(
	ctx sdk.Context,
	order types.Order,
) bool

func (*FakeMemClobKeeper) GetIndexerEventManager

func (f *FakeMemClobKeeper) GetIndexerEventManager() indexer_manager.IndexerEventManager

func (*FakeMemClobKeeper) GetLongTermOrderPlacement

func (f *FakeMemClobKeeper) GetLongTermOrderPlacement(
	ctx sdk.Context,
	orderId types.OrderId,
) (val types.LongTermOrderPlacement, found bool)

func (*FakeMemClobKeeper) GetOrderFillAmount

func (f *FakeMemClobKeeper) GetOrderFillAmount(
	ctx sdk.Context,
	orderId types.OrderId,
) (
	exists bool,
	fillAmount satypes.BaseQuantums,
	prunableBlockHeight uint32,
)

func (*FakeMemClobKeeper) GetStatePosition

func (f *FakeMemClobKeeper) GetStatePosition(
	ctx sdk.Context,
	subaccountId satypes.SubaccountId,
	clobPairId types.ClobPairId,
) (
	positionSizeQuantums *big.Int,
)

func (*FakeMemClobKeeper) GetStatefulOrdersTimeSlice

func (f *FakeMemClobKeeper) GetStatefulOrdersTimeSlice(
	ctx sdk.Context,
	goodTilBlockTime time.Time,
) (
	orderIds []types.OrderId,
)

func (*FakeMemClobKeeper) IsLiquidatable

func (f *FakeMemClobKeeper) IsLiquidatable(
	ctx sdk.Context,
	subaccountId satypes.SubaccountId,
) (
	isLiquidatable bool,
	err error,
)

func (*FakeMemClobKeeper) Logger

func (f *FakeMemClobKeeper) Logger(ctx sdk.Context) log.Logger

func (*FakeMemClobKeeper) MustAddOrderToStatefulOrdersTimeSlice

func (f *FakeMemClobKeeper) MustAddOrderToStatefulOrdersTimeSlice(
	ctx sdk.Context,
	goodTilBlockTime time.Time,
	orderId types.OrderId,
)

func (*FakeMemClobKeeper) OffsetSubaccountPerpetualPosition

func (f *FakeMemClobKeeper) OffsetSubaccountPerpetualPosition(
	ctx sdk.Context,
	liquidatedSubaccountId satypes.SubaccountId,
	perpetualId uint32,
	deltaQuantumsTotal *big.Int,
	isFinalSettlement bool,
) (
	fills []types.MatchPerpetualDeleveraging_Fill,
	deltaQuantumsRemaining *big.Int,
)

func (*FakeMemClobKeeper) PlaceShortTermOrder

func (f *FakeMemClobKeeper) PlaceShortTermOrder(
	ctx sdk.Context,
	msg *types.MsgPlaceOrder,
) (
	orderSizeOptimisticallyFilledFromMatchingQuantums satypes.BaseQuantums,
	orderStatus types.OrderStatus,
	err error,
)

func (*FakeMemClobKeeper) ProcessSingleMatch

func (f *FakeMemClobKeeper) ProcessSingleMatch(
	ctx sdk.Context,
	matchWithOrders *types.MatchWithOrders,
) (
	success bool,
	takerUpdateResult satypes.UpdateResult,
	makerUpdateResult satypes.UpdateResult,
	offchainUpdates *types.OffchainUpdates,
	err error,
)

func (*FakeMemClobKeeper) ReplayPlaceOrder

func (f *FakeMemClobKeeper) ReplayPlaceOrder(
	ctx sdk.Context,
	msg *types.MsgPlaceOrder,
) (
	orderSizeOptimisticallyFilledFromMatchingQuantums satypes.BaseQuantums,
	orderStatus types.OrderStatus,
	offchainUpdates *types.OffchainUpdates,
	err error,
)

func (*FakeMemClobKeeper) ResetState

func (f *FakeMemClobKeeper) ResetState()

Commit simulates the `checkState` being reset and uncommitted.

func (*FakeMemClobKeeper) SetLongTermOrderPlacement

func (f *FakeMemClobKeeper) SetLongTermOrderPlacement(
	ctx sdk.Context,
	order types.Order,
	blockHeight uint32,
)

func (*FakeMemClobKeeper) SetOrderFillAmount

func (f *FakeMemClobKeeper) SetOrderFillAmount(
	ctx sdk.Context,
	orderId types.OrderId,
	fillAmount satypes.BaseQuantums,
)

func (*FakeMemClobKeeper) ValidateSubaccountEquityTierLimitForNewOrder

func (f *FakeMemClobKeeper) ValidateSubaccountEquityTierLimitForNewOrder(ctx sdk.Context, order types.Order) error

func (*FakeMemClobKeeper) WithCollatCheckFn

func (*FakeMemClobKeeper) WithCollatCheckFnForProcessSingleMatch

func (f *FakeMemClobKeeper) WithCollatCheckFnForProcessSingleMatch() *FakeMemClobKeeper

func (*FakeMemClobKeeper) WithIndexerEventManager

func (f *FakeMemClobKeeper) WithIndexerEventManager(
	indexerEventManager indexer_manager.IndexerEventManager,
) *FakeMemClobKeeper

func (*FakeMemClobKeeper) WithStatePositionFn

func (f *FakeMemClobKeeper) WithStatePositionFn(fn types.GetStatePositionFn) *FakeMemClobKeeper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL