> 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.md).

# V1

This directory documents the registered OpenAlgo v1 REST API and the separate WebSocket protocol. The source of truth for REST registration is `restx_api/__init__.py`; request validation is defined in `restx_api/schemas.py`, `restx_api/data_schemas.py`, and `restx_api/account_schema.py`.

## Base URLs

```
REST API:  http://127.0.0.1:5000/api/v1
WebSocket: ws://127.0.0.1:8765
```

Replace the local host with the configured HTTPS/WSS domain in a remote deployment.

## Authentication

Most POST endpoints accept the OpenAlgo API key as `apikey` in a JSON object. GET endpoints accept it as the `apikey` query parameter. Telegram and WhatsApp management endpoints may also accept `X-API-KEY`; the Telegram webhook authenticates with `X-Telegram-Bot-Api-Secret-Token` instead of an OpenAlgo key.

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

Never put broker credentials or broker access tokens in these requests. The OpenAlgo API key resolves the active broker session server-side.

## Registered REST Inventory

The current v1 surface contains **57 method/path pairs**. A resource with both GET and POST counts as two endpoints.

### Order Management

| Method | Path                 | Documentation                                                                |
| ------ | -------------------- | ---------------------------------------------------------------------------- |
| POST   | `/placeorder`        | [Place order](/api-documentation/v1/orders-api/placeorder.md)                |
| POST   | `/placesmartorder`   | [Place smart order](/api-documentation/v1/orders-api/placesmartorder.md)     |
| POST   | `/optionsorder`      | [Options order](/api-documentation/v1/orders-api/optionsorder.md)            |
| POST   | `/optionsmultiorder` | [Options multi-order](/api-documentation/v1/orders-api/optionsmultiorder.md) |
| POST   | `/basketorder`       | [Basket order](/api-documentation/v1/orders-api/basketorder.md)              |
| POST   | `/splitorder`        | [Split order](/api-documentation/v1/orders-api/splitorder.md)                |
| POST   | `/modifyorder`       | [Modify order](/api-documentation/v1/orders-api/modifyorder.md)              |
| POST   | `/cancelorder`       | [Cancel order](/api-documentation/v1/orders-api/cancelorder.md)              |
| POST   | `/cancelallorder`    | [Cancel all orders](/api-documentation/v1/orders-api/cancelallorder.md)      |
| POST   | `/closeposition`     | [Close positions](/api-documentation/v1/orders-api/closeposition.md)         |
| POST   | `/placegttorder`     | [Place GTT](/api-documentation/v1/orders-api/placegttorder.md)               |
| POST   | `/modifygttorder`    | [Modify GTT](/api-documentation/v1/orders-api/modifygttorder.md)             |
| POST   | `/cancelgttorder`    | [Cancel GTT](/api-documentation/v1/orders-api/cancelgttorder.md)             |
| POST   | `/gttorderbook`      | [GTT order book](/api-documentation/v1/orders-api/gttorderbook.md)           |

### Order And Account Information

| Method | Path            | Documentation                                                       |
| ------ | --------------- | ------------------------------------------------------------------- |
| POST   | `/orderstatus`  | [Order status](/api-documentation/v1/orders-api/orderstatus.md)     |
| POST   | `/openposition` | [Open position](/api-documentation/v1/orders-api/openposition.md)   |
| POST   | `/funds`        | [Funds](/api-documentation/v1/accounts-api/funds.md)                |
| POST   | `/margin`       | [Margin](/api-documentation/v1/accounts-api/margin.md)              |
| POST   | `/orderbook`    | [Order book](/api-documentation/v1/accounts-api/orderbook.md)       |
| POST   | `/tradebook`    | [Trade book](/api-documentation/v1/accounts-api/tradebook.md)       |
| POST   | `/positionbook` | [Position book](/api-documentation/v1/accounts-api/positionbook.md) |
| POST   | `/holdings`     | [Holdings](/api-documentation/v1/accounts-api/holdings.md)          |

### Market Data And Symbols

| Method | Path                      | Documentation                                                         |
| ------ | ------------------------- | --------------------------------------------------------------------- |
| POST   | `/quotes`                 | [Quote](/api-documentation/v1/data-api/quotes.md)                     |
| POST   | `/multiquotes`            | [Multiple quotes](/api-documentation/v1/data-api/multiquotes.md)      |
| POST   | `/depth`                  | [Market depth](/api-documentation/v1/data-api/depth.md)               |
| POST   | `/history`                | [Historical candles](/api-documentation/v1/data-api/history.md)       |
| POST   | `/intervals`              | [Supported intervals](/api-documentation/v1/data-api/intervals.md)    |
| GET    | `/ticker/<string:symbol>` | [Ticker-compatible history](/api-documentation/v1/data-api/ticker.md) |
| POST   | `/symbol`                 | [Symbol information](/api-documentation/v1/data-api/symbol.md)        |
| POST   | `/search`                 | [Symbol search](/api-documentation/v1/data-api/search.md)             |
| POST   | `/expiry`                 | [Expiry dates](/api-documentation/v1/data-api/expiry.md)              |
| GET    | `/instruments`            | [Instrument master](/api-documentation/v1/data-api/instruments.md)    |

### Options Analytics

| Method | Path                 | Documentation                                                              |
| ------ | -------------------- | -------------------------------------------------------------------------- |
| POST   | `/optionsymbol`      | [Resolve option symbol](/api-documentation/v1/data-api/optionsymbol.md)    |
| POST   | `/optionchain`       | [Option chain](/api-documentation/v1/data-api/option-chain.md)             |
| POST   | `/syntheticfuture`   | [Synthetic future](/api-documentation/v1/data-api/syntheticfuture.md)      |
| POST   | `/optiongreeks`      | [Option Greeks](/api-documentation/v1/data-api/optiongreeks.md)            |
| POST   | `/multioptiongreeks` | [Batch option Greeks](/api-documentation/v1/data-api/multioptiongreeks.md) |

