Package: dhanhq
DhanHQ-py : v1.3The official Python client for communicating with theDhan APIDhanHQ-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.Not just this, you also get real-time market data via DhanHQ Live Market Feed.Dhan(c) 2024. Licensed under theMIT LicenseDocumentationDhanHQ Developer KitDhanHQ API Documentationv1.3 - What's NewLive Market Feed data is now available across exchanges and segments via DhanHQLow latency websocketsUnlimited instruments per socketEstablish upto 5 sockets per userWith Market Feed, you can subscribe data in below formats:Ticker DataQuote DataMarket DepthFeaturesOrder ManagementThe order management APIs lets you place a new order, cancel or modify the pending order, retrieve the order status, trade status, order book & tradebook.Live Market FeedGet real-time market data to power your trading systems, with easy to implement functions and data across exchanges.PortfolioWith this set of APIs, retrieve your holdings and positions in your portfolio.Historical DataGet historical candle data for the desired scrip across segments & exchange, both Intraday 1 minute OHLC and Daily OHLC.Get fund limitsGet all information of your trading account like balance, margin utilised, collateral, etc.eDIS AuthorisationTo sell holding stocks, one needs to complete the CDSL eDIS flow, generate T-PIN & mark stock to complete the sell action.QuickstartYou can install the package via pippip install dhanhqHands-on APIfromdhanhqimportdhanhqdhan=dhanhq("client_id","access_token")# Place an order for Equity Cashdhan.place_order(security_id='1333',#hdfcbankexchange_segment=dhan.NSE,transaction_type=dhan.BUY,quantity=10,order_type=dhan.MARKET,product_type=dhan.INTRA,price=0)# Place an order for NSE Futures & Optionsdhan.place_order(security_id='52175',#NiftyPEexchange_segment=dhan.NSE_FNO,transaction_type=dhan.BUY,quantity=550,order_type=dhan.MARKET,product_type=dhan.INTRA,price=0)# Place an order for Currencydhan.place_order(security_id='10093',#usdinrexchange_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 Equitydhan.place_order(security_id='500180',#hdfcbankexchange_segment=dhan.BSE,transaction_type=dhan.BUY,quantity=1,order_type=dhan.MARKET,product_type=dhan.INTRA,price=0,)# Place an order for BSE Futures & Optionsdhan.place_order(security_id='1135553',#SensexPEexchange_segment=dhan.BSE_FNO,transaction_type=dhan.BUY,quantity=1,order_type=dhan.MARKET,product_type=dhan.INTRA,price=0,)# Place an order for MCX Commoditydhan.place_order(security_id='114',#goldexchange_segment=dhan.MCX,transaction_type=dhan.BUY,quantity=1,order_type=dhan.MARKET,product_type=dhan.INTRA,price=0)# Place Slice Orderdhan.place_slice_order(security_id='52175',#NiftyPEexchange_segment=dhan.NSE_FNO,transaction_type=dhan.BUY,quantity=2000,#nifty freeze quantity is 1800order_type=dhan.MARKET,product_type=dhan.INTRA,price=0)# Place MTF Orderdhan.place_order(security_id='1333',#hdfcbankexchange_segment=dhan.NSE,transaction_type=dhan.BUY,quantity=100,order_type=dhan.MARKET,product_type=dhan.MTF,price=0)# Fetch all ordersdhan.get_order_list()# Get order by iddhan.get_order_by_id(order_id)# modify orderdhan.modify_order(order_id,order_type,leg_name,quantity,price,trigger_price,disclosed_quantity,validity)# Cancel orderdhan.cancel_order(order_id)# Get order by correlation iddhan.get_order_by_corelationID(corelationID)# Get positionsdhan.get_positions()# Get holdingsdhan.get_holdings()# Intraday Minute Datadhan.intraday_minute_data(security_id,exchange_segment,instrument_type)# Historical Daily Datadhan.historical_daily_data(symbol,exchange_segment,instrument_type,expiry_code,from_date,to_date)# Time Converterdhan.convert_to_date_time(JulianDate)# Get trade bookdhan.get_trade_book(order_id)# Get trade historydhan.get_trade_history(from_date,to_date,page_number=0)# Get fund limitsdhan.get_fund_limits()# Generate TPINdhan.generate_tpin()# Enter TPIN in Formdhan.open_browser_for_tpin(isin='INE00IN01015',qty=1,exchange='NSE')# EDIS Status and Inquirydhan.edis_inquiry()Market Feed Usagefromdhanhqimportmarketfeed# Add your Dhan Client ID and Access Tokenclient_id="Dhan Client ID"access_token="Access Token"# Structure for subscribing is ("exchange_segment","security_id")# Maximum 100 instruments can be subscribed, then use 'subscribe_symbols' functioninstruments=[(1,"1333"),(0,"13")]# Type of data subscriptionsubscription_code=marketfeed.Ticker# Ticker - Ticker Data# Quote - Quote Data# Depth - Market Depthasyncdefon_connect(instance):print("Connected to websocket")asyncdefon_message(instance,message):print("Received:",message)print("Subscription code :"subscription_code)feed=marketfeed.DhanFeed(client_id,access_token,instrumentssubscription_codeon_connect=on_connect,on_message=on_message)feed.run_forever()ChangelogCheck release notes