> For the complete documentation index, see [llms.txt](https://docs.openalgo.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openalgo.in/api-documentation/v1/orders-api/basketorder.md).

# BasketOrder

Place multiple orders simultaneously in a single API call. Ideal for portfolio rebalancing, multi-stock strategies, or executing correlated trades.

## Endpoint URL

```http
Local Host   :  POST http://127.0.0.1:5000/api/v1/basketorder
Ngrok Domain :  POST https://<your-ngrok-domain>.ngrok-free.app/api/v1/basketorder
Custom Domain:  POST https://<your-custom-domain>/api/v1/basketorder
```

## Sample API Request

```json
{
  "apikey": "<your_app_apikey>",
  "strategy": "Python",
  "orders": [
    {
      "symbol": "BHEL",
      "exchange": "NSE",
      "action": "BUY",
      "quantity": "1",
      "pricetype": "MARKET",
      "product": "MIS"
    },
    {
      "symbol": "ZOMATO",
      "exchange": "NSE",
      "action": "SELL",
      "quantity": "1",
      "pricetype": "MARKET",
      "product": "MIS"
    },
    {
      "symbol": "RELIANCE",
      "exchange": "NSE",
      "action": "BUY",
      "quantity": "1",
      "pricetype": "LIMIT",
      "product": "MIS",
      "price": "1180"
    }
  ]
}
```

## Sample cURL Request

```bash
curl -X POST http://127.0.0.1:5000/api/v1/basketorder \
  -H 'Content-Type: application/json' \
  -d '{
  "apikey": "<your_app_apikey>",
  "strategy": "Python",
  "orders": [
    {
      "symbol": "BHEL",
      "exchange": "NSE",
      "action": "BUY",
      "quantity": "1",
      "pricetype": "MARKET",
      "product": "MIS"
    },
    {
      "symbol": "ZOMATO",
      "exchange": "NSE",
      "action": "SELL",
      "quantity": "1",
      "pricetype": "MARKET",
      "product": "MIS"
    },
    {
      "symbol": "RELIANCE",
      "exchange": "NSE",
      "action": "BUY",
      "quantity": "1",
      "pricetype": "LIMIT",
      "product": "MIS",
      "price": "1180"
    }
  ]
}'
```

## Sample API Response

```json
{
  "status": "success",
  "results": [
    {
      "symbol": "BHEL",
      "status": "success",
      "orderid": "250408000999544"
    },
    {
      "symbol": "ZOMATO",
      "status": "success",
      "orderid": "250408000997545"
    },
    {
      "symbol": "RELIANCE",
      "status": "success",
      "orderid": "250408000997546"
    }
  ]
}
```

## Request Body

| Parameter | Description            | Mandatory/Optional | Default Value |
| --------- | ---------------------- | ------------------ | ------------- |
| apikey    | Your OpenAlgo API key  | Mandatory          | -             |
| strategy  | Strategy identifier    | Mandatory          | -             |
| orders    | Array of order objects | Mandatory          | -             |

### Order Object Fields

| Parameter      | Description                                               | Mandatory/Optional | Default Value |
| -------------- | --------------------------------------------------------- | ------------------ | ------------- |
| symbol         | Trading symbol                                            | Mandatory          | -             |
| exchange       | Exchange code accepted by the shared validation constants | Mandatory          | -             |
| action         | Order action: BUY or SELL                                 | Mandatory          | -             |
| quantity       | Positive numeric order quantity                           | Mandatory          | -             |
| pricetype      | Price type: MARKET, LIMIT, SL, SL-M                       | Optional           | MARKET        |
| product        | Product type: MIS, CNC, NRML                              | Optional           | MIS           |
| price          | Order price (for LIMIT orders)                            | Optional           | 0             |
| trigger\_price | Trigger price (for SL orders)                             | Optional           | 0             |

## Response Fields

| Field   | Type   | Description                               |
| ------- | ------ | ----------------------------------------- |
| status  | string | "success" if at least one order succeeded |
| results | array  | Array of individual order results         |

### Results Array Fields

| Field   | Type   | Description                       |
| ------- | ------ | --------------------------------- |
| symbol  | string | Trading symbol                    |
| status  | string | "success" or "error"              |
| orderid | string | Order ID from broker (on success) |
| message | string | Error message (on failure)        |

## Notes

* BUY orders are processed before SELL orders. Live execution uses concurrent batches of 10 with a one-second delay between batches.
* Analyzer execution prefetches quotes and sends the ordered basket through the sandbox path.
* If some orders fail, others still execute (partial success possible)
* Each order in the basket is independent
* Fractional quantities are accepted only for `CRYPTO`; non-crypto quantities must be whole numbers.
* Use for:
  * **Portfolio rebalancing**: Buy/sell multiple stocks together
  * **Pair trading**: Simultaneous long/short positions
  * **Index tracking**: Replicating index constituents

## Example Use Cases

### Portfolio Rebalancing

```json
{
  "apikey": "<your_app_apikey>",
  "strategy": "Rebalance",
  "orders": [
    {"symbol": "TCS", "exchange": "NSE", "action": "BUY", "quantity": "5", "pricetype": "MARKET", "product": "CNC"},
    {"symbol": "INFY", "exchange": "NSE", "action": "BUY", "quantity": "10", "pricetype": "MARKET", "product": "CNC"},
    {"symbol": "WIPRO", "exchange": "NSE", "action": "SELL", "quantity": "8", "pricetype": "MARKET", "product": "CNC"}
  ]
}
```

### Pair Trading

```json
{
  "apikey": "<your_app_apikey>",
  "strategy": "PairTrade",
  "orders": [
    {"symbol": "SBIN", "exchange": "NSE", "action": "BUY", "quantity": "100", "pricetype": "MARKET", "product": "MIS"},
    {"symbol": "BANKBARODA", "exchange": "NSE", "action": "SELL", "quantity": "200", "pricetype": "MARKET", "product": "MIS"}
  ]
}
```

***

**Back to**: [API Documentation](/api-documentation/v1.md)
