algo2t / alphatrade

Python APIs for SAS Online Alpha Trade Web platform for creating algo trading using python
https://algo2t.github.io/alphatrade
MIT License
45 stars 25 forks source link

Unable to generate access token #46

Closed mrsprawin closed 1 year ago

mrsprawin commented 1 year ago

Giving this Error:

HTTPError Traceback (most recent call last) Input In [14], in <cell line: 10>() 7 totp = f"{int(pin):06d}" if len(pin) <=5 else pin
8 print(config.access_token) ---> 10 sas = AlphaTrade(login_id=config.login_id, password=config.password, twofa=totp, access_token=config.access_token) 11 socket_opened = False 12 def event_handler_quote_update(message):

File ~/opt/anaconda3/lib/python3.9/site-packages/alphatrade/alphatrade.py:240, in AlphaTrade.init(self, login_id, password, twofa, access_token, master_contracts_to_download) 238 if not self.is_token_valid(): 239 self.get_question_ids() --> 240 self.set_access_token() 241 else: 242 self.headers['X-Authorization-Token'] = self.__access_token

File ~/opt/anaconda3/lib/python3.9/site-packages/alphatrade/alphatrade.py:309, in AlphaTrade.__set_access_token(self) 306 response = self.reqsession.post( 307 'https://alpha.sasonline.in/api/v2/checktwofa', json=twofa_body) 308 if response.status_code != 200: --> 309 raise requests.HTTPError(response.text) 310 if 'error' in response.text: 311 raise requests.HTTPError(response.text)

HTTPError: {"errors":{"detail":"Internal server error"}}

I think it is still asking for old format of twofa password which is not part of latest config file. How to avoid this error?

mrsprawin commented 1 year ago
Screenshot 2022-11-14 at 12 02 55 PM
ronaldpaul commented 1 year ago

Hi @mrsprawin, through the latest update for TOTP, should we enter the TOTP everyday in the configuration file or it will automatically do it as earlier? Because today it was sending OTP to my mobile since I am using the existing library and not the latest update (done 7 days ago) with the TOTP code. How do I update it?

Thanks

mrsprawin commented 1 year ago

remove your account from authenticator app and Copy the Code key from the website

Screenshot 2022-11-14 at 1 23 20 PM

's the QR code prompt before scanning the QR Code.

nevatia commented 1 year ago

You dont seem to have/had access_token.txt file. Create one.

yogeshdewangan commented 1 year ago

I am also getting below error

Traceback (most recent call last): File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "E:\MyProjects\alphatrade_intraday\symbol_price.py", line 3, in import sas_live_feed File "E:\MyProjects\alphatrade_intraday\sas_live_feed.py", line 25, in sas = AlphaTrade(login_id=login_id, password=password, twofa=tot, access_token=access_token) File "E:\MyProjects\alphatrade_intraday\venv\lib\site-packages\alphatrade\alphatrade.py", line 240, in init self.__set_access_token() File "E:\MyProjects\alphatrade_intraday\venv\lib\site-packages\alphatrade\alphatrade.py", line 309, in __set_access_token raise requests.HTTPError(response.text) requests.exceptions.HTTPError: {"errors":{"detail":"Internal server error"}}

I have already created access_token.txt file. Please help.

algo2t commented 1 year ago

This is fixed with the new version v1.0.0, pip install -U alphatrade Take a look at the updated README