Function: postLimitOrder(byte[32] asset, address account, PostLimitOrderArgs args)
This function allows a user to create a new limit order to either buy (bid) or sell (ask). Unlike a market fill order, the limit order is placed into the order book and remains there until it is matched and filled, canceled by the owner, or expires or becomes unfillable.
Inputs
assetControl: Full control.
Constraints: Market should exist.
Impact: Determines which
assetmarket the new limit order applies to.
accountControl: Full control.
Constraints: The caller should be the account itself or an approved operator.
Impact: Position, margin, and balance updates are applied to this account. Collateral will be provided by the account.
args.amountInBaseControl: Full control.
Constraints: Must be greater than zero and more than
minLimitOrderAmountInBase.Impact: The order amount.
args.priceControl: Full control.
Constraints: Must be greater than zero —
price % tickSize == 0.Impact: Defines the worst price the user is willing to accept for the trade.
args.cancelTimestampControl: Full control.
Constraints: Should be zero or more than the
block.timestamp.Impact: The expire time of the order.
args.sideControl: Full control.
Constraints:
BUYandSELL.Impact: The buy (bid) or sell (ask) order.
args.limitOrderTypeControl: Full control.
Constraints:
GOOD_TILL_CANCELLEDandPOST_ONLY.Impact: If
POST_ONLYandBUY, the currentBestAskshould be more thanargs.price. IfPOST_ONLYandSELL, the currentBestBidshould be less thanargs.price.
args.subaccountControl: Full control.
Constraints: N/A.
Impact: Determines which subaccount to apply the trade to.
args.leverageControl: Full control.
Constraints: (1e18 * 1e18) / leverage should be less than
settings.initMarginReq.Impact: Controls how much borrowed funds are used — affects margin and liquidation risk.
args.reduceOnlyControl: Full control.
Constraints: Only for the existing position.
Impact: Order to reduce the current account position.
args.settlementControl: Full control.
Constraints: Must be a valid settlement type (
INSTANT,ACCOUNT). For settlementINSTANT, directly transfers from the account, or forACCOUNT, gets funds from the protocol balance of the account.Impact: Defines how the collateral funds will be provided.
Branches and code coverage
Intended branches
Successfully posts a valid
BUYlimit order.Successfully posts a valid
SELLlimit order.Reserves the correct collateral amount based on amount and leverage.
The order is correctly added to the order book.
For large
amountInBaseand low leverage, the collateral amount is correct.For large
amountInBaseand high leverage, the collateral amount is correct.A user posts many orders, and the order limit is enforced.
The order with extreme price.
Negative behavior
amountInBase == 0.price == 0.Reverts if
INSTANTand margin exceed user's available balance.Reverts if
ACCOUNTand margin exceed user's available tokens for transferring.