Library to get candlesticks info
Project description
candlestix
Python package for fetching and working with candlestick data, focused on Indian markets.
candlestix 3.0.0 uses Upstox History V3 for market candles and keeps the main
loader contract stable:
CandleDataLoader().candles(symbol, exchange, candle_length, duration_in_days=-1)
What Changed In 3.0.0
- Upstox candle loading now uses
HistoryV3Api - Historical requests are split into API-safe batches and stitched together
- Native candle sizes are requested from Upstox instead of resampling old V2 data
- Current-day candles are fetched separately and merged with historical candles
The public candle-loading entry point remains CandleDataLoader.
Core Concepts
1. Instrument bootstrap
Before using the Upstox-backed loader, initialize the package:
import candlestix
candlestix.init()
This:
- creates a cache directory under the system temp directory
- downloads the Upstox instrument master
- builds in-memory lookup tables for NSE and BSE symbols
Without candlestix.init(), symbol-based Upstox candle fetches will not resolve instrument keys.
2. Upstox-backed candle loader
Main file: candlestix/candle_loader.py
Responsibilities:
- map public
CandleLengthvalues to Upstox V3unitandinterval - enforce historical API fetch limits
- fetch current-day intraday candles separately
- combine and sort candle data
- cache historical results on disk
3. Chitragupt HTTP loader
Main file: candlestix/candle_loader_ctg.py
This is a separate lightweight loader for a plain HTTP API. It does not depend on:
- Upstox SDK
- instrument bootstrap
- local file caching
Supported Candle Lengths
Public candle lengths are defined in candlestix/candleconf.py.
The core loader currently supports:
ONE_MINFIVE_MINTEN_MINFIFTEEN_MINTHIRTY_MINONE_HOURDAY
WEEK and MONTH remain in the enum for compatibility, but are not directly fetched by CandleDataLoader.
Upstox V3 Fetch Strategy
Upstox imposes limits on how much historical data can be fetched in one request.
CandleDataLoader handles this internally by splitting the requested date range
into multiple batches and concatenating the results.
Current batching strategy:
ONE_MIN,FIVE_MIN,TEN_MIN,FIFTEEN_MIN: 1-month chunksTHIRTY_MIN,ONE_HOUR: 3-month chunksDAY: 10-year chunks
Current-day candles are fetched separately from the intraday endpoint and merged with historical candles after de-duplication.
Quick Start
Upstox loader example
import candlestix
from candlestix import Exchange
from candlestix.candle_loader import CandleDataLoader
from candlestix.candleconf import CandleLength
candlestix.init()
loader = CandleDataLoader()
df = loader.candles("INDHOTEL", Exchange.NSE, CandleLength.ONE_MIN)
print(df.tail())
Index example
import candlestix
from candlestix import Exchange
from candlestix.candle_loader import CandleDataLoader
from candlestix.candleconf import CandleLength
candlestix.init()
loader = CandleDataLoader()
df = loader.candles("NIFTY_50", Exchange.NSE_INDEX, CandleLength.THIRTY_MIN)
print(df.tail())
CTG loader example
from candlestix.candle_loader_ctg import CtgCandleLoader
loader = CtgCandleLoader()
df = loader.df_lookback("OIL", lookback_days=180)
print(df.tail())
Output Contract
CandleDataLoader.candles(...)
Returns a pandas DataFrame:
- index:
dateasDatetimeIndex - columns:
open,high,low,close,volume - sorted in chronological order
CtgCandleLoader.df(...)
Returns a pandas DataFrame:
- index:
dateasDatetimeIndex - columns:
open,high,low,close,volume,oi - sorted in chronological order
Dependencies
Core dependencies:
upstox-python-sdk>=2.21.0pandas
candle_loader_ctg.py also uses requests.
Development Notes
Focused tests added for the V3 rewrite:
- Upstox batching and interval mapping:
test/test_candle_loader_v3.py - CTG loader behavior:
test/test_candle_loader_ctg.py
Run them with the project virtualenv:
venv/bin/python -m unittest discover -s test -p 'test_candle_loader_v3.py' -v
venv/bin/python -m unittest discover -s test -p 'test_candle_loader_ctg.py' -v
Build
Before building, update the project version in setup.py.
Build from project root:
./build.sh
The build script deletes:
build/dist/candlestix.egg-info/
Then builds the wheel using:
python3 -m build --wheel
Build And Install
./build.sh -i
or
./build.sh --install
Verify:
pip list | grep candlestix
Uninstall
pip uninstall candlestix
pip list | grep candlestix
Upload
Upload to PyPI:
twine upload dist/*
Install twine if needed:
pip install twine
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file candlestix-3.0.1-py3-none-any.whl.
File metadata
- Download URL: candlestix-3.0.1-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6e57368e1e01cc5fe8c21633c12d7ce0df098344c59196b1b87dbd1c706f608
|
|
| MD5 |
d4905ffc55dad2137a73bfdadff50d34
|
|
| BLAKE2b-256 |
b3c603e814e419e12bb254645de711fd1037514c405ba0384b9cc8ea4750ee3b
|