### Calendar, Analyzer, And Preferences

| Method | Path               | Documentation                                                                       |
| ------ | ------------------ | ----------------------------------------------------------------------------------- |
| POST   | `/market/holidays` | [Market holidays](/api-documentation/v1/utilities-api/holidays.md)                  |
| POST   | `/market/timings`  | [Market timings](/api-documentation/v1/utilities-api/timings.md)                    |
| POST   | `/analyzer`        | [Analyzer status](/api-documentation/v1/accounts-api/analyzer-status.md)            |
| POST   | `/analyzer/toggle` | [Toggle analyzer mode](/api-documentation/v1/accounts-api/analyzer-toggle.md)       |
| POST   | `/pnl/symbols`     | [Sandbox P\&L by symbol](/api-documentation/v1/accounts-api/pnl-symbols.md)         |
| GET    | `/chart`           | [Read chart preferences](/api-documentation/v1/accounts-api/chart-preferences.md)   |
| POST   | `/chart`           | [Update chart preferences](/api-documentation/v1/accounts-api/chart-preferences.md) |
| POST   | `/ping`            | [Authenticated ping](/api-documentation/v1/accounts-api/ping.md)                    |

There is no public `/api/v1/checkholiday` endpoint. Use `/market/timings` for a date; its response identifies holiday/closed sessions through the returned market schedule.

### Messaging

| Method    | Path                    | Documentation                                                            |
| --------- | ----------------------- | ------------------------------------------------------------------------ |
| GET, POST | `/telegram/config`      | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| POST      | `/telegram/start`       | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| POST      | `/telegram/stop`        | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| POST      | `/telegram/webhook`     | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| GET       | `/telegram/users`       | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| POST      | `/telegram/broadcast`   | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| POST      | `/telegram/notify`      | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| GET       | `/telegram/stats`       | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| GET, POST | `/telegram/preferences` | [Telegram REST surface](/api-documentation/v1/utilities-api/telegram.md) |
| POST      | `/whatsapp/notify`      | [WhatsApp notification](/api-documentation/v1/utilities-api/whatsapp.md) |

The Telegram resource contributes 11 method/path pairs. Its webhook acknowledges validated updates but does not yet dispatch them, and the REST broadcast handler currently returns zero delivery counts. Those limitations are documented on the Telegram page.

## WebSocket Protocol

WebSocket streaming is not mounted below `/api/v1`. Clients connect to the proxy on port `8765`, authenticate, and send action messages.

| Mode  | Documentation                                             |
| ----- | --------------------------------------------------------- |
| LTP   | [LTP subscription](/api-documentation/v1/websockets.md)   |
| Quote | [Quote subscription](/api-documentation/v1/websockets.md) |
| Depth | [Depth subscription](/api-documentation/v1/websockets.md) |

Supported actions are `authenticate`, `subscribe`, `unsubscribe`, `unsubscribe_all`, `get_broker_info`, `get_supported_brokers`, and `ping`.

## Order Constants

### Exchanges

`NSE`, `BSE`, `NFO`, `BFO`, `CDS`, `BCD`, `MCX`, `NCDEX`, `NCO`, `NSE_INDEX`, `BSE_INDEX`, `MCX_INDEX`, `GLOBAL_INDEX`, and `CRYPTO` are recognized by the shared validation constants. Broker capability metadata determines which subset is usable for the active broker.

### Products And Price Types

| Kind       | Values                                                   |
| ---------- | -------------------------------------------------------- |
| Product    | `MIS`, `CNC`, `NRML`                                     |
| Price type | `MARKET`, `LIMIT`, `SL`, `SL-M`                          |
| Action     | `BUY`, `SELL` (lowercase is normalized by order schemas) |

Regular order, smart-order, basket, split, and modify schemas accept numeric quantities. Fractional quantities are allowed only for `CRYPTO`; non-crypto quantities must be whole numbers. Options order quantities remain positive integers.

## Response And Status Conventions

Most JSON resources return `status: "success"` or `status: "error"`, but broker payloads are normalized only at the wrapper level and some resources intentionally return CSV, plain text, or an empty webhook acknowledgement. Treat each endpoint page as authoritative for its payload.

Common status codes are:

| Code | Meaning                                                                             |
| ---- | ----------------------------------------------------------------------------------- |
| 200  | Request handled successfully                                                        |
| 400  | Invalid JSON, schema validation failure, unsupported mode, or invalid request state |
| 401  | Missing or invalid authentication on endpoints that use 401                         |
| 403  | Invalid API key or operation blocked by mode/policy                                 |
| 404  | Broker module, symbol, order, or linked messaging user not found                    |
| 429  | Flask-Limiter rejected the request                                                  |
| 500  | Unhandled internal or broker error                                                  |

## Rate Limits

Defaults from `.sample.env` are `API_RATE_LIMIT="50 per second"`, `ORDER_RATE_LIMIT="10 per second"`, and `SMART_ORDER_RATE_LIMIT="10 per second"`. Some messaging endpoints use their own limiter. All values are deployment configuration and may contain compound semicolon-separated limits. See [rate limiting](/api-documentation/v1/rate-limiting.md).

## Client Libraries

The Python client is available as `openalgo` and is pinned by this application at `2.0.2`. Go and Node.js examples in `examples/` demonstrate direct REST integration; they are not declared here as separately versioned official SDK releases.
