Place a Margin Order
To place a margin order, use the regular Place an Order endpoint with the margin_order_type parameter set to CROSS_MARGIN.
When borrowing funds to cover the order amount, interest will be applied to the borrowed amount based on the rates defined in Get Margin Available Currencies.
Prerequisites
Before placing margin orders, ensure the following conditions are met:
1. Margin Account Funding
Your margin account must be funded with the required collateral. To deposit funds into your margin account, use the Process Margin Funds Movement endpoint with the DEPOSIT movement type.
2. Check Book Availability
Margin orders can only be placed on books that support margin trading. To verify if a book allows margin trading, use the List Available Books endpoint and check the margin_enabled field. Only books with margin_enabled: true support margin orders.
3. Currency Configurations
To view the interest rates charged on borrowed amounts and the discount factors applied to collateral for each currency, use the Get Margin Available Currencies endpoint. This information helps you understand the borrowing costs and collateral requirements for margin trading.
4. Margin Level Requirements
Your margin account must maintain a healthy margin level to place orders. Calculated margin level ratio of the account (total assets / total liabilities) is returned as margin_level.current by Get Margin Account Summary.
Key Thresholds:
- Safe Level: Orders can only be placed when your current margin level is above the safe threshold. This ensures you have sufficient collateral to cover potential risks.
- Maintenance Level: If your margin level falls below the maintenance threshold, your account will be liquidated to protect against further losses.
You can monitor your current margin level and check these thresholds using the Get Margin Account Summary endpoint. The response includes:
margin_level.current- Calculated margin level ratio of the account (total assets / total liabilities)margin_level.safe- The safe threshold (must be above this to place orders)margin_level.maintenance- The maintenance threshold (liquidation occurs if you fall below this)
Example: Complete Margin Trading Scenario
Initial Setup
You have $2,500 USD in your margin account and want to buy 0.1 BTC at $50,000 USD per BTC.
- Total Order Cost: $5,000 USD
- Your Balance: $2,500 USD
- Amount to Borrow: $2,500 USD
- Interest Rate (USD): 0.00008 per hour
Placing the Order
When you place the margin order, the system automatically borrows $2,500 USD to complete the purchase. You now hold:
- Assets: 0.1 BTC (valued at $5,000 USD)
- Liabilities: $2,500 USD borrowed
- Margin level (total assets / total liabilities): $5,000 / $2,500 = 2.0
Interest Accumulation
Interest is charged hourly on the borrowed amount:
- Hourly Interest: $2,500 × 0.00008 = $0.20 USD
- Daily Interest: $0.20 × 24 = $4.80 USD
Liquidation Risk
If the price of BTC drops, your margin level decreases:
Scenario 1 - Price drops to $40,000:
- Assets: 0.1 BTC (now valued at $4,000 USD)
- Liabilities: $2,500 USD (plus accrued interest)
- New margin level (total assets / total liabilities): $4,000 / $2,500 = 1.6
Scenario 2 - Price drops to $33,000:
- Assets: 0.1 BTC (now valued at $3,300 USD)
- Liabilities: $2,500 USD (plus accrued interest)
- New margin level (total assets / total liabilities): $3,300 / $2,500 = 1.32
If your margin level falls below the maintenance threshold (e.g., 1.1), your account enters liquidation:
- The system automatically sells your positions to repay borrowed funds
- Your account status changes to
LIQUIDATING - After liquidation completes, status returns to
INACTIVE
To avoid liquidation, ensure your margin level stays above the maintenance threshold (e.g., 1.1) by either:
- Depositing additional collateral
- Closing positions to reduce liabilities
- Monitoring price movements and market conditions
Error responses
When a margin check rejects an order, the request fails with HTTP status 400 and an error code that identifies the check that failed. The error also includes an errorData object with the values that broke the check, so you can tell how far the order was from being accepted.
| Error code | Reason (errorData.reason) | When it happens |
|---|---|---|
1710 | MARGIN_LEVEL_TOO_LOW | The order would leave your margin level below the required threshold. Reduce the order size or add collateral |
1711 | LENDING_POOL_SIZE_EXCEEDED | The amount the order needs to borrow does not fit in the currency's lending pool |
1712 | USER_BORROW_LIMIT_EXCEEDED | The order would take your total borrowing above the borrow limit set for your account |
1713 | BORROW_NOT_ALLOWED | The order would require borrowing, which is not allowed for this order (for example, an order that repays a loan can't open a new one) |
Error code 1709 (Unable to allocate margin for this order) is returned with HTTP status 500 when the margin service could not process the order. The order was not placed, and you can retry it.
The errorData object
errorData object| Field | Description | Type |
|---|---|---|
reason | The check that rejected the order. One of the reasons in the table above | String |
currency | The currency the check was evaluated in | String |
limit | The threshold or capacity the order was compared against. See the table below for what it means for each reason | String (decimal) |
projected | The value that broke the limit. See the table below for what it means for each reason | String (decimal) |
loan_debt_change | The debt the order would add. Only present when it is reported separately from projected | String (decimal) |
The meaning of limit and projected depends on the reason:
| Reason | limit | projected |
|---|---|---|
MARGIN_LEVEL_TOO_LOW | The initial margin level required to place the order | The margin level your account would have after the order |
LENDING_POOL_SIZE_EXCEEDED | The size of the lending pool | The pool utilization after the order |
USER_BORROW_LIMIT_EXCEEDED | Your borrow limit | Your total debt after the order |
BORROW_NOT_ALLOWED | 0, since no borrowing is allowed | The debt the order would add |
For example, an order that would take your debt above your borrow limit returns:
{
"success": false,
"error": {
"code": "1712",
"message": "Borrowing would exceed your borrow limit",
"errorData": {
"reason": "USER_BORROW_LIMIT_EXCEEDED",
"currency": "cop",
"limit": "469000000",
"projected": "512000000"
}
}
}
Don't parse the messageUse the error
codeanderrorData.reasonin your integration. Themessagetext is meant for people and may change.
For other order errors, see the error codes.
Related Endpoints
- Place an Order - API endpoint to place orders
- List Available Books - Check which books support margin trading
- Get Margin Available Currencies - View interest rates and collateral discount factors for margin currencies
- Process Margin Funds Movement - Deposit or withdraw funds from margin account
- Get Margin Account Summary - Check margin account status and balances
Updated 9 days ago
