Skip to main content

The official Python client for communicating with the Dhan API

Project description

DhanHQ-py : v1.2.2

PyPI

The official Python client for communicating with the Dhan API

DhanHQ-py Rest API is used to automate investing and trading. Execute orders in real time along with position management, historical data, tradebook and more with simple API collection.

Dhan (c) 2022. Licensed under the MIT License

Documentation

v1.2.2 - What's New

  • Bug fixes in Bracket Order Placement

Features

  • Order Management
    The order management APIs lets you place a new order, cancel or modify the pending order, retrieve the order status, trade status, order book & tradebook.

  • Portfolio
    With this set of APIs, retrieve your holdings and positions in your portfolio.

  • Historical Data
    Get historical candle data for the desired scrip across segments & exchange, both Intraday 1 minute OHLC and Daily OHLC.

  • Get fund limits
    Get all information of your trading account like balance, margin utilised, collateral, etc.

  • eDIS Authorisation To sell holding stocks, one needs to complete the CDSL eDIS flow, generate T-PIN & mark stock to complete the sell action.

Quickstart

You can install the package via pip

pip install dhanhq

Hands-on

from dhanhq import dhanhq

dhan = dhanhq("client_id","access_token")

# Place an order for Equity Cash
dhan.place_order(security_id='1333',   #hdfcbank
    exchange_segment=dhan.NSE,
    transaction_type=dhan.BUY,
    quantity=10,
    order_type=dhan.MARKET,
    product_type=dhan.INTRA,
    price=0)
    
# Place an order for Futures & Options
dhan.place_order(security_id='52175',  #NiftyPE
    exchange_segment=dhan.FNO,
    transaction_type=dhan.BUY,
    quantity=550,
    order_type=dhan.MARKET,
    product_type=dhan.INTRA,
    price=0)
    
# Place an order for Currency
dhan.place_order(security_id= '10093',  #usdinr
    exchange_segment= dhan.CUR,
    transaction_type= dhan.BUY,
    quantity=1,
    order_type = dhan.MARKET,
    validity= dhan.DAY,
    product_type= dhan.INTRA,
    price=0)

# Place an order for BSE Equity
dhan.place_order(security_id='500180',   #hdfcbank
    exchange_segment=dhan.BSE,
    transaction_type=dhan.BUY,
    quantity=1,
    order_type=dhan.MARKET,
    product_type=dhan.INTRA,
    price=0,)
    
# Place an order for MCX Commodity    
dhan.place_order(security_id= '114',    #gold
    exchange_segment= dhan.BSE,
    transaction_type= dhan.BUY,
    quantity=1,
    order_type=dhan.MARKET,
    product_type= dhan.INTRA,
    price=0)
    
# Place Slice Order
dhan.place_slice_order(security_id='52175',  #NiftyPE
    exchange_segment=dhan.FNO,
    transaction_type=dhan.BUY,
    quantity=2000,              #nifty freeze quantity is 1800
    order_type=dhan.MARKET,
    product_type=dhan.INTRA,
    price=0)
   
# Place MTF Order
dhan.place_order(security_id='1333',   #hdfcbank
    exchange_segment=dhan.NSE,
    transaction_type=dhan.BUY,
    quantity=100,
    order_type=dhan.MARKET,
    product_type=dhan.MTF,
    price=0)
  
# Fetch all orders
dhan.get_order_list()

# Get order by id
dhan.get_order_by_id(order_id)

# modify order
dhan.modify_order(order_id, order_type, leg_name, quantity, price, trigger_price, disclosed_quantity, validity)

# Cancel order
dhan.cancel_order(order_id)

# Get order by correlation id
dhan.get_order_by_corelationID(corelationID)

# Get positions
dhan.get_positions()

# Get holdings
dhan.get_holdings()

# Intraday daily minute charts
dhan.intraday_daily_minute_charts(security_id,exchange_segment,instrument_type)

# Historical Minute charts
dhan.historical_minute_charts(symbol,exchange_segment,instrument_type,expiry_code,from_date,to_date)

# Time Converter
dhan.convert_to_date_time(Julian Date)

# Get trade book
dhan.get_trade_book(order_id)

# Get trade history
dhan.get_trade_history(from_date,to_date,page_number=0)

# Get fund limits
dhan.get_fund_limits()

# Generate TPIN
dhan.generate_tpin()

# Enter TPIN in Form
dhan.open_browser_for_tpin(isin='INE00IN01015',
    qty=1,
    exchange='NSE')

# EDIS Status and Inquiry
dhan.edis_inquiry()

Changelog

Check release notes

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

dhanhq-1.2.2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

dhanhq-1.2.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file dhanhq-1.2.2.tar.gz.

File metadata

  • Download URL: dhanhq-1.2.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for dhanhq-1.2.2.tar.gz
Algorithm Hash digest
SHA256 2dd1a41034e10ad3f317645706b9e6df282c995dda7cd88423768906799a67d4
MD5 d11f86dcb3a2271406f24950b23af553
BLAKE2b-256 0540b8fb713e35b5ab2d9310ce50084de67cd19a8278ffa401ed2b17d1b2e2d8

See more details on using hashes here.

File details

Details for the file dhanhq-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: dhanhq-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for dhanhq-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 670ebc1e69023a95e0f1b32c39b182311dbb31a9d829907b58c18aa78269b872
MD5 7b6f3d9e07411de090501bba063b06d4
BLAKE2b-256 acf54e18744b1d2e38ce7808a1dbd575a8b0220e4084b5d69e43c4b3bd89957c

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