Skip to main content

python library to get MCX India data

Project description

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, 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:

  • pandas
  • requests
  • xlrd

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

All exported functions return a pandas.DataFrame.

Live Market Data

  • get_market_watch()
  • 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() and get_historical_data() use YYYYMMDD
  • get_pro_cli_details() uses month format YYYYMM
  • get_option_chain() expiry uses DDMMMYYYY, for example 15NOV2023
  • 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 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:

License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcxlib-0.3.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcxlib-0.3-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file mcxlib-0.3.tar.gz.

File metadata

  • Download URL: mcxlib-0.3.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for mcxlib-0.3.tar.gz
Algorithm Hash digest
SHA256 f2d778f553b16dd9f09db0a096071a855c9b88e1da972d7377d06504e26971d7
MD5 363cb9e1f523bbf5a85017491c10d014
BLAKE2b-256 3164eb355f6415ef3f3eedd707f97e65726dfd4d6590a1bd376070d2ed657e08

See more details on using hashes here.

File details

Details for the file mcxlib-0.3-py3-none-any.whl.

File metadata

  • Download URL: mcxlib-0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for mcxlib-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2941176b367dcb9e3bb5f664064d3daedd75e6f79e8419962e182ae0892d347d
MD5 ef3e88b1681c7651a945fee1c39df2a1
BLAKE2b-256 80754892104c07a8a8cb6ec4ccb61053df5f94cd8e36b8dd0a8a37b561825991

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page