首页 > 解决方案 > 如何在 TradingView 中使用 python 请求生成警报?

问题描述

我一直在尝试在 TradingView 上创建警报并且很挣扎。首先,我正在登录 TradingView。之后,我创建了一个警报,但此时我收到了 <Response [400]>。

我在哪里做错了。

import requests
from requests.auth import HTTPBasicAuth

url = "https://pine-facade.tradingview.com/pine-facade/gen_alert/?user_name=*******"
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
    'origin': 'https://tr.tradingview.com'
}
data = {
    'alert_info': '{"version":21,"condition":{"id":"cross","fireInfo":{"frequency":"on_first_fire"},"mainSeries":{"id":"-273720050"},"alertSeries":{"id":"-273720050"},"band":{"id":"4iHylo"}},"statesForAlert":{"-273720050":{"id":"-273720050","uniqueId":"-273720050","type":"MainSeries","proSymbol":"BIST:XU100","actualSymbol":"BIST_DLY:XU100","symbolString":"={\"symbol\":\"BIST_DLY:XU100\",\"adjustment\":\"splits\"}","interval":"1D","style":1,"styleInputs":{},"extendedHours":false,"dividendsAdjustment":false,"isSpread":false,"formatter":{"type":"price","state":{"fractional":false,"fractionalLength":2,"minMove":1,"minMove2":0,"priceScale":100}}},"4iHylo":{"id":"4iHylo","uniqueId":"4iHylo","type":"Value","value":"1441.3"}},"message":"BU BİR DENEMEDİR"}'
}
login_header = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
    'origin': 'https://tr.tradingview.com',
    'referer': 'https://tr.tradingview.com/chart/UBleIH5q/'
}
login_url = "https://tr.tradingview.com/accounts/signin/"
login_data = {
    'username': '****',
    'password': '*****',
    'remember': 'off'
}
with requests.Session() as s:
    y = s.post(login_url, data=login_data, headers=login_header)
    print(y)
    response = s.post(url, data=data, headers=headers)
    print(response)

标签: pythonpython-requests

解决方案


推荐阅读