1.Lib\site-packages\vnpy路径下新建user_tools文件夹,放入pricetick.py
pricetick.py内容如下:
import json
import os
class PRICETICK(object):
PATH = os.environ["USERPROFILE"] + "\\.vntrader\\unit.json"
PRICE_TICK = 0.0 #最小跳动点 float
UNIT = 0 #合约乘数 int
def get_unit(self,symbol):
with open(self.PATH,"r",encoding="utf_8") as f:
result = json.load(f)
for key_symbol in result:
if key_symbol == symbol:
self.PRICE_TICK = float(result[symbol][0]) #json读取最小跳动点
self.UNIT = int(result[symbol][1]) #json读取合约乘数
break
return self.PRICE_TICK,self.UNIT
2. .vntrader\unit.json 在.\vntrader文件夹下,新建unit.json, json文件存储所有标的最小跳动点,合约乘数
unit.json内容如下:
{
"IF":["0.2","300"],
"IC":["0.2","200"],
"IH":["0.2","300"],
"IM":["0.2","200"],
"T":["0.005","10000"],
"TF":["0.005","10000"],
"TS":["0.005","20000"],
"TL":["0.01","10000"],
"AU":["0.02","1000"],
"AG":["1","15"],
"CU":["10","5"],
"AL":["5","5"],
"ZN":["5","5"],
"PB":["5","5"],
"NI":["10","1"],
"SN":["10","1"],
"RB":["1","10"],
"WR":["1","10"],
"I":["0.5","100"],
"HC":["1","10"],
"SS":["5","5"],
"SF":["2","5"],
"SM":["2","5"],
"JM":["0.5","60"],
"J":["0.5","100"],
"ZC":["0.2","100"],
"FG":["1","20"],
"SP":["2","10"],
"FU":["1","10"],
"LU":["1","10"],
"SC":["0.1","1000"],
"BC":["10","5"],
"EC":["0.1","50"],
"BU":["1","10"],
"PG":["1","20"],
"RU":["5","10"],
"NR":["5","10"],
"L":["1","5"],
"TA":["2","5"],
"V":["1","5"],
"EG":["1","10"],
"MA":["1","10"],
"PP":["1","5"],
"EB":["1","5"],
"UR":["1","20"],
"SA":["1","20"],
"C":["1","10"],
"A":["1","10"],
"CS":["1","10"],
"B":["1","10"],
"M":["1","10"],
"Y":["2","10"],
"RM":["1","10"],
"OI":["1","10"],
"P":["2","10"],
"CF":["5","5"],
"SR":["1","10"],
"JD":["1","10"],
"AP":["1","10"],
"CJ":["5","5"],
"PF":["2","5"],
"PK":["2","5"],
"AO":["1","20"],
"LC":["50","1"],
"SI":["5","5"],
"BR":["5","5"],
"RR":["1","10"],
"LH":["5","16"],
"PX":["2","5"],
"SH":["1","30"]
}
3.在自己的策略中调用
from vnpy.user_tools.pricetick import PRICETICK
初始化时候def __init__():
实例化 self.contract = PRICETICK()
获取标的 self.symbol = "".join(re.findall(r"\D+",self.get_data()["vt_symbol"].split(".")[0])).upper()
提取最小变动价格,合约乘数 self.PRICE_TICK,self.UNIT = self.contract.get_unit(self.symbol) #从json提取最小变动价位,合约乘数