2.37K 浏览
0

如题,下面的代码,在收盘以后还一直在显示,请问是什么原因呢?

from tqsdk import TqApi, TqAuth
from time import strftime
 api = TqApi(auth=TqAuth("....", "...."))
 code = 'CFFEX.IO2109-P-4800'
quote = {code: api.get_quote(code)}
q = quote[code]
while True:
    if api.is_changing(q, 'last_price'):
        print(strftime('%X'), 'changed')

我比较了接受到的last_price,和之前的没有不同。

如果我自己把last_price暂存到一个变量,再判断last_price是否更新的话,返回的是False,说明api.is_changing返回结果有问题?

如下是我的代码,收盘或者盘中休息时间不会更新,但是使用api.is_changing会一直为True。

code = 'CFFEX.IO2109-P-4800'
quote = {code: api.get_quote(code)}
q = api.get_quote(code)
k = api.get_kline_serial(code, duration_seconds=60, data_length=500)
old_last_price = q.last_price
while True:
    if q.last_price != old_last_price:
        print('last_price changed!')
        old_last_price = q.last_price
    pass

ringo 已回答的问题 2021年8月31日
1

api.is_changing是作用于本次收到的行情和上次收到的行情来比较是否发生了变化,你的示例代码中并未调用wait_update所以都是取到的第一次的截面行情

当用户只获取到一次截面数据行情时这个时候用api.is_changing会判断为True,因此在循环中会一直判断为True

jaried 发表新评论 2021年8月31日

明白了,谢谢

您正在查看2个答案中的1个,单击此处查看所有答案。