mcxlib
mcxlib is a Python library for fetching publicly available market data from the MCX India website and returning it as pandas DataFrames.
It provides a lightweight wrapper around common MCX endpoints so you can pull market snapshots, derivatives data, and historical reports directly into your Python workflows.
What It Provides
- Live market data such as market watch, available contracts, heat map, top gainers, and top losers
- Derivatives data such as option chain, put-call ratio, and most active contracts
- Historical reports such as bhav copy, date-wise historical data, and trading statistics
- MCX index and participant-level datasets such as iCOMDEX indices and PRO/CLI details
Installation
Install from PyPI:
pip install mcxlib
Upgrade an existing installation:
pip install --upgrade mcxlib
If you are working from source:
pip install -r requirements.txt
pip install -e .
Dependencies
The project relies mainly on:
pandasrequestsxlrd
Some MCX datasets are published as Excel files, so spreadsheet-reading support is required for part of the API.
Quick Start
import mcxlib
market_watch = mcxlib.get_market_watch()
print(market_watch.head())
bhav_copy = mcxlib.get_bhav_copy(
trade_date="20231102",
instrument="ALL",
)
option_chain = mcxlib.get_option_chain(
commodity="CRUDEOIL",
expiry="15NOV2023",
)
historical_data = mcxlib.get_historical_data(
start_date="20230101",
end_date="20231103",
)
Public API
Most exported functions return a pandas.DataFrame. get_mcx_datetime() returns a timezone-aware Python datetime object in IST.
Live Market Data
get_mcx_datetime()get_market_watch()get_available_contracts(commodity="ALL", instrument="ALL")get_heat_map()get_top_gainers()get_top_losers()get_most_active_contracts(instrument="ALL")get_most_active_puts_calls(option_type="PE", product="ALL", instrument="OPTFUT")
Options and Sentiment Data
get_recent_expires(commodity="ALL")get_option_chain(commodity="CRUDEOIL", expiry="15NOV2023")get_put_call_ratio(ratio_type="expiry_wise")
Historical and Report Data
get_bhav_copy(trade_date="YYYYMMDD", instrument="ALL")get_historical_date_wise_data(start_date="YYYYMMDD", end_date="YYYYMMDD")get_historical_data(start_date="YYYYMMDD", end_date="YYYYMMDD")get_category_wise_turnover(year=2023, month_number=9)get_category_wise_oi(year=2023, month_number=9)get_trading_statistics(year=2023, month_number=9)get_ccl_delivery(year=2023, month_number=9)
Index and Participant Data
get_mcx_icomdex_indices()get_pro_cli_details(trade_month="YYYYMM")
Parameter Notes
- Dates for
get_bhav_copy()andget_historical_data()useYYYYMMDD get_pro_cli_details()uses month formatYYYYMMget_option_chain()expiry usesDDMMMYYYY, for example15NOV2023- Historical date-wise queries are limited by MCX to a maximum range of 365 days
- Valid parameter values depend on what MCX currently exposes for each endpoint
Example Use Cases
Get the latest market watch data:
import mcxlib
df = mcxlib.get_market_watch()
print(df.columns)
print(df.head())
Fetch live contracts for a commodity and convert them to JSON:
import mcxlib
df = mcxlib.get_available_contracts(
commodity="LEADMINI",
instrument="FUTCOM",
)
print(df.to_json(orient="records"))
Fetch historical data for analysis:
import mcxlib
df = mcxlib.get_historical_data(
start_date="20230101",
end_date="20230331",
)
print(df.head())
Fetch option chain data for a commodity:
import mcxlib
df = mcxlib.get_option_chain(
commodity="CRUDEOIL",
expiry="15NOV2023",
)
print(df.head())
Error Handling
Most functions raise ValueError when:
- Parameters are invalid
- MCX does not return data for the request
- The upstream MCX endpoint format changes
If you receive an error, first verify the parameter format and whether the requested dataset is currently available on the MCX website.
Limitations
- This library depends on public MCX endpoints and report files remaining available
- Changes on the MCX website can break one or more functions without a package release
- Live data availability depends on MCX publishing current values at request time
Contributing
Contributions are welcome. If you want to help:
- Open an issue: https://github.com/RuchiTanmay/mcxlib/issues
- Submit a pull request with a focused fix or enhancement
- Share examples or documentation improvements to help other users get started
License
This project is licensed under the MIT License. See LICENSE for details.
Metadata
Release files for mcxlib 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mcxlib-0.4.tar.gz | 15.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcxlib-0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.6 kB
Release files / mcxlib-0.4.tar.gz
| Download URL | mcxlib-0.4.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54e33cc5a8735e8aca27e4da4ad61bb81a60f6b726cf0fd503ac635600552409
|
|
BLAKE2b-256 checksum How to use checksums |
245034ef53ab1abab867108c1c0e77972c4211fb580d8977d7df7dbb9c2221d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / mcxlib-0.4-py3-none-any.whl
| Download URL | mcxlib-0.4-py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48a1fa27c337115ad6737bc11fc3decb27a95566822b4b45c0f822c2f3027d1d
|
|
BLAKE2b-256 checksum How to use checksums |
21918d2c6a1256fe3bb13ee887bbef9b71f15b9774577ac35f44e118ef09f6bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|