# Place Margin Order

Source: https://developers.bitgo.com/docs/trade-margin-margin-order

## Overview

Margin orders are similar to trade orders, except the assets for margin orders withdraw from your Margin Trade Account instead of your Go Account.

You can execute all trade order types as margin trades, including market, limit, stop, TWAP, and steady pace orders. See [Place Trade Orders](/docs/trade-funded-place-orders) for details on each order type, including stop market and stop limit variants.

BitGo initiates a Net Open Position (NOP) check before trades execute. Trades that exceed your NOP limit don't execute. Additionally, BitGo runs margin calculations after trades successfully execute. If the trade causes your account to violate the margin limits, then you can't place further trades until your account returns to a healthy state, such as by posting more collateral.

> 📘 **Note:** Trade orders made in testnet confirm but do not settle. Trade orders only settle in the production environment.

## Prerequisites

* [Get Started](/docs/get-started-intro)
* [Create Wallets](/docs/wallets-create-wallets)
* [Deposit Assets](/docs/deposit-assets)
* [Fund Collateral Account](/docs/trade-margin-fund-account)
* Enterprise user with the Trade role
* Access token with the `trade_trade` scope

## Cookbook

Need just the steps? Expand the cookbook below to get started:

<Cookbook slug="place-margin-order" title="Place Margin Order" />

## Place Trade Order

>Endpoint: [Place Order](/reference/tradeordersadd)

```shell cURL (Market)
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export ACCOUNT_ID="<YOUR_ACCOUNT_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
curl -X POST \
    http://$BITGO_EXPRESS_HOST/api/prime/trading/v1/accounts/$ACCOUNT_ID/orders \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $ACCESS_TOKEN" \
    -d '{
           "clientOrderId": "myorder1",
           "type": "market",
           "product": "TBTC-TUSD*",
           "fundingType": "margin",
           "side": "buy",
           "quantity": "10000",
           "quantityCurrency": "TUSD*"
         }'
```
```shell cURL (Limit)
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export ACCOUNT_ID="<YOUR_ACCOUNT_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
curl -X POST http://$BITGO_EXPRESS/prime/trading/v1/accounts/$ACCOUNT_ID/orders \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
     -d '{
           "clientOrderId": "myorder1",
           "type": "limit",
           "product": "TBTC-TUSD*",
           "fundingType": "margin",
           "side": "buy",
           "quantity": "1",
           "quantityCurrency": "TBTC",
           "limitPrice": "10005",
           "duration": 60
         }'
```
```shell cURL (TWAP)
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export ACCOUNT_ID="<YOUR_ACCOUNT_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
curl -X POST http://$BITGO_EXPRESS/prime/trading/v1/accounts/$ACCOUNT_ID/orders \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer $ACCESS_TOKEN"
     -d '{
           "clientOrderId": "myorder1",
           "type": "twap",
           "product": "TBTC-TUSD*",
           "fundingType": "margin",
           "side": "buy",
           "quantity": "100000",
           "quantityCurrency": "TUSD*",
           "duration": 60,
           "interval": 5
         }'

```

#### Step Result

```json
{
  "id": "67fd640c-cb6c-4218-80ae-49e79ec15646",
  "accountId": "60e740e7898f7d00064d43769a73dc48",
  "clientOrderId": "myorderid1",
  "time": "2021-08-05T18:05:23.431Z",
  "creationDate": "2021-08-05T18:05:22.286Z",
  "scheduledDate": "2021-08-05T18:05:00.000Z",
  "lastFillDate": "2021-08-05T18:05:23.302Z",
  "completionDate": "2021-08-05T18:05:23.431Z",
  "settleDate": "2021-08-05T20:00:00.000Z",
  "fundingType": "margin",
  "type": "market",
  "status": "completed",
  "product": "TBTC-TUSD*",
  "side": "buy",
  "quantity": "1000",
  "quantityCurrency": "TUSD*",
  "filledQuantity": "0.02457152",
  "averagePrice": "40697.32"
}
```

## Next

1. [Cover Short Positions](/docs/trade-margin-cover)
1. [Close All Positions](/docs/trade-margin-close)

## See Also

* [API Reference: Get Net Open Margin Position](/reference/trademarginnetopenpositionsget)
* [Go Network Overview](/docs/go-network-overview)
