获取python / Django中所有交易品种的nse股票的实时数据

我正在从事库存预测项目。这就是我想要的:

要显示Nifty50,Nifty100左右的所有可用股票,然后用户将选择该股票以仅预测第二天该股票的高低价格。

我正在使用Django。

我到目前为止所做的事情: 我可以显示库存清单。

def index(request):
    api_key = 'myAPI_Key'

    url50 = 'https://archives.nseindia.com/content/indices/ind_nifty50list.csv'
    url100 = 'https://archives.nseindia.com/content/indices/ind_nifty100list.csv'
    url200 = 'https://archives.nseindia.com/content/indices/ind_nifty200list.csv'

    sfifty = requests.get(url50).content
    shundred = requests.get(url100).content
    stwohundred = requests.get(url200).content

    nifty50 = pd.read_csv(io.StringIO(sfifty.decode('utf-8')))
    nifty100 = pd.read_csv(io.StringIO(shundred.decode('utf-8')))
    nifty200 = pd.read_csv(io.StringIO(stwohundred.decode('utf-8')))

    nifty50 = nifty50['Symbol']
    nifty100 = nifty100['Symbol']
    nifty200 = nifty200['Symbol']



    context = {
        'fifty': nifty50,'hundred': nifty100,'twohundred': nifty200
               }

    return render(request,'StockPrediction/index.html',context)

我想要的东西: 我想获取所有股票的实时数据openhighLTPChangeVolume。根据实时数据,它会发生变化根据股票价值将改变。

请帮助!

iCMS 回答:获取python / Django中所有交易品种的nse股票的实时数据

您必须结合下面的代码Ajax/Jquery来定期获取数据并更新DOM中的值:

(function getStocks() {
    $.ajax({
            type: "GET",url: "url to your view",success: function (data) {
                // here you can get data from backend and do changes like
                // changing color by the data coming from your view.
            }
        }).then(function() {           // on completion,restart
       setTimeout(getStocks,30000);  // function refers to itself
    });
})();

但是在发出过多请求时也要小心,您必须在此行setTimeout(getStocks,"proper interval");

中选择适当的时间间隔

在您的view中,您应该将查询放入JSON格式,如下所示:

return JsonResponse({'stocks': stocks})

此处stocks的格式必须为json

本文链接:https://www.f2er.com/2246593.html

大家都在问