0xrushi / tradingview-scraper

MIT License
328 stars 105 forks source link

Create Study #6

Open Gbrtenorio opened 3 years ago

Gbrtenorio commented 3 years ago

Hello, your python script is very useful and robust! But how do you select a specific study by inspecting the tradingview webpage? I would like to scrap from the SuperTrend indicator (by KivancOzbilgic)

I see that you are scrapping volume information from "" sendMessage(ws, "create_study", [chart_session,"st1","st1","s1","Volume@tv-basicstudies-118",{"length":20,"col_prev_close":"false"}]) ""

Thank you very much! supertrend

euvgub commented 3 years ago

SuperTrend by KivancOzbilgic ~m~1483~m~{"m":"create_study","p":["cs_fIIsHMXKVzB7","st8","st1","s1","Script@tv-scripting-101!",{"text":"WEVWraRmbLWZptpn+HpmoA==_ARZ8r6dJpu7GqgGZTjfBss4kMzcGjsQ3xIdIMxHCEd3BKY8jQVVBkmdbDJfGouR/o8yF2rNRLtmdT1ZIrZDlhcmEYl1vkoE68qTsX7+Nv5El6A7TR20M+CsG6C6Lpx5n0l3v6HSN3Enfeys2xVskaIPWt6Go2ni7miDFUIbneX/4dZCYKxQkx+p6xF56+Jm7MCwOfmSCi6BCGUzDKTU0oyxlwVCotvRAvdRhdNHsz7VsCGu4SEgnxdiHLIlZEOCsSoW8edwj8leclzAtciLylDR1YeVGOsZkpDCCqeJBtXaiMwCAMIso4R1HuIhMwEFUIW4M9LhFO3IS9QBqQ+aPBGXROuQhc3gK2vltU/S7dzjGr0n3x51GFtjPdcblnjmX9naEAa1taJ226oKnPWyfFE8Sv8pVyEJfRetv2rUD6Wi4NZ6mLnr0hYc+FrxjGZW7A5+7PXyNUzjvBOfBlLqdXHKU/luzZeSE/iBDilZMgH/LHcs/igQV8uljoIw8elf9z6XFEMT6l8wbGs4FCIrbJ6tPza1Mq3IzI7/9WBLlKa5AARPakyAcVXd019Scj+kdGhpopuhXnIC0TbXXbUGK3VKsPu/S9UpvqBglsMXGl2SCoLMrTZftbwEUZbJDq8s4vt7EOJp69asIz4fGgY7SqULh9ZH+jwTcIwqaqHTwHmivdRlSTFWPJK4VF3f7xkO02+Z1lgNOPozo7Lo2jRkmZBzRn0pwZZ9g5JVDdUGevoOQrmQO+v5YobSd5V83yY0eIPERjdQa/rHQ6VI44AcJZVFGD3qaIOj1zsYZv0dnRtLitc1SokfjlLIeh8iaX/JUsgnW2KwXoCEn/CE1cNVDGBXGcDmH2+CKbGmLzKHWLEP3PEceA7S+daYfb3d1rWx9hNQjqPY/GvFmJdhWkucGPHQT3n8ulY+MwD7CJYogIiAsThkTJL2hjJmwOLftUm5bLOTnd5vBeiQMhMwMyLZB+UTbixOsqMM7HdpS58HEU9lT8TlHhaXyFiNF3WFBeJ5xCm4ja/joeW0Db8kDoBtFbqHPStO5pMr0OQ==","pineId":"PUB;VfOPXWDHDPhORvJYRTcuHOyeqpOcRR45","pineVersion":"2.0","in_0":{"v":10,"f":true,"t":"integer"},"in_1":{"v":"hl2","f":true,"t":"source"},"in_2":{"v":3,"f":true,"t":"float"},"in_3":{"v":true,"f":true,"t":"bool"},"in_4":{"v":true,"f":true,"t":"bool"},"in_5":{"v":true,"f":true,"t":"bool"}}]}

hariprasad90 commented 3 years ago

can you help me , it is not working

slukin1 commented 3 years ago

