3. K-line Data (OHLC)
Get candlestick data for charting and technical analysis
Objective
Provide OHLCV (Open/High/Low/Close/Volume) data for candlestick charts and technical analysis. Supported timeframes: 1m, 3m, 5m, 15m, 1h, 1d (weekly and monthly bars are not supported).
Flow
Chart/Strategy Module → Market Data API (OHLC) → Chart Engine- Client sends
symbol,interval,from_date,to_date - API returns OHLCV array by time period
- Normalize data (time/open/high/low/close/volume)
- For long history, iterate with paging, or use
get_ohlc_all/iter_ohlc(SDK 3.3.0) and let the SDK page for you
Sample Code — Sync
from ssi_sdk import Auth, Data, Config
from ssi_sdk.enums import Timeframe
from ssi_sdk.exceptions import ValidationError
from auth_helper import ensure_auth
config = Config(
client_id="<your_client_id>",
api_key="<your_api_key>",
api_secret="<your_api_secret>",
private_key="<your_private_key>",
)
SYMBOL = "SSI"
with Auth(config) as auth:
ensure_auth(auth)
with Data(auth) as data:
# Daily OHLC
daily = data.market_data.get_ohlc_1day_historical(
SYMBOL, from_date="2026/03/01 00:00:00", to_date="2026/03/27 23:59:59"
)
for bar in daily[:5]:
print(f" {bar.trading_date} | O:{bar.open_price} C:{bar.close_price} V:{bar.volume}")
# Hourly OHLC
hourly = data.market_data.get_ohlc_1hour(SYMBOL)
# Paging for large datasets (1-minute)
page, total_bars = 1, 0
while True:
bars = data.market_data.get_ohlc_1minute_historical(
symbol=SYMBOL, from_date="2026/03/25 09:00:00",
to_date="2026/03/25 15:00:00", page=page, size=100,
)
if not bars:
break
total_bars += len(bars)
page += 1
# SDK 3.3.0: fetch ALL bars in a range, the SDK pages for you
# Supported timeframes: 1d, 1m, 3m, 5m, 15m, 1h
all_bars = data.market_data.get_ohlc_all(
SYMBOL, Timeframe.DAY_1,
from_date="2026/01/01 00:00:00", to_date="2026/03/27 23:59:59",
ascending=True, # server returns newest first; ascending=True reverses to oldest -> newest
)
print(f"get_ohlc_all 1d: {len(all_bars)} bars")
# iter_ohlc (generator): one bar at a time, auto paging, newest first
count = sum(
1
for _ in data.market_data.iter_ohlc(
SYMBOL, Timeframe.MINUTE_5,
from_date="2026/03/25 09:00:00", to_date="2026/03/25 15:00:00", size=100,
)
)
print(f"iter_ohlc 5m: {count} bars")
# Weekly (1w) / monthly (1M) bars are NOT supported by the server (error 400210).
# Since SDK 3.3.0, get_ohlc_1week_historical / get_ohlc_1month_historical raise
# ValidationError on the client side without sending a request. Aggregate daily bars if needed.
try:
data.market_data.get_ohlc_1week_historical(
SYMBOL, from_date="2026/01/01 00:00:00", to_date="2026/03/27 23:59:59"
)
except ValidationError as e:
print(f"1 week not supported: {e}")Sample Code — Async
import asyncio
from ssi_sdk import AsyncAuth, AsyncData, Config
from ssi_sdk.enums import Timeframe
from auth_helper import ensure_auth_async
config = Config(...)
async def main():
async with AsyncAuth(config) as auth:
await ensure_auth_async(auth)
async with AsyncData(auth) as data:
daily = await data.market_data.get_ohlc_1day_historical(
"SSI", from_date="2026/03/01 00:00:00", to_date="2026/03/27 23:59:59"
)
hourly = await data.market_data.get_ohlc_1hour("SSI")
# SDK 3.3.0: fetch all bars, auto paging
all_bars = await data.market_data.get_ohlc_all(
"SSI", Timeframe.DAY_1,
from_date="2026/01/01 00:00:00", to_date="2026/03/27 23:59:59",
ascending=True,
)
# iter_ohlc is an async generator
count = 0
async for bar in data.market_data.iter_ohlc(
"SSI", Timeframe.MINUTE_5,
from_date="2026/03/25 09:00:00", to_date="2026/03/25 15:00:00", size=100,
):
count += 1
asyncio.run(main())API Methods
| Method | Timeframe | Description |
|---|---|---|
get_ohlc_1day_historical(symbol, from_date, to_date) | 1 day | Historical daily bars |
get_ohlc_1hour(symbol) | 1 hour | Recent hourly bars |
get_ohlc_1minute_historical(symbol, from_date, to_date, page, size) | 1 min | Historical minute bars (paged) |
get_ohlc_3minute_historical(...) | 3 min | Historical 3-min bars |
get_ohlc_5minute_historical(...) | 5 min | Historical 5-min bars |
get_ohlc_15minute_historical(...) | 15 min | Historical 15-min bars |
get_ohlc_all(symbol, timeframe, from_date, to_date, size, ascending) | 1d, 1m, 3m, 5m, 15m, 1h | All bars in a range (auto paging); ascending=True returns oldest -> newest |
iter_ohlc(symbol, timeframe, from_date, to_date, size) | 1d, 1m, 3m, 5m, 15m, 1h | Generator over bars, auto paging, newest first (async: async for) |
get_ohlc_1week_historical / get_ohlc_1month_historical | 1 week / 1 month | Not supported: raise ValidationError (server error 400210) |