Skip to content

kartik4042/dhan-python-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

📈 Dhan Trading Platform - Python SDK

This repository contains a Python SDK generated using the Dhan Trading Platform's OpenAPI (Swagger) specification. It allows seamless interaction with Dhan's order management, portfolio, funds, and market data APIs.


🚀 Features

  • ✅ Place, modify, and cancel orders
  • 📊 Access real-time and historical market data
  • 💼 View portfolio holdings and fund details
  • 🔐 Secure API access via access tokens

🛠️ Installation

1. Clone or Download the SDK

git clone https://github.com/your-username/dhan-python-sdk.git
cd dhan-python-sdk

2. Install the SDK locally

pip install .

📦 This will install the SDK along with its dependencies.


📌 Prerequisites

  • Python 3.7+
  • Access to Dhan APIs
  • Your personal Access Token from Dhan

⚙️ Configuration

To authenticate and use the SDK:

from dhan_sdk import Configuration, ApiClient
from dhan_sdk.api.orders_api import OrdersApi
from dhan_sdk.models.place_order_request import PlaceOrderRequest

🧪 Example: Placing an Order

# Setup configuration with your access token
configuration = Configuration(
    host="https://api.dhan.co"
)
configuration.api_key['access-token'] = 'YOUR_ACCESS_TOKEN'

# Initialize API client and Orders API
with ApiClient(configuration) as api_client:
    orders_api = OrdersApi(api_client)

    # Define order details
    order_request = PlaceOrderRequest(
        security_id="RELIANCE-EQ",
        exchange_segment="NSE",
        transaction_type="BUY",
        quantity=10,
        order_type="MARKET",
        price=0,
        product_type="INTRA"
    )

    # Place the order
    try:
        response = orders_api.place_order(order_request)
        print("✅ Order placed successfully:", response)
    except Exception as e:
        print("❌ Failed to place order:", e)

📚 API Reference

All API classes are located in the dhan_sdk.api package:

  • OrdersApi
  • MarketDataApi
  • PortfolioApi
  • FundsApi

Model classes (request/response schemas) are in dhan_sdk.models.


🔐 Authentication

All API calls require an access-token which can be retrieved from your Dhan Profile Settings → DhanHQ Trading APIs

configuration.api_key['access-token'] = 'YOUR_ACCESS_TOKEN'

🧰 Development

Regenerate SDK (if YAML is updated):

openapi-generator generate -i dhan_api.yaml -g python -o dhan_sdk

🧾 License

This SDK is provided under the MIT License.


🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published