sendMessage(ws, "create_study", [chart_session,"st4","st1","s1","Script@tv-scripting-101!",{"text":"WEVWraRmbLWZptpn+HpmoA==_ARZ8r6dJpu7GqgGZTjfBss4kMzcGjsQ3xIdIMxHCEd3BKY8jQVVBkmdbDJfGouR/o8yF2rNRLtmdT1ZIrZDlhcmEYl1vkoE68qTsX7+Nv5El6A7TR20M+CsG6C6Lpx5n0l3v6HSN3Enfeys2xVskaIPWt6Go2ni7miDFUIbneX/4dZCYKxQkx+p6xF56+Jm7MCwOfmSCi6BCGUzDKTU0oyxlwVCotvRAvdRhdNHsz7VsCGu4SEgnxdiHLIlZEOCsSoW8edwj8leclzAtciLylDR1YeVGOsZkpDCCqeJBtXaiMwCAMIso4R1HuIhMwEFUIW4M9LhFO3IS9QBqQ+aPBGXROuQhc3gK2vltU/S7dzjGr0n3x51GFtjPdcblnjmX9naEAa1taJ226oKnPWyfFE8Sv8pVyEJfRetv2rUD6Wi4NZ6mLnr0hYc+FrxjGZW7A5+7PXyNUzjvBOfBlLqdXHKU/luzZeSE/iBDilZMgH/LHcs/igQV8uljoIw8elf9z6XFEMT6l8wbGs4FCIrbJ6tPza1Mq3IzI7/9WBLlKa5AARPakyAcVXd019Scj+kdGhpopuhXnIC0TbXXbUGK3VKsPu/S9UpvqBglsMXGl2SCoLMrTZftbwEUZbJDq8s4vt7EOJp69asIz4fGgY7SqULh9ZH+jwTcIwqaqHTwHmivdRlSTFWPJK4VF3f7xkO02+Z1lgNOPozo7Lo2jRkmZBzRn0pwZZ9g5JVDdUGevoOQrmQO+v5YobSd5V83yY0eIPERjdQa/rHQ6VI44AcJZVFGD3qaIOj1zsYZv0dnRtLitc1SokfjlLIeh8iaX/JUsgnW2KwXoCEn/CE1cNVDGBXGcDmH2+CKbGmLzKHWLEP3PEceA7S+daYfb3d1rWx9hNQjqPY/GvFmJdhWkucGPHQT3n8ulY+MwD7CJYogIiAsThkTJL2hjJmwOLftUm5bLOTnd5vBeiQMhMwMyLZB+UTbixOsqMM7HdpS58HEU9lT8TlHhaXyFiNF3WFBeJ5xCm4ja/joeW0Db8kDoBtFbqHPStO5pMr0OQ==","pineId":"PUB;VfOPXWDHDPhORvJYRTcuHOyeqpOcRR45","pineId":"PUB;VfOPXWDHDPhORvJYRTcuHOyeqpOcRR45","pineVersion":"2.0","in_0":{"v":10,"f":true,"t":"integer"},"in_1":{"v":"hl2","f":true,"t":"source"},"in_2":{"v":3,"f":true,"t":"float"},"in_3":{"v":true,"f":true,"t":"bool"},"in_4":{"v":true,"f":true,"t":"bool"},"in_5":{"v":true,"f":true,"t":"bool"}}])

na81cho commented 3 years ago

hola como se puede extraer el rsi de una accion o ticker ?

euvgub commented 3 years ago

RSI sendMessage(ws, "create_study", [chart_session,"st1","st1","s1","Script@tv-scripting-101!",{"text":"1f0fkZ72S0de2geyaUhXXw==_xwY73vljRXeew69Rl27RumLDs6aJ9NLsTYN9Xrht254BTb8uSOgccpLDt/cdRWopwJPNZx40m19yEFwJFswkSi62X4guNJYpXe4A6S9iq2n+OXM6mqWeWzDbjTl0lYmEf1ujbg7i3FvUdV/zCSrqd+iwnvvZSV+O2acpfNLpUlDdB6PZX4Y9y8tlQLWA2PiF8CVJng7DF1LPeecWC4fv+lNg+s5OXU46AjIhc+TFu8DOwiuKjNh7wWz6EZ7gpQS3","pineId":"STD;RSI","pineVersion":"12.0","in_2":{"v":"","f":True,"t":"resolution"},"in_0":{"v":14,"f":True,"t":"integer"},"in_1":{"v":"close","f":True,"t":"source"}}])

