Metadata-Version: 2.5
Name: sahiapi
Version: 0.2.0
Summary: The official Python client library for the Sahi APIs.
Project-URL: Homepage, https://docs.sahi.com/
Project-URL: Documentation, https://docs.sahi.com/sdk/python/
Author-email: Aaritya Technologies <customercare@sahi.com>
License-Expression: MIT
License-File: LICENSE
Keywords: bse,market-data,nse,options,sahi,stocks,trading
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx>=0.27
Requires-Dist: protobuf>=4.25
Requires-Dist: websocket-client>=1.7
Provides-Extra: dev
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# sahiapi

The official Python SDK for the [Sahi trading APIs](https://docs.sahi.com/).

Build trading and investing workflows in Python: place and manage orders, track
holdings, positions and funds, pull quotes, candles and option chains, and
receive live ticks and order updates over WebSocket.

[Sahi](https://www.sahi.com/) © 2026. Released under the [MIT License](https://opensource.org/license/mit).

## Documentation

- [Python SDK documentation](https://docs.sahi.com/sdk/python/)
- [Sahi API reference](https://docs.sahi.com/)
- [Authentication and API keys](https://docs.sahi.com/api/v1/reference/authentication/)
- [Orders API reference](https://docs.sahi.com/api/v1/reference/orders/)

## Features

- **Orders**: place, modify and cancel orders, and read the order book and the
  trades behind each order.
- **Portfolio**: holdings and open positions.
- **Funds**: available balance and margin in use.
- **Market data**: LTP and quotes for many instruments in one call, historical
  candles, option expiries and option chains.
- **Live streams**: `SahiFeed` streams LTP, quotes and market depth, plus
  order updates, and reconnects and resubscribes on its own.
- **Typed errors**: every API failure raises an exception carrying the HTTP
  status, error code, request id and a hint on how to fix it.

## Installation

```bash
pip install sahiapi
```

Requires Python 3.9 or newer.

## Quickstart

Create an API key in your Sahi account and approve it for the trading day, then
connect:

```python
import os
from sahiapi import SahiAPI

api = SahiAPI.from_credentials(
    key_id=os.environ["SAHI_KEY_ID"],
    secret=os.environ["SAHI_SECRET"],
)
print(api.get_profile())
print(api.get_funds())
```

### Example: place a limit order

Prices are in paise, so ₹2,499.55 is `249955`.

```python
response = api.place_order(
    exchange_segment=SahiAPI.EXCHANGE_SEGMENT_NSE,
    symbol="RELIANCE",
    txn_type=SahiAPI.TXN_TYPE_BUY,
    qty=1,
    order_type=SahiAPI.ORDER_TYPE_LIMIT,
    product=SahiAPI.PRODUCT_DELIVERY,
    validity=SahiAPI.VALIDITY_DAY,
    price=249955,
)
order_id = response["order_ids"][0]
print(api.get_order_detail(order_id))
```

See the [Python SDK documentation](https://docs.sahi.com/sdk/python/) for streaming, market data and
every other endpoint.
