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:

  1. The system automatically sells your positions to repay borrowed funds
  2. Your account status changes to LIQUIDATING
  3. 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 codeReason (errorData.reason)When it happens
1710MARGIN_LEVEL_TOO_LOWThe order would leave your margin level below the required threshold. Reduce the order size or add collateral
1711LENDING_POOL_SIZE_EXCEEDEDThe amount the order needs to borrow does not fit in the currency's lending pool
1712USER_BORROW_LIMIT_EXCEEDEDThe order would take your total borrowing above the borrow limit set for your account
1713BORROW_NOT_ALLOWEDThe 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

FieldDescriptionType
reasonThe check that rejected the order. One of the reasons in the table aboveString
currencyThe currency the check was evaluated inString
limitThe threshold or capacity the order was compared against. See the table below for what it means for each reasonString (decimal)
projectedThe value that broke the limit. See the table below for what it means for each reasonString (decimal)
loan_debt_changeThe debt the order would add. Only present when it is reported separately from projectedString (decimal)

The meaning of limit and projected depends on the reason:

Reasonlimitprojected
MARGIN_LEVEL_TOO_LOWThe initial margin level required to place the orderThe margin level your account would have after the order
LENDING_POOL_SIZE_EXCEEDEDThe size of the lending poolThe pool utilization after the order
USER_BORROW_LIMIT_EXCEEDEDYour borrow limitYour total debt after the order
BORROW_NOT_ALLOWED0, since no borrowing is allowedThe 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 message

Use the error code and errorData.reason in your integration. The message text is meant for people and may change.

For other order errors, see the error codes.

Related Endpoints


Did this page help you?