-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot log in #32
Comments
If you log in via the Trading View website, do you have to fill in a Google Captcha? If so, this is the problem when logging in with this library. In my fork of this library I persist the token on the file system and load it when using it. So you could take the token from the login request on the Trading View website and save it in token.txt and use the library again. Or you can wait a few days, login via webrowser and hopefully the Google Captcha is gone. |
@liebig I'm experiencing the same issue. Can you provide more info on how to find the token? |
See Pull Request (#29) for a method to login |
@liebig I am still having issue logging in. Can you elaborate on it? |
@traderjoe1968 I installed your commit, however the problem persist. Could you help out? |
Have a look here: liebig@873713a#commitcomment-137518936 |
@liebig thank you, I followed those steps and save Could you guide me on this? |
Ensure you create the 'TvDataFeed' object correctly. I just tested it at mine end - still works. If it does not work check you 2FA is synchronised with TradingView. Log out of TradingView website and re-login. It should ask you for your 2FA code. # get credentials for tradingview
username = "your username"
password = "your password"
# initialize tradingview
tv = TvDatafeed(username=username, password=password, pro=True) here is example code to use import os
import pandas as pd
from datetime import datetime as dt
from pathlib import Path
from tvDatafeed import TvDatafeed, Interval
import logging
logging.basicConfig(
level=logging.INFO,
format="%(message)s",
handlers=[
logging.FileHandler(f"tvdata.log", mode="w"),
logging.StreamHandler(),
],
)
dataPath = r"Data"
# If no such folder exists, create an empty folder
if not os.path.exists(dataPath):
os.mkdir(dataPath)
logging.info(f"creating Directory {dataPath}")
def downloadData(Sym, Exchange):
try:
df = tv.get_hist(
Sym, Exchange, Interval.in_5_minute, n_bars=5000, extended_session=True
)
except Exception:
logging.exception("TvDataFeed Error")
raise
df.insert(0, "date", df.index.date)
df.insert(1, "time", df.index.time)
df.reset_index(inplace=True)
del df["datetime"]
del df["symbol"]
return df
# get credentials for tradingview
username = "your username"
password = "your password"
# initialize tradingview
tv = TvDatafeed(username=username, password=password, pro=True)
if __name__ == "__main__":
symList = [
("SPY", "AMEX"),
]
logging.info("Starting import...")
try:
for i, sym in enumerate(symList):
logging.info(f"Processing {sym}")
info = tv.search_symbol(sym[0], sym[1])
try:
data = downloadData(sym[0], sym[1])
except Exception:
continue
filename = os.path.join(dataPath, sym[0] + ".csv")
logging.info(f"Writing {filename}")
data.to_csv(
filename,
columns=[
"date",
"time",
"open",
"high",
"low",
"close",
"volume",
],
index=False,
)
logging.info("Finished Import")
except Exception:
logging.exception() |
@traderjoe1968 My 2FA is off
After removing |
Then you have not incorporated PR into your code correctly
You need PR #30
You can clone my fork - pip install git+https://github.com/traderjoe1968/tvdatafeed.git@ProData
|
@traderjoe1968 yeah, I just updated main.py with first commit of 2fa, not the other 3 commits. I updated the main.py with the latest commit, still unable to login. I also cloned your repo link, and it gives the same error as well. |
Back to checking you TradingView profile and settings If a) & b) are good then try demo code above and see if you can debug and get why it is failing - look at response coming back in I know the code works for me and others - so not much else I can do to help |
A.) Yes, I have a "Plus" subscription. |
The original code assumed you would get a token back. See original code in main.py. So if you are still not able to login without a putting in a 2FA code then it seems the TradingView requires it. If you just want to get it working then setup 2FA app - follow instructions on TradingView. It should then work ? def __auth(self, username, password):
...
...
if "2FA_required" in response.text:
response = s.post(url=self.__sign_in_totp, data={"code": self.__getcode()}, headers=self.__signin_headers)
token = response.json()['user']['auth_token']
with open(tokendata, 'w') as f:
f.write(token)
...
... |
@traderjoe1968 When I print
I believe @liebig solved it and explained it here, however even when I extract the I don't think setting up 2FA will help? Anyway I will try it. |
If you have the token string just create the file with a text editor in |
@traderjoe1968 I did that and I was getting the error:
I commented out the delete section for now as it was just deleting the token, then I am getting the error: |
The reason your file is being deleted is because it is not a valid token for the connection - if the code fails to log into TrandingView then it assume the token is no longer valid and asks you to log in again. Did you setup 2FA and test it by logging out and in multiple times by logging in via web browser !! If you don't get the enter code box then it's not setup properly This is real simple code - do some debugging
tokendata = Path(user_data_dir(appname="tvdata", appauthor=""), "token.2fa")
tokendata.parent.mkdir(parents=True, exist_ok=True)
if "2FA_required" in response.text:
response = s.post(url=self.__sign_in_totp, data={"code": self.__getcode()}, headers=self.__signin_headers)
token = response.json()['user']['auth_token']
with open(tokendata, 'w') as f:
f.write(token)
else:
token = response.json()['user']['auth_token']
IF you get "code":"recaptcha_required" in response text then you will need to wait until the timeout period for captcha. You can try again the "@liebig solved it and explained it here," process but I am not sure it will work as the token is unique to each application that connects in (I don't think you can take the web browser token and use it with python script - I could be wrong) There is no more I can help you with - please just debug this yourself. If you find that there are improvements / workarounds etc add to the PR or raise another PR |
@traderjoe1968 Sure, I'll will be debugging this. Thank you so much for all the help, patience and time. I'll try with 2FA and see how it goes! |
|
Hi,
it seems like the libarary needs to be udpated. I get the following error when trying to log in:
error while signin
you are using nologin method, data you access may be limited
Thanks!
The text was updated successfully, but these errors were encountered: