D:\Python38\lib\site-packages\tqsdk\api.py:1160: DeprecationWarning: Task.current_task() is deprecated, use asyncio.current_task() instead
if asyncio.Task.current_task(loop=self._loop) is None:
经常反复出现以上提示,但好像也不影响开仓、平仓等。
不知有没有什么影响?如果没有什么不良影响,能否屏蔽这种提示?
class WorkerThread(threading.Thread):
def __init__(self, api, symbol):
threading.Thread.__init__(self)
self.api = api
self.symbol = symbol
def run(self):
SHORT = 30 # 短周期
LONG = 60 # 长周期
data_length = LONG + 2 # k线数据长度
klines = self.api.get_kline_serial(self.symbol, duration_seconds=60, data_length=data_length)
target_pos = TargetPosTask(self.api, self.symbol)
while True:
self.api.wait_update()
if self.api.is_changing(klines.iloc[-1], “datetime”): # 产生新k线:重新计算SMA
short_avg = ma(klines[“close”], SHORT) # 短周期
long_avg = ma(klines[“close”], LONG) # 长周期
if long_avg.iloc[-2] short_avg.iloc[-1]:
target_pos.set_target_volume(-3)
print(“均线下穿,做空”)
if short_avg.iloc[-2] long_avg.iloc[-1]:
target_pos.set_target_volume(3)
print(“均线上穿,做多”)
if __name__ == “__main__”:
api_master = TqApi(TqSim())
# Create new threads
thread1 = WorkerThread(api_master.copy(), “SHFE.cu1901”)
thread2 = WorkerThread(api_master.copy(), “SHFE.rb1901”)
# Start new Threads
thread1.start()
thread2.start()
while True:
api_master.wait_update()