Skip to main content

A library for fetching and caching historical market data from Breeze API using DynamoDB

Project description

Breeze Historical

A Python library for fetching and caching historical market data from ICICI Direct's Breeze API using DynamoDB.

Features

  • Fetch historical option chain data from Breeze API
  • Cache data in DynamoDB for faster subsequent access
  • Support for multiple timeframes (1min, 5min, 30min, daily)
  • Automatic symbol mapping between NSE and ICICI Direct
  • Data interpolation for missing timestamps
  • Market hours aware timestamp generation
  • Verbose mode for detailed operation logging
  • Handles missing data through interpolation
  • Supports multiple expiry dates

Installation

pip install breeze-historical

Prerequisites

  1. ICICI Direct Breeze API credentials
  2. AWS credentials with DynamoDB access
  3. DynamoDB table with the following schema:
    • Partition Key: contract_id (String)
    • Sort Key: ts (String)

Configuration

The library requires both Breeze API and AWS credentials:

Breeze Credentials

  • api_key: Your Breeze API key
  • api_secret: Your Breeze API secret
  • user_id: Your Breeze user ID
  • password: Your Breeze password
  • totp_key: Your TOTP secret key

AWS Credentials

  • access_key_id: AWS access key ID
  • secret_access_key: AWS secret access key
  • region: AWS region (default: "ap-south-1")
  • table_name: DynamoDB table name (default: "breeze_historical")

Usage

from breeze_historical import BreezeHistorical

# Initialize credentials
breeze_creds = {
    "api_key": "your_api_key",
    "api_secret": "your_api_secret",
    "user_id": "your_user_id",
    "password": "your_password",
    "totp_key": "your_totp_key"
}

aws_creds = {
    "access_key_id": "your_aws_access_key",
    "secret_access_key": "your_aws_secret_key",
    "region": "ap-south-1",
    "table_name": "breeze_historical"
}

# Initialize client
client = BreezeHistorical(
    breeze_creds=breeze_creds,
    aws_creds=aws_creds,
    verbose=False  # Set to True for detailed operation logging
)

# Fetch option chain data
data = client.option_chain(
    symbol="BANKNIFTY",
    expiry="2024-03-28",
    start_date="2024-03-20",
    end_date="2024-03-21",
    granularity="5minute"
)

# Data format:
{
    "2024-01-01T09:15:00.000Z": {
        45000: {
            "CE": {
                "open": 100.5,
                "high": 102.0,
                "low": 99.5,
                "close": 101.0,
                "volume": 1000,
                "oi": 5000
            },
            "PE": {
                ...
            }
        },
        45500: {
            ...
        }
    },
    "2024-01-01T09:16:00.000Z": {
        ...
    }
}

Verbose Mode

The library includes a verbose mode that provides detailed logging of operations:

  • Set verbose=True when initializing the client to enable detailed logging
  • Logs include:
    • Client initialization status
    • Data fetching progress
    • Cache hit/miss information
    • Symbol mapping details
    • Strike price discovery
    • Data processing steps
    • Interpolation of missing data

Example with verbose mode:

client = BreezeHistorical(
    breeze_creds=breeze_creds,
    aws_creds=aws_creds,
    verbose=True  # Enable verbose mode
)

Symbol Mapping

Create a JSON file with NSE to ICICI Direct symbol mapping:

{
    "BANKNIFTY": "CNXBAN",
    "NIFTY": "CNX",
    ...
}

Error Handling

The library raises BreezeHistoricalError for various error conditions:

  • Invalid date ranges
  • API failures
  • Authentication issues
  • Data validation errors

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

breeze_historical-0.1.3.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

breeze_historical-0.1.3-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file breeze_historical-0.1.3.tar.gz.

File metadata

  • Download URL: breeze_historical-0.1.3.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for breeze_historical-0.1.3.tar.gz
Algorithm Hash digest
SHA256 191bcfdf3dc7e6fad6a06817370e6fddbcf7d1125dd4ca11e4eead4df51883cb
MD5 b73de02a5d91dcecb76fbcde13a42fd6
BLAKE2b-256 a0b00932bbd6030339dbc69cb844847dc0a49fa6fa442a205165724b6c13b89b

See more details on using hashes here.

File details

Details for the file breeze_historical-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for breeze_historical-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 871934a52e2e2502bfaf880198575e13812b682795b0ad44d3af12e9ab12f1ba
MD5 dc3224cb9a1474fea93359427599b06f
BLAKE2b-256 fd0105a10f16e138a24b5c0dea6df6d9f8ce211513fedf8afdbd3d9bbeed226a

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