rodionlim commented 3 years ago

@euvgub, Thanks for the last reply, it works very well. Is the text param a hardcoded value or is there a way to dynamically generate that value?

euvgub commented 3 years ago

With the Chrome Dev Tools, you can see the WebSocket traffic coming to and going from your browser at https://www.tradingview.com/chart/xxx_your_chart_xxx/ during adding indicator (RSI for example) ~m~636~m~{"m":"create_study","p":["cs_Your_session_name","st1","st1","sds_1","Script@tv-scripting-101!",{"text":"SwpjA8ZvTfm3QzYV4SHlGQ==_fBphOqdJtCV9RSOZQgTZR26ciPAXfb4AyW7Aw9xpSMMXHfUD9LkZNZd2XNEdiXtEA+iiy/2T83TWfyL4ik8Zehob/gN+KrG1pgARlwFeY3qCBYCfB/iHWS1S/n3ascBswxEtQkVz89w58exKoK9sm6ZZXYN3h3xRpgCOduqjTZctqkqpskurbUQWaCol6fWKHwo68SaLKFQf8CyFc1tDaX8Icp89p1k0VFQtHm1NYdIdEGLETcaTlyWz2Gl6yaazMCZrU3nFLWgqktLUSpUpL+nVTQ5NtusEODMPPWzmjtCfCcdPZBAn7KI4YCwWC+YhCCTh05t/w7T1la6NcEHXorpi","pineId":"STD;RSI","pineVersion":"20.0","in_2":{"v":"","f":true,"t":"resolution"},"in_0":{"v":14,"f":true,"t":"integer"},"in_1":{"v":"close","f":true,"t":"source"}}]}

or You can get indicator text value with xpath at https://www.tradingview.com/chart/xxx_your_chart_xxx/ "//script[contains(.,"initData.content")]/text()" tttt = xpath_script_value.split("initData.content = ")[-1].split("initData.defSymbol")[0].replace("}]};","}]}") t=json.loads(tttt) print(t['charts'][0]['panes'][3]['sources'][0]['state']['inputs']['text'])

rodionlim commented 3 years ago

Thanks euvgub, I understand that text param was grabbed from monitoring the WebSocket traffic. I was wondering if there was a dynamic way to re-create that value, similar to how this repository generates the chart session ID, instead of copying the hardcoded values?

euvgub commented 3 years ago

start point to re-create that value https://pine-facade.tradingview.com/pine-facade/get/STD%3BRSI/20.0 https://pine-facade.tradingview.com/pine-facade/translate/STD%3BRSI/20.0/

euvgub commented 3 years ago

trying to find pine script - > create_study "text" attribute translation method in https://www.tradingview.com/static/bundles/ js files xxxxxxxx.js

euvgub commented 3 years ago

pine code source translation for create_study somewhere here: https://www.tradingview.com/static/bundles/main_chart.[unique file name?].js ... c.PINE_FACADE_URL=function(){return window.PINE_URL} ... return c._pineFacadeAjax("POST","/convert/",i).done((function(e,i,n){e.error? ... (u+=l),c._pineFacadeAjax("GET",u,void 0,n).done((function(e,n,r){if(c._translateScriptAsyncDone(i,e) ...

miadz commented 3 years ago

hi how can get more data ? i use this sendMessage(ws, "request_more_data", [chart_session, "sds_2", 500]) but not worked

euvgub commented 3 years ago

