3.26K 浏览
0
k线数据不更新的问题,去掉最后两行代码,print打印正常更新,加上最后两句代码print打印更新不到实时数据
请问这个是哪里出的问题?这里我个人肯定是wait_update底层代码的问题,因为我这样写的代码在跑数字货币API实盘已经有1年多了

from tqsdk import TqApi
import datetime
import pandas as pd
import time
api = TqApi()
pd.set_option('display.max_colwidth', 10000)
pd.set_option('expand_frame_repr', False)
pd.set_option('display.max_columns', None, 'display.max_rows', None)
# 获得 cu2003 10秒K线的引用
df = api.get_kline_serial("SHFE.rb2010", 1,1440)
print(datetime.datetime.fromtimestamp(df.iloc[-1]["datetime"] / 1e9))

def get_k():
    while True:
        api.wait_update()
        time.sleep(1)
        df['Time'] = pd.to_datetime(df['datetime'])
        return df
while True:
    df=get_k()

    df2=df

    df2['Time'] = df2['Time'] + pd.Timedelta(hours=8)
from tqsdk import TqApi
import datetime
import pandas as pd
import time
api = TqApi()
pd.set_option('display.max_colwidth', 10000)
pd.set_option('expand_frame_repr', False)
pd.set_option('display.max_columns', None, 'display.max_rows', None)
# 获得 cu2003 10秒K线的引用
df = api.get_kline_serial("SHFE.rb2010", 1,1440)
print(datetime.datetime.fromtimestamp(df.iloc[-1]["datetime"] / 1e9))
 def get_k():
    while True:
        api.wait_update()
        time.sleep(1)
        df['Time'] = pd.to_datetime(df['datetime'])
        return df
while True:
    df=get_k()
     df2=df
     df2['Time'] = df2['Time'] + pd.Timedelta(hours=8)
     df2['ema5'] = df2['close'].rolling(5, min_periods=1).mean()
    df2['ema20'] = df2['close'].rolling(20, min_periods=1).mean()
    df2['ema120'] = df2['close'].rolling(120, min_periods=1).mean()
     bd_15 = df2.loc[df2['ema5'] <4000, 'ema5'].values[0]
    #
    df2['bd_ab'] = df2['ema5'] / bd_15
     print(df2)
    df3=df2
    df3.loc[df3['bd_ab'] < 2.5, 'duo'] = 1

df2['ema5'] = df2['close'].rolling(5, min_periods=1).mean()
df2['ema20'] = df2['close'].rolling(20, min_periods=1).mean()
df2['ema120'] = df2['close'].rolling(120, min_periods=1).mean()

bd_15 = df2.loc[df2['ema5'] <4000, 'ema5'].values[0]
#
df2['bd_ab'] = df2['ema5'] / bd_15

print(df2)
df3=df2
df3.loc[df3['bd_ab'] < 2.5, 'duo'] = 1

west 已回答的问题 2020年7月17日