Skip to main content

Orders and Trades

Most traders will use our website to create familiar "trades", implemented by one or more orders acting on a position. For instance, a "limit order" is an order that triggers to create a new position if price enters a certain range. A "stop loss" is two orders: one to create a position, and one that will trigger to close it if the position's PnL drops below a certain percent. Right now, our UI exposes simple trades that are familiar to most users. The exchange can handle very complicated trades, which will be supported by a future Advanced Trading interface and upgraded order bots.

Basic Trades

Trades

Placing a limit order means you want to create a position as soon as the current dominance value rises above or below a certain value. A long limit order will trigger only while dominance is below the selected limit; a short limit order will trigger only while dominance is above the selected limit. For more information on limit orders, see Investopedia.

Unlike exchanges with true order books, limit orders will never execute at a price worse than the current market price. For instance, placing a long order with a limit of 40% while dominance is currently 30% will lead to the order immediately filling at 30%. On an order book exchange, the only guarantee of such orders is that the order will execute at the limit price or better. Such an order might be matched with a seller at 35%, leaving you worse off.

Orders

Domination Finance allows users to submit orders, which automatically execute in response to an execution trigger. Each order has an action that it will execute when triggered. Users may submit collateral with their order, to be used by the order's action. If an order is canceled or expires, that collateral is returned to the user.

Trigger Criteria

Each order has a single execution trigger that compares an on-chain metric (for instance, the value of Bitcoin Dominance) to a target value (for instance, 50%).

Available Trigger Types

Compare a product's price to a target value.

const priceTriggerOrder = {
productId: ethers.utils.formatBytes32String('ETHDOM'),
triggerDetails: {
triggerType: TriggerType.PRICE,
triggerCondition: TriggerCondition.GTE, // or .LTE
triggerPrice: E18.mul(25).div(100), // 25%
},
...
}

Actions

Each Order contains one action, which will interact with DomFiPerp on behalf of a user.

Action Types

When triggered, these actions spend collateral to create a new position or increase an existing one with the specified margin and leverage.

They incur a trade fee of 0.15% of the size (margin×leveragemargin \times leverage) increase.

const increaseOrderParams = {
actionType: ActionType.INCREASE_SIZE,
action: {
leverage: E18.mul(25).div(10), // 2.5x
margin: E6.mul(100), // $100
},
accountPositionId: existingPositionLabel,
...
}

When creating a new position, order.isLong and order.productId must also be specified.

Solidity Overview

Orders share some common fields: the account to which they belong, the position to affect, an execution deadline, and creation/cancelation/execution timestamps. Orders also include an arbitrary bytes userData, used for tagging orders but not processed on chain. Currently, this is used to differentiate market orders from limit orders in the UI.

struct Order {
address payable owner;

uint256 executionFee; // gas reimbursement to order executor

uint64 submittedAt;
uint64 canceledAt;
uint64 executedAt;
uint64 executionDeadline;

PositionLabel accountPositionId;
bytes32 productId; // omit unless PRICE trigger or creating a new position
bool isLong; // omit unless creating a new position

TriggerDetails triggerDetails;
ActionType actionType;
OrderDetails action;

bytes userData;
}

Each order has a TriggerDetails that specifies when it can execute.

struct TriggerDetails {
TriggerType triggerType;
TriggerCondition triggerCondition;
FPSigned triggerPnLRate;
FPUnsigned triggerPrice;
}

enum TriggerType {
INVALID,
PRICE,
PNL_RATE
}

enum TriggerCondition {
LTE,
GTE
}

Each order has an Action that specifies what it will do once executed:

enum ActionType {
INCREASE_SIZE,
DECREASE_SIZE,
ADD_MARGIN,
REMOVE_MARGIN
}

struct OrderDetails {
FPUnsigned leverage;
uint256 margin;
uint256 tradeFee; // calculated at order submission
FPUnsigned size;
FPUnsigned removeMarginFactor;
}

For more detailed information, see the OrderBookV1 API documentation.