hi, try to debug in browser dev tools-websocket what`s Your variable name instead of "sds_2" at 'create_series' step for example '~m~76~m~{"m":"create_series","p":["cs_A81hNsYTGtqz","s1","s1","symbol_1","5",10000]}' here variable name is "s1"

miadz commented 3 years ago

thank you , I solve it .

madanmohan0507 commented 1 year ago

Hi, I tried getting the data of RSI through create_study method but the server responded with "Study not allowed in this connection" error. Does anyone know how to fix it? Thanks

slukin1 commented 1 year ago

just change this line in client from wss://${server}.tradingview.com/socket.io/websocket to wss://${server}.tradingview.com/socket.io/websocket?&type=chart source https://github.com/Mathieu2301/TradingView-API/issues/182

madanmohan0507 commented 1 year ago

@slukin1 Thank you so much. It worked! :)

madanmohan0507 commented 1 year ago

Could someone please explain why these strings work because the messages that I am sending on my browser are different and there is an error when I try sending the same message through code that the browser is sending. Also, can anyone tell me how to get other indicators or like sub parts of indicators (like data of K-line of RSI). Thanks

slukin1 commented 1 year ago

study processing logic in js files https://static.tradingview.com/static/bundles/xxx.yyyyy.js

madanmohan0507 commented 1 year ago

The link is showing "This isn't the page you're looking for" :(

slukin1 commented 1 year ago

xxx.yyyy different for every user. browser - developer tools - reload - tab Network - js files. Add other indicators - tab Network - websocket - search websocket message with study string. Or save all as har file and search for study string

madanmohan0507 commented 1 year ago

Okay. Thank you once again. :) And sorry for such stupid questions, I am very new to this. :/

slukin1 commented 1 year ago

first steps questions not equal stupid questions

madanmohan0507 commented 1 year ago

@slukin1 I copied the study string from websocket and ran the code and it showed cannot parse pine error. Any idea why this is happening?

slukin1 commented 1 year ago

sendMessage(ws, "create_study", [chart_session,"xxx","yyy","zz","Script@tv-scripting-101!",{"text":"yoursudystring","pineId":"PUB;youdata","pineId":"PUB;yourdata2","pineVersion":"2.0","in_0":{"v":10,"f":true,"t":"integer"},"in_1":{"v":"hl2","f":true,"t":"source"},"in_2":{"v":3,"f":true,"t":"float"},"in_3":{"v":true,"f":true,"t":"bool"},"in_4":{"v":true,"f":true,"t":"bool"},"in_5":{"v":true,"f":true,"t":"bool"}}])

copy exact message from websocket and past all data of study including study parameters like in_1, in_2,in_3 (your keys`ll be different)

slukin1 commented 1 year ago

example of message in websocket ~m~1880~m~{"m":"create_study","p":["cs_q7qq7EXZjvcI","st7","st1","sds_1","Script@tv-scripting-101!",{"text":"bmI9Ks46_i0/H8fJm/OvjhXV1u68/kg==_42Foz2xVJWH1U9Kcf4Pt2KMghlpyA7KxkxEbOWwZeDcRzi9qVOFMCqXut7MrmwaE+clvDynY/fuMZS9OLPhTWB/j9e6aXIE7MoUf03Fev5PU/ESLpWLhny/gdby+78zLduWvuKnFLWbLbVh1AboV5j7ZhQxBfhHQWTmtNu5hSSyHUGEkBd6i3mHQo+1lCAuw1kDmVeEmnc0/WxcgcOyr6y0hOvx2+kChpwj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XIxqZiy7W8mG0bpnf8A+s=","pineId":"PUB;40","pineVersion":"-1.0","in_0":{"v":true,"f":true,"t":"bool"},"in_1":{"v":"60","f":true,"t":"resolution"},"in_2":{"v":true,"f":true,"t":"bool"},"in_3":{"v":true,"f":true,"t":"bool"},"in_4":{"v":true,"f":true,"t":"bool"},"in_5":{"v":true,"f":true,"t":"bool"},"in_6":{"v":true,"f":true,"t":"bool"},"in_7":{"v":12,"f":true,"t":"integer"},"in_8":{"v":26,"f":true,"t":"integer"},"in_9":{"v":9,"f":true,"t":"integer"}}]}

example what to send from this websocket message:

