已解决3.57K 浏览
0

当前开盘价: 3983.000000, 上轨: 3960.000000, 下轨: 3941.000000
Traceback (most recent call last):
File “F:\PYTHON\workpython\ex19.py”, line 62, in <module>
api.wait_update()
File “F:\PYTHON\python3.6\python3.7\lib\site-packages\tqsdk\api.py”, line 891, in wait_update
self._process_serial_extra_array(serial)
File “F:\PYTHON\python3.6\python3.7\lib\site-packages\tqsdk\api.py”, line 1438, in _process_serial_extra_array
del serial[“extra_array”][col]
KeyError: ‘datetime’

2008 vlent 选择最佳答案 2020年3月31日

没有使用多线程,以下是代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tqsdk import TqApi, TargetPosTask
from tqsdk import TqApi, TqSim, TqBacktest, BacktestFinished
from datetime import datetime, date
from contextlib import closing
from tqsdk import TqApi, TqSim
from tqsdk.tools import DataDownloader
from tqsdk import TqApi, TargetPosTask
from tqsdk import TqApi, TqSim, tafunc
import time

SYMBOL = “DCE.jd2001” # 合约代码
NDAY = 5 # 天数
K1 = 0.2 # 上轨K值
K2 = 0.2 # 下轨K值

acc = TqSim()
api = TqApi(acc,backtest=TqBacktest(start_dt=date(2019, 5, 1), end_dt=date(2019, 10, 1)))
print(“策略开始运行”)

print(“策略开始运行”)

quote = api.get_quote(SYMBOL)
klines = api.get_kline_serial(SYMBOL, 24 * 60 * 60) # 86400使用日线
target_pos = TargetPosTask(api, SYMBOL)
df = api.get_kline_serial(“SHFE.rb2005”, 5*60)
while True:
api.wait_update()
if api.is_changing(klines.iloc[-1], [“datetime”, “open”]): # 新产生一根日线或开盘价发生变化: 重新计算上下轨
current_open = klines.iloc[-1][“open”]
if current_open >klines.high.iloc[-2] or current_open buy_line: # 高于上轨
print(“高于上轨,目标持仓 多头3手”)
target_pos.set_target_volume(3) # 交易
elif quote.last_price < sell_line: # 低于下轨
print("低于下轨,目标持仓 空头3手")
target_pos.set_target_volume(-3) # 交易
else:
print('未穿越上下轨,不调整持仓')

0

tqsdk版本是?是否有使用多线程?

2008 vlent 选择最佳答案 2020年3月31日