jQuery调用腾讯股票数据接口返回指定股票代码的股票信息

Web前端开发 / 19 次阅读

通过js调用腾讯股票数据接口,把返回的股票信息显示在自己的web网页上。调用很简单,把接口返回的数组逐一插入到web上的节点元素即可。

股票接口:

https://qt.gtimg.cn/q=r_hk00700

  • 港股: r_hk + 股票代码

  • 上证:sh + 股票代码

  • 深证:sz + 股票代码

HTML代码:

<script src="https://qt.gtimg.cn/q=r_hk00700"></script>
<div id="stock">
    <div class="status">
        <div class="price down">
            <span class="cur"></span>
            <span class="raf"><i class="much"></i>港元 ( <i class="rate"></i>%)</span>
        </div>
    </div>
    <div class="meta">
        <p>
            <span class="max"></span>
            全日最高(港元)
        </p>
        <p>
            <span class="min"></span>
            全日最低(港元)
        </p>
        <p>
            <span class="vol"></span>
            成就量(萬股)
        </p>
        <p>
            <span class="total"></span>
            成交額(億港元)
        </p>
    </div>                        
    <div class="tips">
        <p>截止<span></span>香港時間報價有十五分鐘或以上延遲</p>
        <p>資料來源:騰訊財經</p>
    </div>
</div>

js代码:

if(typeof v_r_hk00688 != 'undefined'){
    var stock = $('#stock');
    var stockArray = v_r_hk00688.split('~');
    stock.find('.cur').text(stockArray[3]);
    stock.find('.stat').text(stockArray[31]);
    var stat = stockArray[31] > 0 ? 'up' : 'down';
    stock.find('.price').addClass(stat);
    stock.find('.much').text(stockArray[31]);
    stock.find('.rate').text(stockArray[32]);
    stock.find('.max').text(stockArray[33]);
    stock.find('.min').text(stockArray[34]);
    stock.find('.vol').text((Number(stockArray[36])/10000).toFixed(2));
    stock.find('.total').text((stockArray[37]/100000000).toFixed(2));
    var _date = new Date().toLocaleString().replaceAll('/','-');
    stock.find('.tips span').text(_date);
}

附:腾讯股票接口

获取最新行情:https://qt.gtimg.cn/q=sh600000
获取实时资金流向:https://qt.gtimg.cn/q=ff_sh600000
获取盘口分析:https://qt.gtimg.cn/q=s_pksh600000
获取简要信息:https://qt.gtimg.cn/q=s_sh600000
获取港股最新行情:https://qt.gtimg.cn/q=r_hk09988
获取美股最新行情:https://qt.gtimg.cn/?q=s_usBABA
分时图:https://data.gtimg.cn/flashdata/hushen/minute/sh600000.js?maxage=110&0.28163905744440854
五天分时图:https://data.gtimg.cn/flashdata/hushen/4day/sz/sh600000.js?maxage=43200&visitDstTime=1
日k:https://data.gtimg.cn/flashdata/hushen/latest/daily/sh600000.js?maxage=43201&visitDstTime=1
指定年份的日K先:https://data.gtimg.cn/flashdata/hushen/daily/17/sz000750.js?visitDstTime=1
周K:https://data.gtimg.cn/flashdata/hushen/latest/weekly/sh600000.js?maxage=43201&visitDstTime=1
月k:https://data.gtimg.cn/flashdata/hushen/monthly/sh600000.js?maxage=43201
实时成交量明细:https://stock.gtimg.cn/data/index.php?appn=detail&action=data&c=sh600000&p=2(p为分页)
大单数据:https://stock.finance.qq.com/ss