sendMessage(ws, "create_study",["cs_q7qq7EXZjvcI","st7","st1","sds_1","Script@tv-scripting-101!",{"text":"bmI9Ks46_i0/H8fJm/OvjhXV1u68/kg==_42Foz2xVJWH1U9Kcf4Pt2KMghlpyA7KxkxEbOWwZeDcRzi9qVOFMCqXut7MrmwaE+clvDynY/fuMZS9OLPhTWB/j9e6aXIE7MoUf03Fev5PU/ESLpWLhny/gdby+78zLduWvuKnFLWbLbVh1AboV5j7ZhQxBfhHQWTmtNu5hSSyHUGEkBd6i3mHQo+1lCAuw1kDmVeEmnc0/WxcgcOyr6y0hOvx2+kChpwjE9pA72FATdn3+7nC6TpyDXtaMVlNs/ECHetIp4dLUSShM3K4zgwFXc+J8mYgb8+JnCBoTjBPZ08T8mB3Ni8ZnZjBqxvuC4IGnFtNv5zRlrksr35gH5/1nbAZmFgfJ6754NxE9aIGXvZtOnILH4B1rtwRGdIAwAH9KdZBKtacJLsKyPHS4VVTmIg6BilaifKKQIa7NoZWTV8VzR4pya4ku1VEy/Tz/EIDOxl9lKc9Ewr0cPzIfE1zMcbHBX+83Ppj84N/BFuXaM1Ohc9rmsfPl2rm27NQbUn3UVVy3DIqiaLIp4ZBi4Ku4Rqmsgw5UZmGe8PygI/eiEcBn7QZUm2zWsyU8wDE+MIyRdiI2MpsdONednuCiqY49tJno3jOMdsDDQwnPeqjVASbTZ0CthCZbxfLmfte8eXFK3iv09pbQjs45xd0WH7Ycye5O+Q+r0Z7jtRS7wkcaxzashdW+fCyyF9KIVdEkffv3YghSqF+Yfn3kqYwXh0CgN/eZ77SGmxAu/FuwwbyFifTK9EAthNSXEy+H8cZD3yubAuLEtzOaPF2EX5zaxZYQMZRddZar6QpRfKuKXF7Ha65URb1JZCGDXlbGxbkzAKDxY1PjdOFN9HD8YlTr4TOESV1sNykzd4IDx1hK2chU2VUgn99vQbFN/RV767Rc3ZH8J1Tm2Z8ogCfiQnvmZZtnSryHeERVlSnAyyBbO83IYTv0zBiK6wnq9JvrMcW1qG1xx5aeUDZ/3i6tZTUG09QouUbYVry3kahS5Pu3wnlE4d0ERboj/T+WtAmTwO++YsUV0o3RoO7dpSgfkhIdEtZqWOPY2Wpu7P+3+ebhAdlAzcWGqWFLd7dttF9bvZN1y+YzpuxAkZtr3zYvmzvpM6SjFIQs9ijfDfKXIqvRSQOiGsipR7aNjRMeD0enC6bUHy+wR//KF/hIBAP804/Zyf0Ur31u9t6WOeU3nurlr651k4hMIIXET/faFAsTkpkUPNCmqgcAQyJI5Fr3eUdV8ZkxipNPQjjVgfuzPqPCRwDYnU3QCRbO3f23NPf8i0L+KCVx17HezeUiTNXIxqZiy7W8mG0bpnf8A+s=","pineId":"PUB;40","pineVersion":"-1.0","in_0":{"v":true,"f":true,"t":"bool"},"in_1":{"v":"60","f":true,"t":"resolution"},"in_2":{"v":true,"f":true,"t":"bool"},"in_3":{"v":true,"f":true,"t":"bool"},"in_4":{"v":true,"f":true,"t":"bool"},"in_5":{"v":true,"f":true,"t":"bool"},"in_6":{"v":true,"f":true,"t":"bool"},"in_7":{"v":12,"f":true,"t":"integer"},"in_8":{"v":26,"f":true,"t":"integer"},"in_9":{"v":9,"f":true,"t":"integer"}}]})

madanmohan0507 commented 1 year ago

@slukin1 That's exactly what I did. Is it working for you??

slukin1 commented 1 year ago

