代码基于天勤量化平台,先贴出完整代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#import asyncio
from tqsdk import TqApi, TqAuth
from contextlib import closing
from time import time
# 创建API实例.
api = TqApi(auth=TqAuth("天勤账号", "账号密码"))
async def taoli(Call='',Put='',Lr=3, Dlr=1): #默认3跳,1跳对手价平仓损耗,1跳抹除手续费,1跳纯利润
quote_C = api.get_quote(Call)
quote_P = api.get_quote(Put)
futer = quote_C.underlying_symbol
quote_F = api.get_quote(futer)
async with api.register_update_notify([quote_C,quote_P,quote_F]) as update_chan: #
async for _ in update_chan: #
D_time = (quote_C.last_exercise_datetime-time()) * Lr / (Dlr*86400)
if quote_C.exercise_type == 'A':
lr = quote_F.price_tick * Lr #行权盈利点数