# OpenAlgo Python Library
A Python library for algorithmic trading using OpenAlgo's REST APIs. This library provides a comprehensive interface for order management, market data, account operations, and strategy automation.
## Installation
```bash
pip install openalgo
```
## Quick Start
```python
from openalgo import api
# Initialize the client
client = api(
api_key="your_api_key",
host="http://127.0.0.1:5000" # or your OpenAlgo server URL
)
```
## API Categories
### 1. Strategy API
#### Strategy Management Module
OpenAlgo's Strategy Management Module allows you to automate your trading strategies using webhooks. This enables seamless integration with any platform or custom system that can send HTTP requests. The Strategy class provides a simple interface to send signals that trigger orders based on your strategy configuration in OpenAlgo.
```python
from openalgo import Strategy
import requests
# Initialize strategy client
client = Strategy(
host_url="http://127.0.0.1:5000", # Your OpenAlgo server URL
webhook_id="your-webhook-id" # Get this from OpenAlgo strategy section
)
try:
# Long entry (BOTH mode with position size)
response = client.strategyorder("RELIANCE", "BUY", 1)
print(f"Long entry successful: {response}")
# Short entry
response = client.strategyorder("ZOMATO", "SELL", 1)
print(f"Short entry successful: {response}")
# Close positions
response = client.strategyorder("RELIANCE", "SELL", 0) # Close long
response = client.strategyorder("ZOMATO", "BUY", 0) # Close short
except requests.exceptions.RequestException as e:
print(f"Error sending order: {e}")
```
Strategy Modes:
- **LONG_ONLY**: Only processes BUY signals for long-only strategies
- **SHORT_ONLY**: Only processes SELL signals for short-only strategies
- **BOTH**: Processes both BUY and SELL signals with position sizing
The Strategy Management Module can be integrated with:
- Custom trading systems
- Technical analysis platforms
- Alert systems
- Automated trading bots
- Any system capable of making HTTP requests
### 2. Accounts API
#### Funds
Get funds and margin details of the trading account.
```python
result = client.funds()
# Returns:
{
"data": {
"availablecash": "18083.01",
"collateral": "0.00",
"m2mrealized": "0.00",
"m2munrealized": "0.00",
"utiliseddebits": "0.00"
},
"status": "success"
}
```
#### Orderbook
Get orderbook details with statistics.
```python
result = client.orderbook()
# Returns order details and statistics including:
# - Total buy/sell orders
# - Total completed/open/rejected orders
# - Individual order details with status
```
#### Tradebook
Get execution details of trades.
```python
result = client.tradebook()
# Returns list of executed trades with:
# - Symbol, action, quantity
# - Average price, trade value
# - Timestamp, order ID
```
#### Positionbook
Get current positions across all segments.
```python
result = client.positionbook()
# Returns list of positions with:
# - Symbol, exchange, product
# - Quantity, average price
```
#### Holdings
Get stock holdings with P&L details.
```python
result = client.holdings()
# Returns:
# - List of holdings with quantity and P&L
# - Statistics including total holding value
# - Total investment value and P&L
```
#### Analyzer Status
Get analyzer status information.
```python
result = client.analyzerstatus()
# Returns:
{
"data": {
"analyze_mode": false,
"mode": "live",
"total_logs": 2
},
"status": "success"
}
```
#### Analyzer Toggle
Toggle analyzer mode between analyze and live modes.
```python
# Switch to analyze mode (simulated responses)
result = client.analyzertoggle(mode=True)
# Switch to live mode (actual broker operations)
result = client.analyzertoggle(mode=False)
# Returns:
{
"status": "success",
"data": {
"mode": "live/analyze",
"analyze_mode": true/false,
"total_logs": 2,
"message": "Analyzer mode switched to live"
}
}
```
### 3. Orders API
#### Place Order
Place a regular order.
```python
result = client.placeorder(
symbol="RELIANCE",
exchange="NSE",
action="BUY",
quantity=1,
price_type="MARKET",
product="MIS"
)
```
#### Place Smart Order
Place an order with position sizing.
```python
result = client.placesmartorder(
symbol="RELIANCE",
exchange="NSE",
action="BUY",
quantity=1,
position_size=100,
price_type="MARKET",
product="MIS"
)
```
#### Basket Order
Place multiple orders simultaneously.
```python
orders = [
{
"symbol": "RELIANCE",
"exchange": "NSE",
"action": "BUY",
"quantity": 1,
"pricetype": "MARKET",
"product": "MIS"
},
{
"symbol": "INFY",
"exchange": "NSE",
"action": "SELL",
"quantity": 1,
"pricetype": "MARKET",
"product": "MIS"
}
]
result = client.basketorder(orders=orders)
```
#### Split Order
Split a large order into smaller ones.
```python
result = client.splitorder(
symbol="YESBANK",
exchange="NSE",
action="SELL",
quantity=105,
splitsize=20,
price_type="MARKET",
product="MIS"
)
```
#### Order Status
Check status of a specific order.
```python
result = client.orderstatus(
order_id="24120900146469",
strategy="Test Strategy"
)
```
#### Open Position
Get current open position for a symbol.
```python
result = client.openposition(
symbol="YESBANK",
exchange="NSE",
product="CNC"
)
```
#### Modify Order
Modify an existing order.
```python
result = client.modifyorder(
order_id="24120900146469",
symbol="RELIANCE",
action="BUY",
exchange="NSE",
quantity=2,
price="2100",
product="MIS",
price_type="LIMIT"
)
```
#### Cancel Order
Cancel a specific order.
```python
result = client.cancelorder(
order_id="24120900146469"
)
```
#### Cancel All Orders
Cancel all open orders.
```python
result = client.cancelallorder()
```
#### Close Position
Close all open positions.
```python
result = client.closeposition()
```
### 4. WebSocket Feed API
The WebSocket Feed API provides real-time market data through WebSocket connections. The API supports three types of market data:
#### LTP (Last Traded Price) Feed
Get real-time LTP updates for multiple instruments:
```python
from openalgo import api
import time
# Initialize the client with explicit WebSocket URL
client = api(
api_key="your_api_key",
host="http://127.0.0.1:5000", # REST API host
ws_url="ws://127.0.0.1:8765" # WebSocket server URL (can be different from REST API)
)
# Define instruments to subscribe to
instruments = [
{"exchange": "MCX", "symbol": "GOLDPETAL30MAY25FUT"},
{"exchange": "MCX", "symbol": "GOLD05JUN25FUT"}
]
# Callback function for data updates
def on_data_received(data):
print("LTP Update:")
print(data)
# Connect and subscribe
client.connect()
client.subscribe_ltp(instruments, on_data_received=on_data_received)
# Poll LTP data
print(client.get_ltp())
# Returns nested format:
# {"ltp": {"MCX": {"GOLDPETAL30MAY25FUT": {"timestamp": 1747761583959, "ltp": 9529.0}}}}
# Cleanup
client.unsubscribe_ltp(instruments)
client.disconnect()
```
#### Quote Feed
Get real-time quote updates with OHLC data:
```python
from openalgo import api
# Initialize the client
client = api(
api_key="your_api_key",
host="http://127.0.0.1:5000",
ws_url="ws://127.0.0.1:8765"
)
# Define instruments
instruments = [
{"exchange": "MCX", "symbol": "GOLDPETAL30MAY25FUT"}
]
# Connect and subscribe
client.connect()
client.subscribe_quote(instruments)
# Poll quote data
print(client.get_quotes())
# Returns nested format:
# {"quote": {"MCX": {"GOLDPETAL30MAY25FUT": {
# "timestamp": 1747767126517,
# "open": 9430.0,
# "high": 9544.0,
# "low": 9390.0,
# "close": 9437.0,
# "ltp": 9535.0
# }}}}
# Cleanup
client.unsubscribe_quote(instruments)
client.disconnect()
```
#### Market Depth Feed
Get real-time market depth (order book) data:
```python
from openalgo import api
# Initialize the client
client = api(
api_key="your_api_key",
host="http://127.0.0.1:5000",
ws_url="ws://127.0.0.1:8765"
)
# Define instruments
instruments = [
{"exchange": "MCX", "symbol": "GOLDPETAL30MAY25FUT"}
]
# Connect and subscribe
client.connect()
client.subscribe_depth(instruments)
# Poll depth data
print(client.get_depth())
# Returns nested format with order book:
# {"depth": {"MCX": {"GOLDPETAL30MAY25FUT": {
# "timestamp": 1747767126517,
# "ltp": 9535.0,
# "buyBook": {"1": {"price": "9533.0", "qty": "53332", "orders": "0"}, ...},
# "sellBook": {"1": {"price": "9535.0", "qty": "53332", "orders": "0"}, ...}
# }}}}
# Cleanup
client.unsubscribe_depth(instruments)
client.disconnect()
```
### 5. REST Data API
#### Quotes
Get real-time quotes for a symbol using REST API.
```python
result = client.quotes(
symbol="RELIANCE",
exchange="NSE"
)
# Returns bid/ask, LTP, volume and other quote data
```
#### Market Depth
Get market depth (order book) data.
```python
result = client.depth(
symbol="RELIANCE",
exchange="NSE"
)
# Returns market depth with top 5 bids/asks
```
#### Historical Data
Get historical price data.
```python
result = client.history(
symbol="RELIANCE",
exchange="NSE",
interval="5m", # Use intervals() to get supported intervals
start_date="2024-01-01",
end_date="2024-01-31"
)
# Returns pandas DataFrame with OHLC data
```
#### Intervals
Get supported time intervals for historical data.
```python
result = client.intervals()
# Returns:
{
"status": "success",
"data": {
"seconds": ["1s"],
"minutes": ["1m", "2m", "3m", "5m", "10m", "15m", "30m", "60m"],
"hours": [],
"days": ["D"],
"weeks": [],
"months": []
}
}
```
> Note: The legacy `interval()` method is still available but will be deprecated in future versions.
#### Symbol
Get details for a specific trading symbol.
```python
result = client.symbol(
symbol="NIFTY24APR25FUT",
exchange="NFO"
)
# Returns:
{
"status": "success",
"data": {
"brexchange": "NFO",
"brsymbol": "NIFTY24APR25FUT",
"exchange": "NFO",
"expiry": "24-APR-25",
"id": 39521,
"instrumenttype": "FUTIDX",
"lotsize": 75,
"name": "NIFTY",
"strike": -0.01,
"symbol": "NIFTY24APR25FUT",
"tick_size": 0.05,
"token": "54452"
}
}
```
#### Search
Search for symbols across exchanges.
```python
result = client.search(
query="RELIANCE"
)
# Returns list of matching symbols with details
# Search with exchange filter
result = client.search(
query="NIFTY",
exchange="NFO"
)
# Supported exchanges: NSE, NFO, BSE, BFO, MCX, CDS, BCD, NCDEX, NSE_INDEX, BSE_INDEX, MCX_INDEX
# Returns:
{
"status": "success",
"data": [
{
"symbol": "NIFTY24APR25FUT",
"name": "NIFTY",
"exchange": "NFO",
"token": "54452",
"instrumenttype": "FUTIDX",
"lotsize": 75,
"strike": -0.01,
"expiry": "24-APR-25"
},
# ... more matching symbols
]
}
```
#### Expiry
Get expiry dates for futures and options.
```python
# Get expiry dates for futures
result = client.expiry(
symbol="NIFTY",
exchange="NFO",
instrumenttype="futures"
)
# Returns:
{
"status": "success",
"data": [
"31-JUL-25",
"28-AUG-25",
"25-SEP-25"
],
"message": "Found 3 expiry dates for NIFTY futures in NFO"
}
# Get expiry dates for options
result = client.expiry(
symbol="NIFTY",
exchange="NFO",
instrumenttype="options"
)
# Returns:
{
"status": "success",
"data": [
"10-JUL-25",
"17-JUL-25",
"24-JUL-25",
"31-JUL-25",
"07-AUG-25",
"28-AUG-25",
"25-SEP-25",
"24-DEC-25",
"26-MAR-26",
"25-JUN-26"
],
"message": "Found 10 expiry dates for NIFTY options in NFO"
}
```
## Examples
Check the examples directory for detailed usage:
- account_test.py: Test account-related functions
- order_test.py: Test order management functions
- data_examples.py: Test market data functions
- feed_examples.py: Test WebSocket LTP feeds
- quote_example.py: Test WebSocket quote feeds
- depth_example.py: Test WebSocket market depth feeds
## Publishing to PyPI
1. Update version in `openalgo/__init__.py`
2. Build the distribution:
```bash
python -m pip install --upgrade build
python -m build
```
3. Upload to PyPI:
```bash
python -m pip install --upgrade twine
python -m twine upload dist/*
```
## License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": "https://openalgo.in",
"name": "openalgo",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "trading, algorithmic-trading, finance, websocket, market-data, real-time, stock-market, api-wrapper, openalgo, market-data, trading-api, stock-trading, technical-analysis, indicators, rsi, macd, sma, ema, bollinger-bands, supertrend, atr, volume-analysis",
"author": "Rajandran R",
"author_email": "rajandran@openalgo.in",
"download_url": "https://files.pythonhosted.org/packages/a0/ae/5849f7821d21ca503535397733fe7c8d37446892776ee61850a33a224290/openalgo-1.0.21.tar.gz",
"platform": null,
"description": "# OpenAlgo Python Library\r\n\r\nA Python library for algorithmic trading using OpenAlgo's REST APIs. This library provides a comprehensive interface for order management, market data, account operations, and strategy automation.\r\n\r\n## Installation\r\n\r\n```bash\r\npip install openalgo\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom openalgo import api\r\n\r\n# Initialize the client\r\nclient = api(\r\n api_key=\"your_api_key\",\r\n host=\"http://127.0.0.1:5000\" # or your OpenAlgo server URL\r\n)\r\n```\r\n\r\n## API Categories\r\n\r\n### 1. Strategy API\r\n\r\n#### Strategy Management Module\r\nOpenAlgo's Strategy Management Module allows you to automate your trading strategies using webhooks. This enables seamless integration with any platform or custom system that can send HTTP requests. The Strategy class provides a simple interface to send signals that trigger orders based on your strategy configuration in OpenAlgo.\r\n\r\n```python\r\nfrom openalgo import Strategy\r\nimport requests\r\n\r\n# Initialize strategy client\r\nclient = Strategy(\r\n host_url=\"http://127.0.0.1:5000\", # Your OpenAlgo server URL\r\n webhook_id=\"your-webhook-id\" # Get this from OpenAlgo strategy section\r\n)\r\n\r\ntry:\r\n # Long entry (BOTH mode with position size)\r\n response = client.strategyorder(\"RELIANCE\", \"BUY\", 1)\r\n print(f\"Long entry successful: {response}\")\r\n\r\n # Short entry\r\n response = client.strategyorder(\"ZOMATO\", \"SELL\", 1)\r\n print(f\"Short entry successful: {response}\")\r\n\r\n # Close positions\r\n response = client.strategyorder(\"RELIANCE\", \"SELL\", 0) # Close long\r\n response = client.strategyorder(\"ZOMATO\", \"BUY\", 0) # Close short\r\n\r\nexcept requests.exceptions.RequestException as e:\r\n print(f\"Error sending order: {e}\")\r\n```\r\n\r\nStrategy Modes:\r\n- **LONG_ONLY**: Only processes BUY signals for long-only strategies\r\n- **SHORT_ONLY**: Only processes SELL signals for short-only strategies\r\n- **BOTH**: Processes both BUY and SELL signals with position sizing\r\n\r\nThe Strategy Management Module can be integrated with:\r\n- Custom trading systems\r\n- Technical analysis platforms\r\n- Alert systems\r\n- Automated trading bots\r\n- Any system capable of making HTTP requests\r\n\r\n### 2. Accounts API\r\n\r\n#### Funds\r\nGet funds and margin details of the trading account.\r\n```python\r\nresult = client.funds()\r\n# Returns:\r\n{\r\n \"data\": {\r\n \"availablecash\": \"18083.01\",\r\n \"collateral\": \"0.00\",\r\n \"m2mrealized\": \"0.00\",\r\n \"m2munrealized\": \"0.00\",\r\n \"utiliseddebits\": \"0.00\"\r\n },\r\n \"status\": \"success\"\r\n}\r\n```\r\n\r\n#### Orderbook\r\nGet orderbook details with statistics.\r\n```python\r\nresult = client.orderbook()\r\n# Returns order details and statistics including:\r\n# - Total buy/sell orders\r\n# - Total completed/open/rejected orders\r\n# - Individual order details with status\r\n```\r\n\r\n#### Tradebook\r\nGet execution details of trades.\r\n```python\r\nresult = client.tradebook()\r\n# Returns list of executed trades with:\r\n# - Symbol, action, quantity\r\n# - Average price, trade value\r\n# - Timestamp, order ID\r\n```\r\n\r\n#### Positionbook\r\nGet current positions across all segments.\r\n```python\r\nresult = client.positionbook()\r\n# Returns list of positions with:\r\n# - Symbol, exchange, product\r\n# - Quantity, average price\r\n```\r\n\r\n#### Holdings\r\nGet stock holdings with P&L details.\r\n```python\r\nresult = client.holdings()\r\n# Returns:\r\n# - List of holdings with quantity and P&L\r\n# - Statistics including total holding value\r\n# - Total investment value and P&L\r\n```\r\n\r\n#### Analyzer Status\r\nGet analyzer status information.\r\n```python\r\nresult = client.analyzerstatus()\r\n# Returns:\r\n{\r\n \"data\": {\r\n \"analyze_mode\": false,\r\n \"mode\": \"live\",\r\n \"total_logs\": 2\r\n },\r\n \"status\": \"success\"\r\n}\r\n```\r\n\r\n#### Analyzer Toggle\r\nToggle analyzer mode between analyze and live modes.\r\n```python\r\n# Switch to analyze mode (simulated responses)\r\nresult = client.analyzertoggle(mode=True)\r\n\r\n# Switch to live mode (actual broker operations)\r\nresult = client.analyzertoggle(mode=False)\r\n\r\n# Returns:\r\n{\r\n \"status\": \"success\",\r\n \"data\": {\r\n \"mode\": \"live/analyze\",\r\n \"analyze_mode\": true/false,\r\n \"total_logs\": 2,\r\n \"message\": \"Analyzer mode switched to live\"\r\n }\r\n}\r\n```\r\n\r\n### 3. Orders API\r\n\r\n#### Place Order\r\nPlace a regular order.\r\n```python\r\nresult = client.placeorder(\r\n symbol=\"RELIANCE\",\r\n exchange=\"NSE\",\r\n action=\"BUY\",\r\n quantity=1,\r\n price_type=\"MARKET\",\r\n product=\"MIS\"\r\n)\r\n```\r\n\r\n#### Place Smart Order\r\nPlace an order with position sizing.\r\n```python\r\nresult = client.placesmartorder(\r\n symbol=\"RELIANCE\",\r\n exchange=\"NSE\",\r\n action=\"BUY\",\r\n quantity=1,\r\n position_size=100,\r\n price_type=\"MARKET\",\r\n product=\"MIS\"\r\n)\r\n```\r\n\r\n#### Basket Order\r\nPlace multiple orders simultaneously.\r\n```python\r\norders = [\r\n {\r\n \"symbol\": \"RELIANCE\",\r\n \"exchange\": \"NSE\",\r\n \"action\": \"BUY\",\r\n \"quantity\": 1,\r\n \"pricetype\": \"MARKET\",\r\n \"product\": \"MIS\"\r\n },\r\n {\r\n \"symbol\": \"INFY\",\r\n \"exchange\": \"NSE\",\r\n \"action\": \"SELL\",\r\n \"quantity\": 1,\r\n \"pricetype\": \"MARKET\",\r\n \"product\": \"MIS\"\r\n }\r\n]\r\nresult = client.basketorder(orders=orders)\r\n```\r\n\r\n#### Split Order\r\nSplit a large order into smaller ones.\r\n```python\r\nresult = client.splitorder(\r\n symbol=\"YESBANK\",\r\n exchange=\"NSE\",\r\n action=\"SELL\",\r\n quantity=105,\r\n splitsize=20,\r\n price_type=\"MARKET\",\r\n product=\"MIS\"\r\n)\r\n```\r\n\r\n#### Order Status\r\nCheck status of a specific order.\r\n```python\r\nresult = client.orderstatus(\r\n order_id=\"24120900146469\",\r\n strategy=\"Test Strategy\"\r\n)\r\n```\r\n\r\n#### Open Position\r\nGet current open position for a symbol.\r\n```python\r\nresult = client.openposition(\r\n symbol=\"YESBANK\",\r\n exchange=\"NSE\",\r\n product=\"CNC\"\r\n)\r\n```\r\n\r\n#### Modify Order\r\nModify an existing order.\r\n```python\r\nresult = client.modifyorder(\r\n order_id=\"24120900146469\",\r\n symbol=\"RELIANCE\",\r\n action=\"BUY\",\r\n exchange=\"NSE\",\r\n quantity=2,\r\n price=\"2100\",\r\n product=\"MIS\",\r\n price_type=\"LIMIT\"\r\n)\r\n```\r\n\r\n#### Cancel Order\r\nCancel a specific order.\r\n```python\r\nresult = client.cancelorder(\r\n order_id=\"24120900146469\"\r\n)\r\n```\r\n\r\n#### Cancel All Orders\r\nCancel all open orders.\r\n```python\r\nresult = client.cancelallorder()\r\n```\r\n\r\n#### Close Position\r\nClose all open positions.\r\n```python\r\nresult = client.closeposition()\r\n```\r\n\r\n### 4. WebSocket Feed API\r\n\r\nThe WebSocket Feed API provides real-time market data through WebSocket connections. The API supports three types of market data:\r\n\r\n#### LTP (Last Traded Price) Feed\r\nGet real-time LTP updates for multiple instruments:\r\n```python\r\nfrom openalgo import api\r\nimport time\r\n\r\n# Initialize the client with explicit WebSocket URL\r\nclient = api(\r\n api_key=\"your_api_key\",\r\n host=\"http://127.0.0.1:5000\", # REST API host\r\n ws_url=\"ws://127.0.0.1:8765\" # WebSocket server URL (can be different from REST API)\r\n)\r\n\r\n# Define instruments to subscribe to\r\ninstruments = [\r\n {\"exchange\": \"MCX\", \"symbol\": \"GOLDPETAL30MAY25FUT\"},\r\n {\"exchange\": \"MCX\", \"symbol\": \"GOLD05JUN25FUT\"}\r\n]\r\n\r\n# Callback function for data updates\r\ndef on_data_received(data):\r\n print(\"LTP Update:\")\r\n print(data)\r\n\r\n# Connect and subscribe\r\nclient.connect()\r\nclient.subscribe_ltp(instruments, on_data_received=on_data_received)\r\n\r\n# Poll LTP data\r\nprint(client.get_ltp())\r\n# Returns nested format:\r\n# {\"ltp\": {\"MCX\": {\"GOLDPETAL30MAY25FUT\": {\"timestamp\": 1747761583959, \"ltp\": 9529.0}}}}\r\n\r\n# Cleanup\r\nclient.unsubscribe_ltp(instruments)\r\nclient.disconnect()\r\n```\r\n\r\n#### Quote Feed\r\nGet real-time quote updates with OHLC data:\r\n```python\r\nfrom openalgo import api\r\n\r\n# Initialize the client\r\nclient = api(\r\n api_key=\"your_api_key\",\r\n host=\"http://127.0.0.1:5000\",\r\n ws_url=\"ws://127.0.0.1:8765\"\r\n)\r\n\r\n# Define instruments\r\ninstruments = [\r\n {\"exchange\": \"MCX\", \"symbol\": \"GOLDPETAL30MAY25FUT\"}\r\n]\r\n\r\n# Connect and subscribe\r\nclient.connect()\r\nclient.subscribe_quote(instruments)\r\n\r\n# Poll quote data\r\nprint(client.get_quotes())\r\n# Returns nested format:\r\n# {\"quote\": {\"MCX\": {\"GOLDPETAL30MAY25FUT\": {\r\n# \"timestamp\": 1747767126517,\r\n# \"open\": 9430.0,\r\n# \"high\": 9544.0,\r\n# \"low\": 9390.0,\r\n# \"close\": 9437.0,\r\n# \"ltp\": 9535.0\r\n# }}}}\r\n\r\n# Cleanup\r\nclient.unsubscribe_quote(instruments)\r\nclient.disconnect()\r\n```\r\n\r\n#### Market Depth Feed\r\nGet real-time market depth (order book) data:\r\n```python\r\nfrom openalgo import api\r\n\r\n# Initialize the client\r\nclient = api(\r\n api_key=\"your_api_key\",\r\n host=\"http://127.0.0.1:5000\",\r\n ws_url=\"ws://127.0.0.1:8765\"\r\n)\r\n\r\n# Define instruments\r\ninstruments = [\r\n {\"exchange\": \"MCX\", \"symbol\": \"GOLDPETAL30MAY25FUT\"}\r\n]\r\n\r\n# Connect and subscribe\r\nclient.connect()\r\nclient.subscribe_depth(instruments)\r\n\r\n# Poll depth data\r\nprint(client.get_depth())\r\n# Returns nested format with order book:\r\n# {\"depth\": {\"MCX\": {\"GOLDPETAL30MAY25FUT\": {\r\n# \"timestamp\": 1747767126517,\r\n# \"ltp\": 9535.0,\r\n# \"buyBook\": {\"1\": {\"price\": \"9533.0\", \"qty\": \"53332\", \"orders\": \"0\"}, ...},\r\n# \"sellBook\": {\"1\": {\"price\": \"9535.0\", \"qty\": \"53332\", \"orders\": \"0\"}, ...}\r\n# }}}}\r\n\r\n# Cleanup\r\nclient.unsubscribe_depth(instruments)\r\nclient.disconnect()\r\n```\r\n\r\n### 5. REST Data API\r\n\r\n#### Quotes\r\nGet real-time quotes for a symbol using REST API.\r\n```python\r\nresult = client.quotes(\r\n symbol=\"RELIANCE\",\r\n exchange=\"NSE\"\r\n)\r\n# Returns bid/ask, LTP, volume and other quote data\r\n```\r\n\r\n#### Market Depth\r\nGet market depth (order book) data.\r\n```python\r\nresult = client.depth(\r\n symbol=\"RELIANCE\",\r\n exchange=\"NSE\"\r\n)\r\n# Returns market depth with top 5 bids/asks\r\n```\r\n\r\n#### Historical Data\r\nGet historical price data.\r\n```python\r\nresult = client.history(\r\n symbol=\"RELIANCE\",\r\n exchange=\"NSE\",\r\n interval=\"5m\", # Use intervals() to get supported intervals\r\n start_date=\"2024-01-01\",\r\n end_date=\"2024-01-31\"\r\n)\r\n# Returns pandas DataFrame with OHLC data\r\n```\r\n\r\n#### Intervals\r\nGet supported time intervals for historical data.\r\n```python\r\nresult = client.intervals()\r\n# Returns:\r\n{\r\n \"status\": \"success\",\r\n \"data\": {\r\n \"seconds\": [\"1s\"],\r\n \"minutes\": [\"1m\", \"2m\", \"3m\", \"5m\", \"10m\", \"15m\", \"30m\", \"60m\"],\r\n \"hours\": [],\r\n \"days\": [\"D\"],\r\n \"weeks\": [],\r\n \"months\": []\r\n }\r\n}\r\n```\r\n\r\n> Note: The legacy `interval()` method is still available but will be deprecated in future versions.\r\n\r\n#### Symbol\r\nGet details for a specific trading symbol.\r\n```python\r\nresult = client.symbol(\r\n symbol=\"NIFTY24APR25FUT\",\r\n exchange=\"NFO\"\r\n)\r\n# Returns:\r\n{\r\n \"status\": \"success\",\r\n \"data\": {\r\n \"brexchange\": \"NFO\",\r\n \"brsymbol\": \"NIFTY24APR25FUT\",\r\n \"exchange\": \"NFO\",\r\n \"expiry\": \"24-APR-25\",\r\n \"id\": 39521,\r\n \"instrumenttype\": \"FUTIDX\",\r\n \"lotsize\": 75,\r\n \"name\": \"NIFTY\",\r\n \"strike\": -0.01,\r\n \"symbol\": \"NIFTY24APR25FUT\",\r\n \"tick_size\": 0.05,\r\n \"token\": \"54452\"\r\n }\r\n}\r\n```\r\n\r\n#### Search\r\nSearch for symbols across exchanges.\r\n```python\r\nresult = client.search(\r\n query=\"RELIANCE\"\r\n)\r\n# Returns list of matching symbols with details\r\n\r\n# Search with exchange filter\r\nresult = client.search(\r\n query=\"NIFTY\",\r\n exchange=\"NFO\"\r\n)\r\n# Supported exchanges: NSE, NFO, BSE, BFO, MCX, CDS, BCD, NCDEX, NSE_INDEX, BSE_INDEX, MCX_INDEX\r\n# Returns:\r\n{\r\n \"status\": \"success\",\r\n \"data\": [\r\n {\r\n \"symbol\": \"NIFTY24APR25FUT\",\r\n \"name\": \"NIFTY\",\r\n \"exchange\": \"NFO\",\r\n \"token\": \"54452\",\r\n \"instrumenttype\": \"FUTIDX\",\r\n \"lotsize\": 75,\r\n \"strike\": -0.01,\r\n \"expiry\": \"24-APR-25\"\r\n },\r\n # ... more matching symbols\r\n ]\r\n}\r\n```\r\n\r\n#### Expiry\r\nGet expiry dates for futures and options.\r\n```python\r\n# Get expiry dates for futures\r\nresult = client.expiry(\r\n symbol=\"NIFTY\",\r\n exchange=\"NFO\",\r\n instrumenttype=\"futures\"\r\n)\r\n# Returns:\r\n{\r\n \"status\": \"success\",\r\n \"data\": [\r\n \"31-JUL-25\",\r\n \"28-AUG-25\",\r\n \"25-SEP-25\"\r\n ],\r\n \"message\": \"Found 3 expiry dates for NIFTY futures in NFO\"\r\n}\r\n\r\n# Get expiry dates for options\r\nresult = client.expiry(\r\n symbol=\"NIFTY\",\r\n exchange=\"NFO\",\r\n instrumenttype=\"options\"\r\n)\r\n# Returns:\r\n{\r\n \"status\": \"success\",\r\n \"data\": [\r\n \"10-JUL-25\",\r\n \"17-JUL-25\",\r\n \"24-JUL-25\",\r\n \"31-JUL-25\",\r\n \"07-AUG-25\",\r\n \"28-AUG-25\",\r\n \"25-SEP-25\",\r\n \"24-DEC-25\",\r\n \"26-MAR-26\",\r\n \"25-JUN-26\"\r\n ],\r\n \"message\": \"Found 10 expiry dates for NIFTY options in NFO\"\r\n}\r\n```\r\n\r\n## Examples\r\n\r\nCheck the examples directory for detailed usage:\r\n- account_test.py: Test account-related functions\r\n- order_test.py: Test order management functions\r\n- data_examples.py: Test market data functions\r\n- feed_examples.py: Test WebSocket LTP feeds\r\n- quote_example.py: Test WebSocket quote feeds\r\n- depth_example.py: Test WebSocket market depth feeds\r\n\r\n## Publishing to PyPI\r\n\r\n1. Update version in `openalgo/__init__.py`\r\n\r\n2. Build the distribution:\r\n```bash\r\npython -m pip install --upgrade build\r\npython -m build\r\n```\r\n\r\n3. Upload to PyPI:\r\n```bash\r\npython -m pip install --upgrade twine\r\npython -m twine upload dist/*\r\n```\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A Python library for interacting with OpenAlgo's trading APIs with high-performance technical indicators",
"version": "1.0.21",
"project_urls": {
"Documentation": "https://docs.openalgo.in",
"Homepage": "https://openalgo.in",
"Source": "https://github.com/openalgo/openalgo-python",
"Tracker": "https://github.com/openalgo/openalgo-python/issues"
},
"split_keywords": [
"trading",
" algorithmic-trading",
" finance",
" websocket",
" market-data",
" real-time",
" stock-market",
" api-wrapper",
" openalgo",
" market-data",
" trading-api",
" stock-trading",
" technical-analysis",
" indicators",
" rsi",
" macd",
" sma",
" ema",
" bollinger-bands",
" supertrend",
" atr",
" volume-analysis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "aff197b520851bcf45836f7b83e4842e6aa6526eff6d7afb080fce51208a4640",
"md5": "4bb84f35c56aac14856409e50d753842",
"sha256": "afd3cf74ed9281be56347effc489dfd6003d8883765ef601f5e86d2af3581962"
},
"downloads": -1,
"filename": "openalgo-1.0.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4bb84f35c56aac14856409e50d753842",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 58411,
"upload_time": "2025-07-18T08:33:14",
"upload_time_iso_8601": "2025-07-18T08:33:14.642027Z",
"url": "https://files.pythonhosted.org/packages/af/f1/97b520851bcf45836f7b83e4842e6aa6526eff6d7afb080fce51208a4640/openalgo-1.0.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a0ae5849f7821d21ca503535397733fe7c8d37446892776ee61850a33a224290",
"md5": "8d12c8a90ca23891cd424ca899ab0310",
"sha256": "05c104e15a496010ed15da5fb47a90690d3b48a5524a19ef2af3378a628973e4"
},
"downloads": -1,
"filename": "openalgo-1.0.21.tar.gz",
"has_sig": false,
"md5_digest": "8d12c8a90ca23891cd424ca899ab0310",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 58312,
"upload_time": "2025-07-18T08:33:15",
"upload_time_iso_8601": "2025-07-18T08:33:15.943535Z",
"url": "https://files.pythonhosted.org/packages/a0/ae/5849f7821d21ca503535397733fe7c8d37446892776ee61850a33a224290/openalgo-1.0.21.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-18 08:33:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "openalgo",
"github_project": "openalgo-python",
"github_not_found": true,
"lcname": "openalgo"
}