cannot parse pine error - probably check unclosed [or { or } etc., [{},{},...{}]

slukin1 commented 1 year ago

rsi, your values "st5","st1","sds_1" will be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p1d26K/0fMEsGYzC2UzVt1qzeibZD9zwC6LBpTUT00paFZBS0r3o0b0RnhD4eB1RmLBtqYYcc+tArCQHj0JFUe0qtDo/u6SzXfrd8p0PJPMWhTzClx8U0p0OtcoVMRRK825svFaVMfpyIti4oCjIpMWQbd/7WvimP/Xus5qDXAd64UTWT+X9u9vnNFaFsb0gL7MGiCPCXhG7L3/0dj1YzfpZVUtiPmKkauqS/5J3MLTUVfl9FhbNM/65oFHP2MYq00DjY+sXMd+3134boI1VHDo9f6pFOtQsmRvNg5AwYVQBvK4/bgDZHmZLv2D65HpjhMrrdXdfX7QqiJ4rtzvU0exs4TfBxeDD/cNCugtjKxO2g5XrosN5AT1LwP4WEdE/3gjS2QPQAJ7FfENRiZyp17KH8K71XZ6mehC2ZNF0k1V82SAF/YcyPhp1F76D6paeA8SGO8/11boyoShTtzG/zgU+dlOaFB/946ED0t/vPNmwSkEVda4JJU4Nbcp0rCYcS9+cyiLykcU9kkvB2ZlwqPOVSX4WdANLrijTka8uxoQO1o+n1yE1NXm9QD5PG7NfCn4RrZPywn8M140jGw4hjrdDVolMvwcCleJbKDKmzctdvxPkDI23XugjIVET+0FB2D8oOX9v2ZCPib5qX3nEqaZQyliTF1caatg==","pineId":"STD;RSI","pineVersion":"34.0","pineFeatures":{"v":"{\"indicator\":1,\"plot\":1,\"ta\":1,\"math\":1,\"alertcondition\":1}","f":True,"t":"text"},"in_0":{"v":14,"f":True,"t":"integer"},"in_1":{"v":"close","f":True,"t":"source"},"in_2":{"v":"SMA","f":True,"t":"text"},"in_3":{"v":14,"f":True,"t":"integer"},"in_4":{"v":2,"f":True,"t":"float"},"in_5":{"v":False,"f":True,"t":"bool"},"in_6":{"v":"","f":True,"t":"resolution"},"in_7":{"v":True,"f":True,"t":"bool"}}])

madanmohan0507 commented 1 year ago

@slukin1 I checked for commas and even tried this message, but didn't work. :( But thanks a lot for all the input and help. :)

slukin1 commented 1 year ago

Indicators data also available by selenium parsing window Object tree - Data window

madanmohan0507 commented 1 year ago

rsi, your values "st5","st1","sds_1" will be different

