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

因为收盘后交易所也可能返回数据的,并不是完全没有任何数据。盘后建议关闭重启策略,跨交易日如果不重启容易导致未知错误

jaried 编辑评论 2021年8月31日

但是我用的是:api.is_changing(q, ‘last_price’)
盘后last_price应该不会更新才对呀。

会发的,但是数据比较奇怪,这个是可能的

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

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

因为评论的代码有问题,我更新了问题。

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