> 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/accounts-api/positionbook.md).

# PositionBook

Get all current open positions for the trading day.

## Endpoint URL

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

## Sample API Request

```json
{
  "apikey": "<your_app_apikey>"
}
```

## Sample cURL Request

```bash
curl -X POST http://127.0.0.1:5000/api/v1/positionbook \
  -H 'Content-Type: application/json' \
  -d '{
  "apikey": "<your_app_apikey>"
}'
```

## Sample API Response

```json
{
  "status": "success",
  "data": [
    {
      "symbol": "NHPC",
      "exchange": "NSE",
      "product": "MIS",
      "quantity": "-1",
      "average_price": "83.74",
      "ltp": "83.72",
      "pnl": "0.02"
    },
    {
      "symbol": "RELIANCE",
      "exchange": "NSE",
      "product": "MIS",
      "quantity": "0",
      "average_price": "0.0",
      "ltp": "1189.9",
      "pnl": "5.90"
    },
    {
      "symbol": "YESBANK",
      "exchange": "NSE",
      "product": "MIS",
      "quantity": "-104",
      "average_price": "17.2",
      "ltp": "17.31",
      "pnl": "-10.44"
    }
  ]
}
```

## Request Body

| Parameter | Description           | Mandatory/Optional | Default Value |
| --------- | --------------------- | ------------------ | ------------- |
| apikey    | Your OpenAlgo API key | Mandatory          | -             |

`PositionbookSchema` declares only `apikey`. Any other field returns HTTP 400.

## Response Fields

| Field  | Type   | Description               |
| ------ | ------ | ------------------------- |
| status | string | "success" or "error"      |
| data   | array  | Array of position objects |

### Position Object Fields

| Field                 | Type   | Description                                                                   |
| --------------------- | ------ | ----------------------------------------------------------------------------- |
| symbol                | string | Trading symbol                                                                |
| exchange              | string | Exchange code                                                                 |
| product               | string | MIS, CNC, NRML                                                                |
| quantity              | string | Net position quantity                                                         |
| average\_price        | string | Average entry price                                                           |
| ltp                   | string | Last traded price                                                             |
| pnl                   | string | Profit/Loss                                                                   |
| average\_price\_basis | string | Optional qualification when the average/P\&L are not measured from entry cost |

## When the Entry Price Is Not Available

`average_price` is the price the position was entered at, and `pnl` is measured from it. A broker that cannot supply that for a given position sets `average_price_basis` on the row to say what the numbers mean instead. The key is **absent** on every position whose average really is an entry price, so a caller that does not care can ignore it, and one that does can test a single field:

```python
for position in positionbook["data"]:
    if position.get("average_price_basis"):
        # average_price and pnl are not measured from entry - see the value
        ...
```

| Value                     | Meaning                                                                                                                                                                                                                                                                                                |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `carry_forward_valuation` | The position was carried over from a previous day, and the broker reports the overnight leg re-valued at the previous day's settlement price rather than at what it cost. `average_price` is that settlement price and `pnl` is the move since it, i.e. the day's profit and loss, not the position's. |

Only **Kotak Neo** sets this today, when it cannot recover the cost of a carried position. OpenAlgo first uses Kotak's uploaded price (`upldPrc`), then the matching Holdings `averagePrice` for carried cash positions. Without a usable cost, it falls back to Kotak's carried amounts and marks the row. For carried F\&O positions these can be settlement revaluations rather than entry cost; current-day order/trade history does not reconstruct an older entry. Same-day positions with a usable entry price are unaffected.

## Understanding Position Quantity

| Quantity       | Meaning                                    |
| -------------- | ------------------------------------------ |
| Positive (+ve) | Long position                              |
| Negative (-ve) | Short position                             |
| Zero (0)       | Closed position (still shows today's P\&L) |

## Notes

* Returns **all positions including closed ones** (quantity = 0)
* Closed positions show the **realized P\&L** for the day
* **average\_price** is the weighted average entry price
* **ltp** is the current market price
* A simple open-position mark-to-market is `(LTP - average_price) × signed quantity`; broker `pnl` can also include realized day P\&L. Check `average_price_basis` before treating it as return since entry
* For F\&O positions, ensure lot size alignment

## Use Cases

* **Position monitoring**: Track all open positions
* **P\&L tracking**: View real-time profit/loss
* **Risk management**: Monitor position sizes

## Related Endpoints

* [OpenPosition](https://docs.openalgo.in/api-documentation/v1/orders-api/openposition.md) - Get position for specific symbol
* [ClosePosition](https://docs.openalgo.in/api-documentation/v1/orders-api/closeposition.md) - Close all positions

***

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