sendMessage(ws, "create_study", [chart_session,"st5","st1","sds_1","Script@tv-scripting-101!",{"text":"bmI9Ks46_GDXU32aIsC0JJYVxCztrYw==_lFuvP6Rua1E9Z4DGGhWENnCFtZtuQzhGv5h1sv6iIKS6m+8nbjXP1Y5hZI3bkb8ffxCpA9k1WG50+7QCUplyOQ93Q1j0/i/7u4BLqJmwFaNEPRgH7k7hOB+7WhgDaw3OUFF/V2AUEkKsUiBTliW9a/VdtZjQeGfZRB+B6nxWz8u5uFhWnG4h++lzufuJwYQBOdNBBy/Dd+9gQL3jz9NOswUN0NLaAz0oQyUr8r/UtTV9Hjybc7J5/x7jttiVjV7rUOWkL2kVU3CdQ/WXQ2l/SCilAjwlEOFpHNzUtK6utvEknLnV4u2gDmfIgQzoLOil09qKUFXwLGz+9DgG6QE3P/mgOBaOjnyNcxcaqvDdwayKFz9HBymxGXnHX+MXYBA+505o53A9CH2beLQpm9fhKkFGOFjhuvDVXFN5MeY39vJ7uOPkKxk+r5FiISlRzT3s5WnJOiF5cfO2mM8H+ssq9bce6IvOg/1UUJJWHPmlro/MQ7RvvGVPA3KDjuV6iZpXFD/dEjCNrYcY7CQ9AMBG24GxsYZyRa2JV9NWDFFaPFgXprVi69/Ba4FOp9urbe5BkzfpkQaHWZVGsKotUeFh5Tl2z4ai5Fpf12/OMDeOpOrwVfOqJ8Im5tCcOLCQ26kgL1+TRYoaGX5UXeoYsrcAsNE1NtzKGNr+wXXDnDo/GtqVzkqhIs9OV9R82QG5z3TQNpDsGcFtsxHEasbWDm5zNnJVDzwKBCGMal8RKut+/uUAT86q5r+/scyqDHasgJ7fxf9hoChbSIQ797qFCBVT82dwqcOsq4iPilf9RvvCBAceW2rZF4Yp8M1vDSyFXwNG6VemzhAfmAmlXGdnpP/ydA0prg+66/ZBl8O7JAO9bKrNwp4tJSPG9rI0EV4na25yzT6a7WLIYUpWZmlnv7sag/K9Kt7cxPted6h0ltz4npiNw0qF5mtIE0QD23HLoQEeZfEcgg/ZEtFFyArp1d26K/0fMEsGYzC2UzVt1qzeibZD9zwC6LBpTUT00paFZBS0r3o0b0RnhD4eB1RmLBtqYYcc+tArCQHj0JFUe0qtDo/u6SzXfrd8p0PJPMWhTzClx8U0p0OtcoVMRRK825svFaVMfpyIti4oCjIpMWQbd/7WvimP/Xus5qDXAd64UTWT+X9u9vnNFaFsb0gL7MGiCPCXhG7L3/0dj1YzfpZVUtiPmKkauqS/5J3MLTUVfl9FhbNM/65oFHP2MYq00DjY+sXMd+3134boI1VHDo9f6pFOtQsmRvNg5AwYVQBvK4/bgDZHmZLv2D65HpjhMrrdXdfX7QqiJ4rtzvU0exs4TfBxeDD/cNCugtjKxO2g5XrosN5AT1LwP4WEdE/3gjS2QPQAJ7FfENRiZyp17KH8K71XZ6mehC2ZNF0k1V82SAF/YcyPhp1F76D6paeA8SGO8/11boyoShTtzG/zgU+dlOaFB/946ED0t/vPNmwSkEVda4JJU4Nbcp0rCYcS9+cyiLykcU9kkvB2ZlwqPOVSX4WdANLrijTka8uxoQO1o+n1yE1NXm9QD5PG7NfCn4RrZPywn8M140jGw4hjrdDVolMvwcCleJbKDKmzctdvxPkDI23XugjIVET+0FB2D8oOX9v2ZCPib5qX3nEqaZQyliTF1caatg==","pineId":"STD;RSI","pineVersion":"34.0","pineFeatures":{"v":"{"indicator":1,"plot":1,"ta":1,"math":1,"alertcondition":1}","f":True,"t":"text"},"in_0":{"v":14,"f":True,"t":"integer"},"in_1":{"v":"close","f":True,"t":"source"},"in_2":{"v":"SMA","f":True,"t":"text"},"in_3":{"v":14,"f":True,"t":"integer"},"in_4":{"v":2,"f":True,"t":"float"},"in_5":{"v":False,"f":True,"t":"bool"},"in_6":{"v":"","f":True,"t":"resolution"},"in_7":{"v":True,"f":True,"t":"bool"}}])

@slukin1 Is this working for you??

slukin1 commented 1 year ago

