xiaohongshu
xiaohongshu
market-data
Market data retrieval with OpenAlgo - real-time quotes, historical OHLCV, market depth, option chains, WebSocket streaming, and symbol search
Full skill instructions
Access real-time and historical market data using OpenAlgo's unified Python SDK. Supports REST API for on-demand data and WebSocket for real-time streaming.
from openalgo import api
# REST API only
client = api(
api_key='your_api_key_here',
host='http://127.0.0.1:5000'
)
# With WebSocket streaming
client = api(
api_key='your_api_key_here',
host='http://127.0.0.1:5000',
ws_url='ws://127.0.0.1:8765',
verbose=True # Enable connection logs
)
python scripts/quotes.py --symbol RELIANCE --exchange NSE
python scripts/quotes.py --symbols RELIANCE,TCS,INFY --exchange NSE
python scripts/history.py --symbol SBIN --exchange NSE --interval 5m --start 2025-01-01 --end 2025-01-15
python scripts/depth.py --symbol SBIN --exchange NSE
python scripts/stream.py --symbols NIFTY,BANKNIFTY --exchange NSE_INDEX --mode ltp
Get current market quote for a symbol:
response = client.quotes(symbol="RELIANCE", exchange="NSE")
Response:
{
"status": "success",
"data": {
"open": 1172.0,
"high": 1196.6,
"low": 1163.3,
"ltp": 1187.75,
"ask": 1188.0,
"bid": 1187.85,
"prev_close": 1165.7,
"volume": 14414545
}
}
Get quotes for multiple symbols in one call:
response = client.multiquotes(symbols=[
{"symbol": "RELIANCE", "exchange": "NSE"},
{"symbol": "TCS", "exchange": "NSE"},
{"symbol": "INFY", "exchange": "NSE"},
{"symbol": "NIFTY", "exchange": "NSE_INDEX"}
])
Response:
{
"status": "success",
"results": [
{
"symbol": "RELIANCE",
"exchange": "NSE",
"data": {
"open": 1542.3,
"high": 1571.6,
"low": 1540.5,
"ltp": 1569.9,
"prev_close": 1539.7,
"ask": 1569.9,
"bid": 1569.8,
"oi": 0,
"volume": 14054299
}
},
...
]
}
Get order book with 5 best bid/ask levels:
response = client.depth(symbol="SBIN", exchange="NSE")
Response:
{
"status": "success",
"data": {
"open": 760.0,
"high": 774.0,
"low": 758.15,
"ltp": 769.6,
"ltq": 205,
"prev_close": 746.9,
"volume": 9362799,
"oi": 161265750,
"totalbuyqty": 591351,
"totalsellqty": 835701,
"asks": [
{"price": 769.6, "quantity": 767},
{"price": 769.65, "quantity": 115},
{"price": 769.7, "quantity": 162},
{"price": 769.75, "quantity": 1121},
{"price": 769.8, "quantity": 430}
],
"bids": [
{"price": 769.4, "quantity": 886},
{"price": 769.35, "quantity": 212},
{"price": 769.3, "quantity": 351},
{"price": 769.25, "quantity": 343},
{"price": 769.2, "quantity": 399}
]
}
}
Get historical candlestick data:
response = client.history(
symbol="SBIN",
exchange="NSE",
interval="5m",
start_date="2025-01-01",
end_date="2025-01-15"
)
Response (Pandas DataFrame):
close high low open volume
timestamp
2025-01-01 09:15:00+05:30 772.50 774.00 763.20 766.50 318625
2025-01-01 09:20:00+05:30 773.20 774.95 772.10 772.45 197189
2025-01-01 09:25:00+05:30 775.15 775.60 772.60 773.20 227544
...
Available Intervals:
response = client.intervals()
# Returns: {'minutes': ['1m', '3m', '5m', '10m', '15m', '30m'],
# 'hours': ['1h'], 'days': ['D']}
Get complete option chain for an underlying:
chain = client.optionchain(
underlying="NIFTY",
exchange="NSE_INDEX",
expiry_date="30JAN25",
strike_count=10 # ±10 strikes from ATM (optional)
)
Response:
{
"status": "success",
"underlying": "NIFTY",
"underlying_ltp": 26215.55,
"expiry_date": "30JAN25",
"atm_strike": 26200.0,
"chain": [
{
"strike": 26100.0,
"ce": {
"symbol": "NIFTY30JAN2526100CE",
"label": "ITM2",
"ltp": 490,
"bid": 490,
"ask": 491,
"volume": 1195800,
"oi": 5000000,
"lotsize": 75
},
"pe": {
"symbol": "NIFTY30JAN2526100PE",
"label": "OTM2",
"ltp": 193,
"bid": 191.2,
"ask": 193,
"volume": 1832700,
"oi": 4500000,
"lotsize": 75
}
},
...
]
}
Get available expiry dates:
response = client.expiry(
symbol="NIFTY",
exchange="NFO",
instrumenttype="options" # or "futures"
)
# Returns: ['30-JAN-25', '06-FEB-25', '13-FEB-25', ...]
response = client.search(query="NIFTY 26000 JAN CE", exchange="NFO")
Response:
{
"status": "success",
"message": "Found 7 matching symbols",
"data": [
{
"symbol": "NIFTY30JAN2526000CE",
"exchange": "NFO",
"expiry": "30-JAN-25",
"strike": 26000,
"instrumenttype": "CE",
"lotsize": 75
},
...
]
}
response = client.symbol(symbol="NIFTY30JAN25FUT", exchange="NFO")
Response:
{
"status": "success",
"data": {
"symbol": "NIFTY30JAN25FUT",
"exchange": "NFO",
"name": "NIFTY",
"expiry": "30-JAN-25",
"instrumenttype": "FUT",
"lotsize": 75,
"freeze_qty": 1800,
"tick_size": 10
}
}
Download complete instrument list for an exchange:
instruments = client.instruments(exchange="NSE")
# Returns Pandas DataFrame with all symbols
from openalgo import api
import time
client = api(
api_key='your_api_key',
host='http://127.0.0.1:5000',
ws_url='ws://127.0.0.1:8765',
verbose=True # Show connection logs
)
# Connect to WebSocket
client.connect()
| Level | Value | Description |
|---|---|---|
| Silent | False or 0 | Errors only (default) |
| Basic | True or 1 | Connection, auth, subscription logs |
| Debug | 2 | All market data updates |
instruments = [
{"exchange": "NSE", "symbol": "RELIANCE"},
{"exchange": "NSE", "symbol": "INFY"},
{"exchange": "NSE_INDEX", "symbol": "NIFTY"}
]
def on_ltp(data):
print(f"{data['symbol']}: {data['data']['ltp']}")
client.subscribe_ltp(instruments, on_data_received=on_ltp)
# Run for 60 seconds
time.sleep(60)
# Cleanup
client.unsubscribe_ltp(instruments)
client.disconnect()
def on_quote(data):
d = data['data']
print(f"{data['symbol']}: O={d['open']} H={d['high']} L={d['low']} LTP={d['ltp']}")
client.subscribe_quote(instruments, on_data_received=on_quote)
def on_depth(data):
d = data['data']
print(f"{data['symbol']}: Best Bid={d['bids'][0]['price']} Best Ask={d['asks'][0]['price']}")
client.subscribe_depth(instruments, on_data_received=on_depth)
Access latest cached data without callback:
# After subscribing
ltp_data = client.get_ltp()
quote_data = client.get_quotes()
depth_data = client.get_depth()
# Access specific symbol
nifty_ltp = ltp_data['ltp']['NSE_INDEX']['NIFTY']['ltp']
response = client.holidays(year=2025)
Response:
{
"data": [
{
"date": "2025-01-26",
"description": "Republic Day",
"holiday_type": "TRADING_HOLIDAY",
"closed_exchanges": ["NSE", "BSE", "NFO", "MCX"]
},
...
]
}
response = client.timings(date="2025-01-15")
Response:
{
"data": [
{"exchange": "NSE", "start_time": 1705293300000, "end_time": 1705315800000},
{"exchange": "BSE", "start_time": 1705293300000, "end_time": 1705315800000},
{"exchange": "MCX", "start_time": 1705293000000, "end_time": 1705346700000}
]
}
watchlist = [
{"symbol": "NIFTY", "exchange": "NSE_INDEX"},
{"symbol": "BANKNIFTY", "exchange": "NSE_INDEX"},
{"symbol": "RELIANCE", "exchange": "NSE"},
{"symbol": "HDFCBANK", "exchange": "NSE"},
{"symbol": "INFY", "exchange": "NSE"}
]
quotes = client.multiquotes(symbols=watchlist)
for item in quotes.get('results', []):
data = item.get('data', {})
change = ((data['ltp'] - data['prev_close']) / data['prev_close']) * 100
print(f"{item['symbol']}: {data['ltp']} ({change:+.2f}%)")
from datetime import date
today = date.today().strftime("%Y-%m-%d")
intraday = client.history(
symbol="NIFTY",
exchange="NSE_INDEX",
interval="1m",
start_date=today,
end_date=today
)
print(f"Today's range: High={intraday['high'].max()}, Low={intraday['low'].min()}")
import time
while True:
chain = client.optionchain(
underlying="NIFTY",
exchange="NSE_INDEX",
expiry_date="30JAN25",
strike_count=5
)
atm = chain.get('atm_strike')
print(f"\nNIFTY ATM: {atm}, LTP: {chain.get('underlying_ltp')}")
for strike in chain.get('chain', []):
if strike['strike'] == atm:
ce = strike['ce']
pe = strike['pe']
print(f" CE: {ce['ltp']} (Vol: {ce['volume']})")
print(f" PE: {pe['ltp']} (Vol: {pe['volume']})")
time.sleep(5)
verbose=2 for debugging WebSocket issuesxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience