Hi @Kishore007
session 10 code files:
Hi @Kishore007
session 10 code files:
Hi @Tradehull_Imran
I wrote a standalone program to test it then, Im NOT calling it in loop to have to add a time.sleep. I just called it once in seperate program and it returns empty dictionary. As you can see below in the output, IT IS THE FIRST THING BEING CALLED AFTER “logged into dhan”, “Got instrument file” etc. How would it makes sense to use time.sleep then. I think you guys changed something in the tsl code or something without informing and hence its breaking
Output:
-----Logged into Dhan-----
reading existing file all_instrument 2024-11-29.csv
Got the instrument file
getting ltp … [‘NIFTY 05 DEC 24300 PUT’]
NIFTY 05 DEC 24300 PUT
{}
Updated the code files for Seession 5 and Session 10.
Thats the end folks - we are thinking of doing a live webinar with @Tradehull_Imran this week - what all things would you like us to cover - let know in the comments below.
Hi @Tradehull_Imran,
I am talking about this:
because of this:
You can establish upto five WebSocket connections per user with 5000 instruments on each connection.
I am working on something which works on realtime intraday data and sometimes API rate limit creates issue so to resolve that I was thinking using Live Market feed.
When we restart everything is fresh for it. Ideally algo should not be restarted.
But in case you want to save the variables, you can connect it to excel, and sore latest traded value there itelf.
use below code
do create a .xlsx file named trades_info in the folder in which code is running
import xlwings as xw
workbook = xw.Book('trades_info.xlsx')
sheet = workbook.sheets['Sheet1']
sheet.range('A1').value = 'yes_traded'
Hi @Msk92
do share the complete code folder, and share the output for “pip show dhanhq” as well.
do remove api credentials.
Hi @Aijaz_Ahmad
This is webscokets code,
see session 3 : https://youtu.be/DPWU5wLuYcQ?si=w3vcmhDPLeN2jTPq
use code files : Dhan_websocket_v2.py - Google Drive
@RahulDeshpande
@Tradehull_Imran
I am heartly interested in this webinar
Hi @Tradehull_Imran,
I’ve checked it by introducing sleep(1) between consecutive calls as you have suggested. However, I’m still getting the below errors. Unable to figure out where its going wrong.
1. Exception at calling ltp as {'status': 'failure', 'remarks': {'error_code': None, 'error_type': None, 'error_message': None}, 'data': {'data': {'805': 'Too many requests. Further requests may result in the user being blocked.'}, 'status': 'failed'}}
2. Traceback (most recent call last):
File "C:\Users/krish/OneDrive/Documents/Krishna/DhanAlgoTrading/Required Files\Dhan_Tradehull_V2.py", line 493, in ATM_Strike_Selection
ltp = ltp_data[Underlying]
~~~~~~~~^^^^^^^^^^^^
KeyError: 'NIFTY' ```
Hi Tradehull_Imran,
I am rpnemade ( Ramaji Nemade)
please resolve the error
Code is as follow.
============
import pdb
import time
import datetime
import traceback
import talib
from Dhan_Tradehull import Tradehull
import pandas as pd
client_code = "1105367739"
token_id = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiIiwiZXhwIjoxNzM1NjQxNjExLCJ0b2tlbkNvbnN1bWVyVHlwZSI6IlNFTEYiLCJ3ZWJob29rVXJsIjoiIiwiZGhhbkNsaWVudElkIjoiMTEwNTM2NzczOSJ9.k1EtN8wRFDj3mM6XgEB0W-NDt21YvqVy-GHHXb3AKZSF4l6MlcCIEl1F1zW1FFlFuqMxOcwdm6Kf5WQWj6xudA"
tsl = Tradehull(client_code,token_id) # tradehull_support_library
available_balance = tsl.get_balance()
max_risk_for_the_day = (available_balance*1)/100*-1
print("available_balance", available_balance)
ltp1 = tsl.get_ltp('ACC')
ltp2 = tsl.get_ltp('NIFTY')
print(ltp1,ltp2)
previous_hist_data = tsl.get_historical_data('CIPLA','NSE',12)
print(previous_hist_data)
pdb.set_trace()
# previous_hist_data = tsl.get_historical_data('ACC','NSE',12)
# intraday_hist_data = tsl.get_intraday_data('ACC','NSE',1)
# ce_name, pe_name, strike = tsl.ATM_Strike_Selection('NIFTY','05-09-2024')
# otm_ce_name, pe_name, ce_OTM_strike, pe_OTM_strike = tsl.OTM_Strike_Selection('NIFTY','05-09-2024',3)
# ce_name, pe_name, ce_ITM_strike, pe_ITM_strike = tsl.ITM_Strike_Selection('NIFTY','05-09-2024', 4)
# intraday_hist_data = tsl.get_intraday_data(otm_ce_name,'NFO',1)
# intraday_hist_data['rsi'] = talib.RSI(intraday_hist_data['close'], timeperiod=14)
# lot_size = tsl.get_lot_size('NIFTY 29 AUG 24500 CALL')
# lot_size = tsl.get_lot_size(otm_ce_name)
# qty = 2*lot_size
# # next lecture
# orderid1 = tsl.order_placement('NIFTY 29 AUG 24500 CALL','NFO',25, 0.05, 0, 'LIMIT', 'BUY', 'MIS')
# orderid2 = tsl.order_placement('BANKNIFTY 28 AUG 51600 CALL','NFO',15, 0.05, 0, 'LIMIT', 'BUY', 'MIS')
# orderid3 = tsl.order_placement('ACC','NSE', 1, 0, 0, 'MARKET', 'BUY', 'MIS')
# exit_all = tsl.cancel_all_orders()
=============================
Error message :slight_smile:
===================================
C:\Users\Mr. Ramji Nemade\Desktop\RPN\Session 3\Dhan codebase>py Dhan_codebase_usage.py
-----Logged into Dhan-----
reading existing file all_instrument 2024-12-03.csv
Got the instrument file
available_balance 4511.18
2300.3 24410.5
DataFrame constructor not properly called!
Traceback (most recent call last):
File "C:\Users\Mr. Ramji Nemade\Desktop\RPN\Session 3\Dhan codebase\Dhan_Tradehull.py", line 222, in get_historical_data
df = pd.DataFrame(ohlc['data'])
File "C:\Users\Mr. Ramji Nemade\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py", line 817, in __init__
raise ValueError("DataFrame constructor not properly called!")
ValueError: DataFrame constructor not properly called!
None
--Return--
[0] > ←[33;01mc:\users\mr. ramji nemade\desktop\rpn\session 3\dhan codebase\dhan_codebase_usage.py←[00m(←[36;01m29←[00m)<module>()->None
-> pdb.set_trace()
(Pdb++)
# live_pnl = tsl.get_live_pnl()
# if live_pnl < max_risk_for_the_day:
# exit_all = tsl.cancel_all_orders()
# response = tsl.kill_switch('ON')
Hi @Tradehull_Imran,
This works but the only problem is it uses excel to fetch the data for the stocks mentioned in the excel, but what I want is that the code should fetch data for the watchlist using websocket method without using excel.
Reason,
Before the main code was ran, did you do any kind code testing , it may be that there the rate limits was breached there and when the main code was ran it got rate limit issues
It maybe so that the api_keys you are using compromised, try running the same algo with a new regenerated key tomorrow , and do delete the old key
Also for testing do block live pnl code
if rate limits are still not fixed, we would need some more help from @Hardik in this case.
Hi @Tradehull_Imran, Thank you for the revert.
Regarding point 1, i did not run any other code before this code.
I’ll check point 2 and 3 tomorrow and let you know if it worked
Thank you
Hi @rpnemade
The Historical api call is upgraded
do check this solution link : Learn Algo Trading with Python | Codes | Youtube Series - #952 by Tradehull_Imran
Hi @Aijaz_Ahmad
This would require WebSocket code modifications, will update you on this.
Also Excel on server is anyways required, as it works as a user interface for algos.
Hi @Tradehull_Imran,
Today my algo executed from 9:15am to 3:01pm successfully (not a single error, SL/Target orders and Trailing SL worked perfectly).
Thanks for your guidance and support. it was wonderful learning journey with you.
-Rahul
hello @Tradehull_Imran ,
can this code work of 2nd , 3rd, 4th live algo automatically run throughout the trading session of that day once started at 9:!5 am ?
for example, i mean does this algos automatically scan and put trades when the conditions on technical indicators meets even at10am if we run it on 9:15 am ? or we have to run the code again at 10am ?
“ Heart of Algo Trading : Backtesting”
Very much interested in the cloud deployment as well as Back testing Algo.
Hello sir @Tradehull_Imran
code runing fine and sudenly one error massege (Too many requests on server from single user breaching rate limits. Try throttling API calls)…and code stop
please help
@Tradehull_Imran, I am getting ERROR: “Illegal instruction (core dumped)” while running any function. Please lead my way to the solution.
I am using VScode on linux. I created virtual environment and installed all the required packages.
Sample code :
from Dhan_Tradehull import Tradehull
from credentials import client_id, access_token
tsl = Tradehull(client_id, access_token)
available_balance = tsl.get_balance()
print(available_balance)
Thanks for the very informative algo series. After watching all the videos I think I can make the algo too.