~m~98~m~{"m":"study_completed","p":["cs_UzgA87OuYCzF",....

madanmohan0507 commented 1 year ago

~m~158~m~{"m":"study_error","p":["cs_dgvstwayrbsh","st5","s1_st1","Can't parse pine","sin1-charts-24-webchart-11@sin1-compute-24"],"t":1699606103,"t_ms":1699606103531} This is what I am getting

madanmohan0507 commented 1 year ago

Could you please share your code on mail so I can figure out where am I going wrong. Thanks :)

slukin1 commented 1 year ago

these codes with adding one more line sendMessage(ws, "create_study", [chart_session,"st5","st1","sds_1","Script@tv-scripting-101!",....

https://raw.githubusercontent.com/0xrushi/tradingview-scraper/master/main.py https://raw.githubusercontent.com/0xrushi/tradingview-scraper/master/livestreamtest.py

madanmohan0507 commented 1 year ago

That is the line I wanted to check. Rest of the code works for me.

slukin1 commented 1 year ago

copy-paste from working code isnt good solution for first steps. better to find error in not working code. Could You show Your code with deleted login password, Ill test it with my login password

madanmohan0507 commented 1 year ago

Yea sure. test.txt

slukin1 commented 1 year ago

Error reason is: unauthorized_user_token Indicators not allowed without authorisation. Log in with free subscription and code will work. With free subscription You can add 2 indicators https://github.com/0xrushi/tradingview-scraper def get_auth_token(): sign_in_url = 'https://www.tradingview.com/accounts/signin/' username = 'username' password = 'password' data = {"username": username, "password": password, "remember": "on"} headers = { 'Referer': 'https://www.tradingview.com' } response = requests.post(url=sign_in_url, data=data, headers=headers) auth_token = response.json()['user']['auth_token']
return auth_token Then send a message through the tunnel sendMessage(ws, "set_auth_token", ["auth_token"])

madanmohan0507 commented 1 year ago

I was doing this earlier, this stated showing me some error which was due to recaptcha verification failure. But the cannot parse pine error was still there even when the verification worked. Th RSI string that is there in the discussion (given by euvgub) does work so I don't think authentication is the problem. :(

madanmohan0507 commented 1 year ago

That is why I was asking for the code so I could see my error.

slukin1 commented 1 year ago

Indicators not allowed without authorisation What was recaptcha verification failure error?

slukin1 commented 1 year ago

use full headers from browser for log in to avoid recaptcha error.

madanmohan0507 commented 1 year ago

I got the following error after using all the headers: - ~m~45~m~{"m":"protocol_error","p":["bad auth token"]}

slukin1 commented 1 year ago

login form changed change [here_other_string] to yours from browser without [ ] and without " " change [your_login] to yours from browser without [ ] and without " " change [your_password] to yours from browser without [ ] and without " " response will contain "auth_token":"eyJh......"

import requests s=requests.session() headers = { 'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"', 'x-language': 'en', 'sec-ch-ua-mobile': '?0', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', 'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundary[here_other_string]', 'Referer': 'https://www.tradingview.com/', 'x-requested-with': 'XMLHttpRequest', 'sec-ch-ua-platform': '"Linux"', }

data = '------WebKitFormBoundary[here_other_string]\r\nContent-Disposition: form-data; name="username"\r\n\r\n[your_login]\r\n------WebKitFormBoundary[here_other_string]\r\nContent-Disposition: form-data; name="password"\r\n\r\n[your_password]\r\n------WebKitFormBoundary[here_other_string]--\r\n' response = s.post('https://www.tradingview.com/accounts/signin/', headers=headers, data=data) print(response.text) print(response.headers)

madanmohan0507 commented 1 year ago

Where are these headers? The headers that I have on my websockets are different. (They are already in the headers list in the code)

slukin1 commented 1 year ago

first we need to log in. but we got recaptcha_required. probably we can use cookies from browser. code refactoring in progress

slukin1 commented 1 year ago

first idea log in with selenium, manually solve recaptcha and pass cookies and auth_token to requests

def get_auth_token():
    #from selenium import webdriver
    #from selenium.webdriver.chrome.service import Service as ChromeService
    #from webdriver_manager.chrome import ChromeDriverManager
    #from selenium.webdriver.chrome.options import Options
    #from selenium.webdriver.common.keys import Keys
    #from selenium.webdriver.common.action_chains import ActionChains
    #from selenium.webdriver.support.wait import WebDriverWait
    #from selenium.webdriver.support import expected_conditions as EC
    #from selenium.webdriver.common.by import By
    #import requests

    chrome_options = Options() 
    chrome_options.add_experimental_option("detach",True)
    driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
    driver.get('https://www.tradingview.com/accounts/signin')
    driver.find_element(By.XPATH,'//button[@name="Email"]').click()
    driver.find_element(By.XPATH,'//input[@id="id_username"]').send_keys('your_login')
    driver.find_element(By.XPATH,'//input[@id="id_password"]').send_keys('your_password')
    #driver.find_element(By.XPATH,'//input[@type="checkbox"]').click()
    driver.find_element(By.XPATH,'//button[contains(@class,"submitButton")]').click()
    ### here come recaptcha
    ### after solving it manually we authorizied and have auth_token and cookies to pass to requests session
    html_source = driver.page_source
    #f = open("page_after_login_auth_token_here.html", "w")
    #f.write(html_source)
    #f.close()
    auth_token=html_source.split('"auth_token":"')[1].split('",')[0]

    cookies_selenium = driver.get_cookies()
    s = requests.Session()
    c = [s.cookies.set(c['name'], c['value']) for c in cookies_selenium]
    driver.close()
    return auth_token
.....
.....sendMessage(ws, "set_auth_token", ["auth_token"])
.....
slukin1 commented 1 year ago

It seems that the paranoid mode against automation in the browser version is activated. I'll try the android version Your computer or network may be sending automated queries. To protect our users, we can't process your request right now.