Skip to main content

Order

IOrderBookDomain

Addresses

ChainAddress

Types

ActionType

The type of an Action

Values

NameDescription
INCREASE_SIZEcall DomFiPerp.increasePosition
DECREASE_SIZEcall DomFiPerp.decreasePositionWithId
ADD_MARGINcall DomFiPerp.increasePosition with 0 size
REMOVE_MARGINcall DomFiPerp.removeMargin
enum ActionType {
INCREASE_SIZE,
DECREASE_SIZE,
ADD_MARGIN,
REMOVE_MARGIN
}

TriggerType

The type of a Trigger

Values

NameDescription
INVALIDRevert if encountered. Guards against accidental 0x00
PRICECompare price of a product vs a specified price
PNL_RATECompare PnL of a position vs a specified %
enum TriggerType {
INVALID,
PRICE,
PNL_RATE
}

TriggerCondition

Whether a trigger should activate below or above a value

Values

NameDescription
LTEActivate if the current value is <= the target value
GTEActivate if the current value is >= the target value
enum TriggerCondition {
LTE,
GTE
}

TriggerDetails

Details for an order's execution criteria

Fields

NameTypeDescription
triggerTypeenum IOrderBookDomain.TriggerTypeThe type of comparison to make
triggerConditionenum IOrderBookDomain.TriggerConditionshould trigger >= or <= threshold?
triggerPnLRateFPSignedTarget PnL rate, a position's PnL divided by its margin, to be compared with conditions on chain.
triggerPriceFPUnsignedTarget price, to be compared with on-chain product price.
struct TriggerDetails {
enum IOrderBookDomain.TriggerType triggerType;
enum IOrderBookDomain.TriggerCondition triggerCondition;
FPSigned triggerPnLRate;
FPUnsigned triggerPrice;
}

OrderDetails

The action taken when an order is executed. Each OrderDetails instance must contain only the relevant fields for its trigger and action types.

Fields

NameTypeDescription
leverageFPUnsignedUnused (legacy)
marginuint256This slot is:
  • INCREASE_SIZE: margin to increase by. See size
  • DECREASE_SIZE: unused
  • ADD_MARGIN: margin to add
  • REMOVE_MARGIN: margin to remove. 0 if removeMarginFactor is present./
tradeFeeuint256For INCREASE_SIZE only; pre-collected trade fee.
sizeFPUnsignedFor INCREASE_SIZE and DECREASE_SIZE only; size to change by
removeMarginFactorFPUnsignedThis slot is:
  • INCREASE_SIZE: unused
  • DECREASE_SIZE: unused
  • ADD_MARGIN: unused
  • REMOVE_MARGIN: fraction of available margin to remove (0,1]. 0 if margin is present
struct OrderDetails {
FPUnsigned leverage;
uint256 margin;
uint256 tradeFee;
FPUnsigned size;
FPUnsigned removeMarginFactor;
}

Order

A user order on the exchange.

Fields

NameTypeDescription
executionFeeuint256Amount of network token reimbursed to order executor
submittedAtuint64Unix timestamp, in seconds, of last update.
canceledAtuint64Unix timestamp, in seconds, of cancelation. 0 if not yet canceled.
executedAtuint64Unix timestamp, in seconds, of execution. 0 if not yet executed.
executionDeadlineuint64
productIdProductId
actionTypeenum IOrderBookDomain.ActionTypeSee OrderBook.ActionType
actionstruct IOrderBookDomain.OrderDetailsAction that will be taken when the order executes.
triggerDetailsstruct IOrderBookDomain.TriggerDetails
isLongboolRequired for INCREASE_SIZE only, since we might be creating a new position
owneraddress payableThe creator and beneficiary of this order.
accountPositionIdPositionLabel
userDatabytesUser-specified data to attach to the order.
struct Order {
uint256 executionFee;
uint64 submittedAt;
uint64 canceledAt;
uint64 executedAt;
uint64 executionDeadline;
ProductId productId;
enum IOrderBookDomain.ActionType actionType;
struct IOrderBookDomain.OrderDetails action;
struct IOrderBookDomain.TriggerDetails triggerDetails;
bool isLong;
address payable owner;
PositionLabel accountPositionId;
bytes userData;
}

OrderParams

Parameters to create an order. The same thing as Order, except it does not include owner (set to msg.sender) or any of the timestamp fields (which users cannot modify directly).

struct OrderParams {
PositionLabel accountPositionId;
ProductId productId;
bool isLong;
enum IOrderBookDomain.ActionType actionType;
struct IOrderBookDomain.OrderDetails action;
struct IOrderBookDomain.TriggerDetails triggerDetails;
uint256 executionFee;
uint64 executionDeadline;
bytes userData;
}