上期技术CTPAPI封装COM组件ctp开放平台openctp环境7_24小时x64组件python_delphi调用演示程序
生活随笔
收集整理的這篇文章主要介紹了
上期技术CTPAPI封装COM组件ctp开放平台openctp环境7_24小时x64组件python_delphi调用演示程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
源碼下載地址:https://gitee.com/topview999/TopViewQHTCtpCom
新修改后的python調用COM組件,pyside2制作的UI界面。體驗一下遠超VeighNaStation(VNPY)的訂單及持倉刷新速度。陽了的時候無聊,攻了攻pyside2,算是入了門。pyside2界面簡潔大方,功能強大,性能不錯。源代碼全部公開,COM組件免費,所有涉及到的代碼都免費,拿去簡單修改就可以搭建自己的量化平臺。代碼中大量的使用線程多任務用以更新界面、操作開平倉,性能、速度、穩定性沒的說。話說python pyside2的性能有時確實不俗,查詢全市場合約時,python pyside2界面下線程幾秒鐘完成。
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'TvQhtCtpComPYClient.ui' # # Created by: PyQt5 UI code generator 5.15.7 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing.import win32com.client.CLSIDToClass, pythoncom, pywintypes import win32com.client.util from pywintypes import IID from win32com.client import Dispatch from threading import Thread import random import time import datetime import ctypes import numpy as np import traceback #import tracemalloc #進行內存分析追蹤from TVQHTCTPCOM import * from TVQHTCTPCOM import ITVQhtICtpClientAPI from PySide2.QtWidgets import QApplication,QWidget,QLabel,QProgressBar,QTableView,QTextEdit,QLabel #引用的 是pyside6時,線程無法觸及信號發送。不知為何。 from PySide2.QtUiTools import QUiLoader from PySide2.QtCore import QFile,QTimer from PySide2.QtGui import QStandardItemModel from PySide2.QtGui import QStandardItem from PySide2.QtCore import Signal,QObject # 導入信號類 DescendingOrder import sys class TMyPostion:def __init__(self):self.LongPostion = 0 self.LongYDPostion = 0 self.LongFrozen = 0 self.LongOrder = 0self.LongOrder1 = 0 self.LongOrderFlag = 0 self.ShortPostion = 0 self.ShortYDPostion = 0 self.ShortFrozen = 9self.ShortOrder = 0self.ShortOrder1 = 0 self.ShortOrderFlag = 0 class TvMyUseVar:def __init__(self):self.sInstrumentID = 'IF2212' self.sUserId = '4100' self.sPassWord = '750' self.iRefMin = 0 self.iMin = 0 self.IsDoit = 0 self.iBeginTest = 0 self.iVolT = 9self.vloop = 0 #循環時循環步驟標志self.vWaitOrderInt= 60 #下訂單時間間隔self.vWaitInOrder =0 #下訂單時間計數器self.vWaitInCancle = 0 #撤單后時間計數器self.vWaitCancleInt = 6 #撤單后時間間隔self.RunFlag = 0self.Interval = 1 #循環時間間隔self.RefSec = -1 #上一秒數self.BeginOpenClose = 0 #開始進行循環開平倉測試self.vMyBidPrice = .0self.vMyAskPrice = .0self.vIsCanC = 0self.vIsCanC1 = 0self.vIsCanC2 = 0self.vIsCanC3 = 0self.MinDouble = -99999.99self.MyPostion = TMyPostion() MyUseVar = TvMyUseVar()class MySignals(QObject):# 定義一種信號,因為有文本框和進度條兩個類,此處要四個參數,類型分別是: QPlainTextEdit 、 QProgressBar、字符串和整形數字# 調用 emit方法發信號時,傳入參數必須是這里指定的參數類型# 此處也可分開寫兩個函數,一個是文本框輸出的,一個是給進度條賦值的text_print = Signal(QLabel,QProgressBar,str,int) #刷新登錄獲取數據信息進度信號 text_MarketData = Signal(QTableView,str,float,int,float,int,float,int,float,int,float,int,str)#行情信息信號text_Account = Signal(ITVQhtICtpClientAPI,QTableView,QLabel) #每秒刷新賬戶資金信號text_PositionProfit = Signal(ITVQhtICtpClientAPI,QTableView) # 每秒刷新持倉盈虧數據信號text_OnOrder = Signal(ITVQhtICtpClientAPI,QTableView,str) #ITVQhtICtpClientAPI 訂單信號text_OnOrderLst = Signal(QTableView,int,str,str,int,str,int,int,int,int,int,float,int,str,str) #訂單推送后將訂單信息添加到表格信號text_OpenClose = Signal(ITVQhtICtpClientAPI,QTextEdit) #開平倉循環測試信號text_OutBars = Signal(ITVQhtICtpClientAPI,QTextEdit,str,int,int,float,float,float,float,str) #輸出K線Bars數據時 ,InstrumentID,Period,Counts,Hight,Low,Open,Close,CreatTimetext_OuttextEdit = Signal(QTextEdit,str) ##一個參數要寫成元數組的形式class myevents:# Event Handlers 事件回調函數列表 ,執行操作后的響應事件 都在以下函數中操作。# If you create handlers, they should have the following prototypes:def OnMarketData(self, InstrumentID=defaultNamedNotOptArg, BidPrice1=defaultNamedNotOptArg, BidVolume1=defaultNamedNotOptArg, AskPrice1=defaultNamedNotOptArg, AskVolume1=defaultNamedNotOptArg, OpenPrice=defaultNamedNotOptArg, HighestPrice=defaultNamedNotOptArg, LowestPrice=defaultNamedNotOptArg, LastPrice=defaultNamedNotOptArg, OpenInterest=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, UpperLimitPrice=defaultNamedNotOptArg, LowerLimitPrice=defaultNamedNotOptArg, PreSettlementPrice=defaultNamedNotOptArg, AveragePrice=defaultNamedNotOptArg, UpdateTime=defaultNamedNotOptArg, UpdateMilliSecond=defaultNamedNotOptArg):MyUseVar.vMyBidPrice = BidPrice1MyUseVar.vMyAskPrice = AskPrice1 for row in range(2):j = 0 for column in [InstrumentID,LastPrice,Volume,BidPrice1,BidVolume1,AskPrice1,AskVolume1,BidPrice1,-99999,AskPrice1,-99999,UpdateTime]:item = QStandardItem(f"{column}")Mui.model4.setItem(row,j,item)j = j+1Mui.AppText([j,column])def OnEventsInfo(self, InfoID=defaultNamedNotOptArg, MsgInfo=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str(["OnEventsInfo:",InfoID,MsgInfo]),))#一個參數要寫成元數組的形式thread.start()def OnInstrumentStatus(self, InstrumentID=defaultNamedNotOptArg, ExchangeID=defaultNamedNotOptArg, EnterTime=defaultNamedNotOptArg, NewState=defaultNamedNotOptArg):Mui.AppText2(["OnInstrumentStatus:",InstrumentID, ExchangeID, EnterTime,NewState])def OnTradeConnected(self):Mui.AppText2(["OnTradeConnected"])def OnTradeDisconnected(self):Mui.AppText2(["OnTradeDisconnected"])def OnMDConnected(self):Mui.AppText2(["OnMDConnected"])def OnMDDisconnected(self):Mui.AppText2(["OnMDDisconnected"])def OnOrder(self, OrderID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, TradedVolume=defaultNamedNotOptArg, AvgTradePrice=defaultNamedNotOptArg, OrderStatus=defaultNamedNotOptArg, OrderSysID=defaultNamedNotOptArg, BrokerOrderSeq=defaultNamedNotOptArg, OrderLocalID=defaultNamedNotOptArg, InsertTime=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg, ErrorMsg=defaultNamedNotOptArg, HedgeType=defaultNamedNotOptArg):threadOnOrder = Thread(target=Mui.printFunc_OnOrder,args=(InstrumentID,)) # 訂單信號線程threadOnOrder.start()threadOnOrderLst = Thread(target=Mui.printFunc_OnOrderLst,args=(OrderID,OrderLocalID,OrderSysID,BrokerOrderSeq,InstrumentID,IsBuy,IsOpen,OrderStatus, Volume,TradedVolume,Price,ErrorID,InsertTime,ErrorMsg))threadOnOrderLst.start() #訂單推送后將訂單信息添加到表格信號線程def OnTrade(self, OrderID=defaultNamedNotOptArg, OrderSysID=defaultNamedNotOptArg, OrderLocalID=defaultNamedNotOptArg, TradeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, ThisTradePrice=defaultNamedNotOptArg, TradeTime=defaultNamedNotOptArg, OrderStatus=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str(["OnTrade:",TradeTime,OrderID,OrderLocalID,OrderSysID,InstrumentID,IsBuy, IsOpen, Volume,ThisTradePrice]),))#一個參數要寫成元數組的形式thread.start()def OnRtnQuote(self, BrokerID=defaultNamedNotOptArg, UserID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, ExchangeInstID=defaultNamedNotOptArg):print("OnRtnQuote")def OnOrderCanceled(self, OrderID=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg, ErrorMsg=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str([OrderID,ErrorID,ErrorMsg]),))#一個參數要寫成元數組的形式thread.start()def OnOrderActionFailed(self, OrderID=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg, ErrorMsg=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str(["OnOrderActionFailed:",OrderID,ErrorID,ErrorMsg]),))#一個參數要寫成元數組的形式thread.start()def OnInitFinished(self):Mui.AppText2(["OnInitFinished:","初始化完成!"])MyUseVar.RunFlag = 1thread_OpenClose = Thread(target=Mui.printFunc_OpenClose) #進行每秒刷新賬戶資金 持倉盈虧數據線程 登錄完成后開始thread_OpenClose.start() def OnGetPositionDetail(self, InstrumentID=defaultNamedNotOptArg, OpenDate=defaultNamedNotOptArg, OrderID=defaultNamedNotOptArg, TradeID=defaultNamedNotOptArg, Direction=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, CloseVolume=defaultNamedNotOptArg, OpenPrice=defaultNamedNotOptArg, PositionProfitByDate=defaultNamedNotOptArg, PositionProfitByTrade=defaultNamedNotOptArg, Margin=defaultNamedNotOptArg, LastSettlementPrice=defaultNamedNotOptArg, SettlementPrice=defaultNamedNotOptArg,CloseProfitByDate=defaultNamedNotOptArg, CloseProfitByTrade=defaultNamedNotOptArg, CloseAmount=defaultNamedNotOptArg, TimeFirstVolume=defaultNamedNotOptArg,MarginRateByMoney=defaultNamedNotOptArg, MarginRateByVolume=defaultNamedNotOptArg):Mui.AppText3(["OnGetPositionDetail:",InstrumentID, OpenDate, TradeID, Direction,Volume,CloseVolume, OpenPrice, PositionProfitByDate, PositionProfitByTrade,Margin,LastSettlementPrice,SettlementPrice,CloseProfitByDate,CloseProfitByTrade, CloseAmount, TimeFirstVolume,MarginRateByMoney, MarginRateByVolume])def OnGetInstrument(self, ExchangeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, ExchangeInstID=defaultNamedNotOptArg, InstrumentName=defaultNamedNotOptArg, ProductClass=defaultNamedNotOptArg, MaxMarketOrderVolume=defaultNamedNotOptArg, MinMarketOrderVolume=defaultNamedNotOptArg, MaxLimitOrderVolume=defaultNamedNotOptArg, MinLimitOrderVolume=defaultNamedNotOptArg, VolumeMultiple=defaultNamedNotOptArg, PriceTick=defaultNamedNotOptArg, ExpireDate=defaultNamedNotOptArg, IsTrading=defaultNamedNotOptArg, LongMarginRatio=defaultNamedNotOptArg, ShortMarginRatio=defaultNamedNotOptArg, OptionsType=defaultNamedNotOptArg, ProductID=defaultNamedNotOptArg, CombinationType=defaultNamedNotOptArg, bIsLast=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str(["OnGetInstrument:",ExchangeID,InstrumentID,InstrumentName,ExpireDate,IsTrading]),))#一個參數要寫成元數組的形式thread.start()def OnRspError(self, ErrorID=defaultNamedNotOptArg, ErrorMsg=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str(["OnRspError:",ErrorID,ErrorMsg]),))#一個參數要寫成元數組的形式thread.start()def OnRspQryTrade(self, OrderID=defaultNamedNotOptArg, TradeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, OrderSysID=defaultNamedNotOptArg, OrderLocalID=defaultNamedNotOptArg, BrokerOrderSeq=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, TradeDate=defaultNamedNotOptArg, TradeTime=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str(["OnRspQryTrade:",TradeDate,TradeTime,InstrumentID,OrderID,TradeID,BrokerOrderSeq,OrderLocalID,OrderSysID,IsBuy, IsOpen, Volume,Price]),))#一個參數要寫成元數組的形式thread.start()def OnOutPosition(self, InstrumentID=defaultNamedNotOptArg, LongPostion=defaultNamedNotOptArg, LongYDPostion=defaultNamedNotOptArg, LongFrozen=defaultNamedNotOptArg, LongSuspendPostion=defaultNamedNotOptArg, LongPositionPrice=defaultNamedNotOptArg, LongProfit=defaultNamedNotOptArg, ShortPostion=defaultNamedNotOptArg, ShortYDPostion=defaultNamedNotOptArg, ShortFrozen=defaultNamedNotOptArg, ShortSuspendPostion=defaultNamedNotOptArg, ShortPositionPrice=defaultNamedNotOptArg, ShortProfit=defaultNamedNotOptArg):finded = 0findrow = -1tmpmodel = Mui.ui.gridpositions.model()j = tmpmodel.rowCount()#print("tmpmodel.rowCount ",j)#print("tmpmodel.rowCount ",tmpmodel.item(0,0).text())for row in range(j):#print("row ",row)if ((tmpmodel.item(row,0).text()==InstrumentID and tmpmodel.item(row,1).text()==" 賣") or tmpmodel.item(row,0).text()==""):#print("tmpmodel.item(row,0).text() ",tmpmodel.item(row,0).text())finded = 1findrow = rowbreakbidprice = 0.0askprice =0.0 if (finded==1):j = 0for column in [InstrumentID," 賣",ShortPostion,ShortYDPostion,ShortFrozen,ShortSuspendPostion,ShortPositionPrice,ShortProfit,bidprice,askprice]:item = QStandardItem(f"{column}")tmpmodel.setItem(findrow,j,item)j = j+1j = 0for column in [InstrumentID,"買 ",LongPostion, LongYDPostion, LongFrozen, LongSuspendPostion,LongPositionPrice,LongProfit,bidprice,askprice]:item = QStandardItem(f"{column}")tmpmodel.setItem(findrow+1,j,item)j = j+1else:item0 = QStandardItem('%s' % InstrumentID)item1 = QStandardItem('%s' % " 賣")item2 = QStandardItem('%d' % ShortPostion)item3 = QStandardItem('%d' % ShortYDPostion)item4 = QStandardItem('%d' % ShortFrozen)item5 = QStandardItem('%d' % ShortSuspendPostion)item6 = QStandardItem('%.2f' % ShortPositionPrice)item7 = QStandardItem('%.2f' % ShortProfit)item8 = QStandardItem('%.2f' % bidprice)item9 = QStandardItem('%.2f' % askprice)tmpmodel.appendRow([item0,item1,item2,item3,item4,item5,item6,item7,item8,item9])item0 = QStandardItem('%s' % InstrumentID)item1 = QStandardItem('%s' % "買 ")item2 = QStandardItem('%d' % LongPostion)item3 = QStandardItem('%d' % LongYDPostion)item4 = QStandardItem('%d' % LongFrozen)item5 = QStandardItem('%d' % LongSuspendPostion)item6 = QStandardItem('%.2f' % LongPositionPrice)item7 = QStandardItem('%.2f' % LongProfit)item8 = QStandardItem('%.2f' % bidprice)item9 = QStandardItem('%.2f' % askprice)tmpmodel.appendRow([item0,item1,item2,item3,item4,item5,item6,item7,item8,item9])def OnDepthMarketData(self, InstrumentID=defaultNamedNotOptArg, BidPrice1=defaultNamedNotOptArg, BidVolume1=defaultNamedNotOptArg, AskPrice1=defaultNamedNotOptArg, AskVolume1=defaultNamedNotOptArg, BidPrice2=defaultNamedNotOptArg, BidVolume2=defaultNamedNotOptArg, AskPrice2=defaultNamedNotOptArg, AskVolume2=defaultNamedNotOptArg, BidPrice3=defaultNamedNotOptArg, BidVolume3=defaultNamedNotOptArg, AskPrice3=defaultNamedNotOptArg, AskVolume3=defaultNamedNotOptArg, BidPrice4=defaultNamedNotOptArg, BidVolume4=defaultNamedNotOptArg, AskPrice4=defaultNamedNotOptArg, AskVolume4=defaultNamedNotOptArg, BidPrice5=defaultNamedNotOptArg, BidVolume5=defaultNamedNotOptArg, AskPrice5=defaultNamedNotOptArg, AskVolume5=defaultNamedNotOptArg, OpenPrice=defaultNamedNotOptArg, HighestPrice=defaultNamedNotOptArg, LowestPrice=defaultNamedNotOptArg, LastPrice=defaultNamedNotOptArg, OpenInterest=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, UpperLimitPrice=defaultNamedNotOptArg, LowerLimitPrice=defaultNamedNotOptArg, PreSettlementPrice=defaultNamedNotOptArg, AveragePrice=defaultNamedNotOptArg, UpdateTime=defaultNamedNotOptArg, UpdateMilliSecond=defaultNamedNotOptArg):threadDepthMarketData = Thread(target=Mui.printFunc_MarketData,args=(InstrumentID,LastPrice,Volume,BidPrice1,BidVolume1,AskPrice1,AskVolume1,BidPrice5,BidVolume5,AskPrice5,AskVolume5,UpdateTime))threadDepthMarketData.start() #行情信息 刷新到表格線程MyUseVar.vMyBidPrice = BidPrice1MyUseVar.vMyAskPrice = AskPrice1def OnPushCancleOrder(self, OrderID=defaultNamedNotOptArg, InsertTime=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, TradedVolume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, OrderStatus=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OuttextEdit,args=(str(["OnPushCancleOrder",InsertTime,InstrumentID,OrderID,IsBuy,IsOpen, Volume,TradedVolume,Price,OrderStatus]),))#一個參數要寫成元數組的形式thread.start()def OnOutProgress(self, ProFlag=defaultNamedNotOptArg, MaxInt=defaultNamedNotOptArg, Position=defaultNamedNotOptArg):str1 = ""if (ProFlag==1):str1 = "獲取全市場合約信息進度"elif (ProFlag==2):str1 = "獲取歷史訂單信息進度"elif (ProFlag==3):str1 = "獲取持倉信息進度"elif (ProFlag==4):str1 = "獲取持倉明細信息進度"elif (ProFlag==5):str1 = "讀取歷史K線數據進度"elif (ProFlag==9):str1 = "登錄初始化完成"thread = Thread(target=Mui.printFunc,args=(str1,((Position-1) % 100) +1))#登錄獲取數據進度信息 刷新到progress線程thread.start()def OnOutBars(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, Counts=defaultNamedNotOptArg, Hight=defaultNamedNotOptArg, Low=defaultNamedNotOptArg, Open=defaultNamedNotOptArg, Close=defaultNamedNotOptArg, CreatTime=defaultNamedNotOptArg):thread = Thread(target=Mui.printFunc_OutBars,args=(InstrumentID,Period,Counts,Hight,Low,Open,Close,CreatTime))thread.start()def OnOutExchangeTradeTimes(self, ExchangeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, OpenTime=defaultNamedNotOptArg, CloseTime=defaultNamedNotOptArg, TradeMins=defaultNamedNotOptArg, Flag=defaultNamedNotOptArg):Mui.AppText3("ExchangeID:{0} InstrumentID:{1} OpenTime:{2} CloseTime:{3} TradeMins:{4} Flag:{5}\n".format(ExchangeID,InstrumentID, OpenTime, CloseTime,TradeMins,Flag))thread = Thread(target=Mui.printFunc_OuttextEdit,args=("ExchangeID:{0} InstrumentID:{1} OpenTime:{2} CloseTime:{3} TradeMins:{4} Flag:{5}\n".format(ExchangeID,InstrumentID, OpenTime, CloseTime,TradeMins,Flag),))#一個參數要寫成元數組的形式thread.start()class Ui_UiMainWindow(QWidget): #objectdef __init__(self):super(Ui_UiMainWindow,self).__init__()#先導入.ui文件,存在qfile_UIUI。然后關閉qfile_UIUI = QFile("TvQhtCtpComPYClient.ui")qfile_UIUI.open(QFile.ReadOnly)qfile_UIUI.close()# 導入加載的UI類(返回的就是UI界面對應的QWidget窗體對象)self.ui = QUiLoader().load(qfile_UIUI) # 界面對象if not self.ui:print(QUiLoader().errorString())print("LoadO error")sys.exit(-1)else:print("LoadOk")# 加入界面按鈕點擊事件對應的過程回調映射。self.ui.BtnLogin.clicked.connect(self.Login) # type: ignoreself.ui.SubIns.clicked.connect(self.bSubIns) # type: ignore bUnSubInsself.ui.UnSubIns.clicked.connect(self.bUnSubIns) # type: ignoreself.ui.BtnRSQ.clicked.connect(self.callbacklog) # LogOutself.ui.BtnLogout.clicked.connect(self.LogOut) # LogOutself.ui.btnorder.clicked.connect(self.btnorder) # LogOutself.ui.rb0_4.clicked.connect(self.rb0_4click) # LogOutself.ui.rb1_4.clicked.connect(self.rb0_4click) # LogOutself.ui.rb0_5.clicked.connect(self.rb0_5click) # LogOutself.ui.rb1_5.clicked.connect(self.rb0_5click) # LogOut self.ui.btnopenclose.clicked.connect(self.btnopencloseclick) # LogOut global BeginOpenClose #開始進行循環開平倉測試 self.ui.btnChinv.clicked.connect(self.btnChinvclick) # LogOut global BeginOpenClose #開始進行循環開平倉測試 self.ms = MySignals() #引入信號函數self.ms.text_print.connect(self.pF) #將信號傳遞給主程序中pF函數進行處理self.ms.text_MarketData.connect(self.pF_MarketData) #將信號傳遞給主程序中pF函數進行處理self.ms.text_Account.connect(self.pF_Account) #將信號傳遞給主程序中pF函數進行處理self.ms.text_PositionProfit.connect(self.pF_PositionProfit) #將信號傳遞給主程序中pF函數進行處理self.ms.text_OnOrder.connect(self.pF_OnOrder) #將信號傳遞給主程序中pF函數進行處理 self.ms.text_OnOrderLst.connect(self.pF_OnOrderLst) #將信號傳遞給主程序中pF函數進行處理self.ms.text_OpenClose.connect(self.pF_OpenClose) #將信號傳遞給主程序中pF函數進行處理self.ms.text_OutBars.connect(self.pF_OutBars) #將信號傳遞給主程序中pF函數進行處理 self.ms.text_OuttextEdit.connect(self.pF_OuttextEdit) #將信號傳遞給主程序中pF函數進行處理 self.model4 = QStandardItemModel(1, 12) # 行情信息表格 設置行數 列數self.model4.setHorizontalHeaderLabels(['合約名稱','最新','數量','買一','買量','賣一','賣量','買五','買量','賣五','賣量','時間'])self.ui.tableView_4.setModel(self.model4)for row in range(1):for column in range(12):item = QStandardItem("") #如果不開始進行表格賦值,.item(row,0).text()會提示錯誤 無text()這個屬性。self.model4.setItem(row,column,item)self.model = QStandardItemModel(1, 8) #賬戶資金表格設置行數 列數self.model.setHorizontalHeaderLabels(["靜態權益","結算準備金","占用保證金","可用資金","可取資金","交易所保證金","浮動[持倉]盈虧","平倉盈虧"])self.ui.tableView.setModel(self.model)for row in range(1):for column in range(8):item = QStandardItem("") #如果不開始進行表格賦值,.item(row,0).text()會提示錯誤 無text()這個屬性。self.model.setItem(row,column,item)self.model1 = QStandardItemModel(2, 10) #持倉數據表格 設置行數 列數self.model1.setHorizontalHeaderLabels(["合約名稱","買賣","總持倉","昨倉","平倉凍結","開倉掛起","開倉均價","持倉盈虧","BidPrice","AskPrice"])self.ui.gridpositions.setModel(self.model1)for row in range(2):for column in range(10):item = QStandardItem("") #如果不開始進行表格賦值,.item(row,0).text()會提示錯誤 無text()這個屬性。self.model1.setItem(row,column,item)self.model2 = QStandardItemModel(1, 10) #訂單列表表格 設置行數 列數self.model2.setHorizontalHeaderLabels(["訂單編號","合約名稱","買賣","開平","手數","已成交","報單價格","成交均價","報單時間","報單狀態"])self.ui.tableView_2.setModel(self.model2)for row in range(1):for column in range(10):item = QStandardItem("") #如果不開始進行表格賦值,.item(row,0).text()會提示錯誤 無text()這個屬性。self.model2.setItem(row,column,item)MyUseVar.RunFlag = 0MyUseVar.Interval = 1MyUseVar.vWaitOrderInt = 60MyUseVar.RefSec = -1MyUseVar.vloop = 0MyUseVar.vWaitCancleInt = 6MyUseVar.vVolT = 9MyUseVar.BeginOpenClose = 0MyUseVar.vWaitInOrder = 0#tracemalloc.start() #啟用內存分析追蹤#self.snapshot1 = tracemalloc.take_snapshot() #建立一個內存快照def rb0_4click(self):errid = 0if (self.ui.rb0_4.isChecked()):tvapi1.SetOrderCloseMode(0,errid) #"設置登錄模式為:0 設置返回值:{0} 0設置成功 1設置失敗\n".format(errid)self.ui.textEdit_3.append("設置平倉時的優先順序模式為:0 【0 先平昨再平今 1 先平今再平昨】 設置返回值:{0} 【0設置成功 1設置失敗】\n".format(errid))else:tvapi1.SetOrderCloseMode(1,errid) #"設置登錄模式為:0 設置返回值:{0} 0設置成功 1設置失敗\n".format(errid)self.ui.textEdit_3.append("設置平倉時的優先順序模式為:1 【0 先平昨再平今 1 先平今再平昨】 設置返回值:{0} 【0設置成功 1設置失敗】\n".format(errid))def btnChinvclick(self): if (self.ui.rb0_5.isChecked()):MyUseVar.vWaitOrderInt = self.ui.spinBox.value()if (MyUseVar.vWaitOrderInt<1):MyUseVar.vWaitOrderInt = 1self.ui.spinBox.setValue(1)else:MyUseVar.vWaitOrderInt = self.ui.spinBox.value()/50if (MyUseVar.vWaitOrderInt<1):MyUseVar.vWaitOrderInt = 1self.ui.spinBox.setValue(50)self.ui.textEdit.append("設置開平倉循環測試時的時間間隔:{0} {1}\n".format(self.ui.spinBox.value(),self.ui.label_9.text()))def rb0_5click(self): if (self.ui.rb0_5.isChecked()): #設置刷新時間間隔 毫秒為單位MyUseVar.Interval = 1self.ui.label_9.setText("秒")else:MyUseVar.Interval = 0.05self.ui.label_9.setText("毫秒")def btnorder(self): #自定義一下 單按鈕事件isopen = -1isbuy = -1#//IsBuy 0.多頭 1.空頭#//IsOpen 0.開倉 1.平倉 2.強平 3.平今 4.平昨 5.強減 6.本地強平;vol = int(self.ui.edtvol.text())if (vol<=0):vol = 1 if (self.ui.rb0_2.isChecked()):isopen = 0elif (self.ui.rb1_2.isChecked()):isopen = 1elif (self.ui.rb3_2.isChecked()):isopen = 3elif (self.ui.rb4_2.isChecked()):isopen = 4if (self.ui.rb0_3.isChecked()):isbuy = 0elif (self.ui.rb1_3.isChecked()):isbuy = 1vMyBidPrice=0.0if (isbuy>=0 and isbuy<=1 and isopen>=0 and isopen<=6):MyUseVar.MyPostion.LongOrder = tvapi1.PlaceOrder(self.ui.edtIns.text(),isbuy,isopen,vol,vMyBidPrice,MyUseVar.MyPostion.LongOrder)self.ui.textEdit_3.append("{} 下訂單 order: {} Price:{} \n".format(self.ui.edtIns.text(),MyUseVar.MyPostion.LongOrder,vMyBidPrice))# 查詢操作代碼def callbacklog(self):if (self.ui.rb0.isChecked()):vMultiply = 0vPriceUnit = 0vMarginRate = 0vExpireDate = ''vMultiply, vPriceUnit, vMarginRate, vExpireDate = tvapi1.GetInstrumentInfo(self.ui.edtIns.text(), vMultiply, vPriceUnit, vMarginRate, vExpireDate)self.ui.textEdit_3.append("查詢合約:{} 合約乘數:{} 最小變動單位:{} 保證金比率:{} 合約到期日:{}\n".format(self.ui.edtIns.text(),vMultiply, vPriceUnit, vMarginRate, vExpireDate))elif (self.ui.rb1.isChecked()):tvapi1.GetPositionDetail(self.ui.edtIns.text())self.ui.textEdit_3.append("查詢合約:%s 持倉成交明細\n".format(self.ui.edtIns.text()))elif (self.ui.rb2.isChecked()):PreBalance = .0Balance = .0PreMargin =.0Available =.0WithdrawQuota =.0ExchangeMargin =.0CloseProfit =.0PositionProfit =.0PreBalance,Balance,PreMargin,Available,WithdrawQuota,ExchangeMargin,CloseProfit,PositionProfit = tvapi1.GetAccount(PreBalance,Balance,PreMargin,Available,WithdrawQuota,ExchangeMargin,CloseProfit ,PositionProfit)self.ui.textEdit_3.append("靜態權益:{0} 結算保證金:{1} 占用保證金:{2} 可用資金:{3} 可取資金:{4} 交易所保證金:{5} 平倉盈虧:{6} 持倉盈虧:{7}\n".format(PreBalance, Balance, PreMargin, Available, WithdrawQuota, ExchangeMargin,CloseProfit,PositionProfit))elif (self.ui.rb3.isChecked()):tvapi1.GetTradeInfo(self.ui.edtIns.text())self.ui.textEdit_3.append("查詢:{0} 成交信息\n".format(self.ui.edtIns.text()))elif (self.ui.rb4.isChecked()):tvapi1.SettlementInfoConfirm()self.ui.textEdit_3.append("確認結算單 !\n")elif (self.ui.rb5.isChecked()):vMultiply=0vPriceUnit=0vMarginRate=0vExpireDate=""tvapi1.GetInstrumentInfo("",vMultiply, vPriceUnit, vMarginRate, vExpireDate)self.ui.textEdit_3.append("查詢全市場合約\n")elif (self.ui.rb6.isChecked()):if (len(self.ui.edtorderid.text())==0):vOrderId = 0else:vOrderId = int(self.ui.edtorderid.text())vIsCanC = 0vIsCanC = tvapi1.IsOrderOpen(vOrderId,vIsCanC)self.ui.textEdit_3.append("訂單:{0} 是否可撤:{1} (0 :不可撤 1:可撤)\n".format(vOrderId,vIsCanC))elif (self.ui.rb7.isChecked()):lsp = 0ssp = 0lpp = .0spp=.0vd1=.0vd2=.0bid=.0ask=.0MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,lsp,vd1,lpp,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,ssp,vd2,spp,bid,ask = tvapi1.GetPositionPlus(self.ui.edtIns.text(),\MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,lsp,vd1,lpp,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,ssp,vd2,spp,bid,ask)self.ui.textEdit_3.append("{12} 多頭倉位:{0} 昨倉:{1} 凍結倉位:{2} 開倉掛起:{3} 持倉價格:{4} 持倉盈虧:{5} bid:{13} 空頭倉位:{6} 昨倉:{7} 凍結倉位:{8} 開倉掛起:{9} 持倉價格:{10} 持倉盈虧:{11} ask:{14}\n".\format(MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,lsp,vd1,lpp,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,ssp,vd2,spp,self.ui.edtIns.text(),bid,ask))elif (self.ui.rb8.isChecked()):vi1=0vi1 = tvapi1.GetHisOrderList("",vi1)#查詢歷史訂單信息 不為空查詢指定合約。self.ui.textEdit_3.append("查詢歷史訂單信息,返回值:{0} (0 :成功 1:查詢歷史訂單不成功 2:查詢全市場合約不成功)\n".format(vi1))elif (self.ui.rb9.isChecked()):YdClose = 0YdSettlement = 0Open = 0Last = 0Bid1 = 0Ask1 = 0Bid1Volume = 0Ask1Volume = 0Highest = 0Lowest = 0TradedVolume = 0TradedAmmount = 0YdClose, YdSettlement,Open,Last,Bid1,Ask1,Bid1Volume, Ask1Volume,Highest,Lowest,TradedVolume,TradedAmmount = tvapi1.GetMarketData(self.ui.edtIns.text(), YdClose, \YdSettlement,Open,Last,Bid1,Ask1,Bid1Volume, Ask1Volume,Highest,Lowest,TradedVolume,TradedAmmount)self.ui.textEdit_3.append("{0} YdClose:{1:.2f} YdSettlement:{2:.2f} Open:{3:.2f} Last:{4:.2f} Bid1:{5:.2f} Ask1:{6:.2f} Bid1Volume:{7} Ask1Volume:{8} Highest:{9:.2f} Lowest:{10:.2f} TradedVolume:{11} TradedAmmount:{12:.2f}\n".format(MyUseVar.sInstrumentID,YdClose, YdSettlement, Open, Last, Bid1, Ask1, Bid1Volume,Ask1Volume, Highest, Lowest,TradedVolume, TradedAmmount))elif (self.ui.rb10.isChecked()):tvapi1.PrintOrderInfo ()self.ui.textEdit_3.append("輸出信息到:{0} 目錄的{0}.txt文件中完成!\n".format(self.ui.UserName.text()))elif (self.ui.rb11.isChecked()):OpenRatioByMoney = 0.0OpenRatioByVolume = 0.0 CloseRatioByMoney = 0.0 CloseRatioByVolume = 0.0 CloseTodayRatioByMoney = 0.0 CloseTodayRatioByVolume = 0.0 OpenRatioByMoney,OpenRatioByVolume, CloseRatioByMoney, CloseRatioByVolume,CloseTodayRatioByMoney , CloseTodayRatioByVolume = tvapi1.GetInstrumentRatio(self.ui.edtIns.text(), OpenRatioByMoney,OpenRatioByVolume, CloseRatioByMoney,\CloseRatioByVolume,CloseTodayRatioByMoney , CloseTodayRatioByVolume)self.ui.textEdit_3.append('{0} OpenRatioByMoney:{1:.7f} OpenRatioByVolume:{2:.7f} CloseRatioByMoney:{3:.7f} CloseRatioByVolume:{4:.7f} CloseTodayRatioByMoney :{5:.7f} CloseTodayRatioByVolume:{6:.7f}'.format(self.ui.edtIns.text(), OpenRatioByMoney,OpenRatioByVolume, CloseRatioByMoney, CloseRatioByVolume, CloseTodayRatioByMoney , CloseTodayRatioByVolume))elif (self.ui.rb12.isChecked()):PreBalance = .0Balance = .0PreMargin =.0Available =.0WithdrawQuota =.0ExchangeMargin =.0CloseProfit =.0PositionProfit =.0PreBalance,Balance,PreMargin,Available,WithdrawQuota,ExchangeMargin,CloseProfit,PositionProfit = tvapi1.GetRealAccount(PreBalance,Balance,PreMargin,Available,WithdrawQuota,ExchangeMargin,CloseProfit ,PositionProfit)self.ui.textEdit_3.append("靜態權益:{0} 結算保證金:{1} 占用保證金:{2} 可用資金:{3} 可取資金:{4} 交易所保證金:{5} 平倉盈虧:{6} 持倉盈虧:{7}\n".format(PreBalance, Balance, PreMargin, Available, WithdrawQuota, ExchangeMargin,CloseProfit,PositionProfit))elif (self.ui.rb13.isChecked()):lsp = 0ssp = 0lpp = .0spp=.0vd1=.0vd2=.0bid=.0ask=.0MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,lsp,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,ssp = tvapi1.GetRealPosition(self.ui.edtIns.text(),\MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,lsp,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,ssp)self.ui.textEdit_3.append("{0} 多頭倉位:{1} 昨倉:{2} 凍結倉位:{3} 持倉價格:{4} 空頭倉位:{5} 昨倉:{6} 凍結倉位:{7} 持倉價格:{8} \n".\format(self.ui.edtIns.text(),MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,lsp,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,ssp))elif (self.ui.rb14.isChecked()):vOrderId = int(self.ui.edtorderid.text())vIsCanC = 0vIsCanC = tvapi1.CancelOrder(vOrderId, vIsCanC)self.ui.textEdit_3.append("訂單:{0} 撤單狀態:{1}【0:撤單成功 其它:撤單不成功】\n".format(vOrderId,vIsCanC))elif (self.ui.rb15.isChecked()):IsOk = 0Period = 1IsOk = tvapi1.CreateBars(self.ui.edtIns.text(),Period,IsOk)self.ui.textEdit_3.append("合約:{0} 創建{1}分鐘周期BARS完成:{2} 【1:創建成功 2:此周期已創建 -1:創建不成功】\n".format(self.ui.edtIns.text(),Period,IsOk))if (IsOk==2):IsOk = tvapi1.DeleteBars(self.ui.edtIns.text(),Period,IsOk)self.ui.textEdit_3.append("合約:{0} 刪除{1}分鐘周期BARS完成:{2} 【1:刪除成功 -1:刪除不成功】\n".format(self.ui.edtIns.text(),Period,IsOk))elif (self.ui.rb16.isChecked()):vMultiply = 0vPriceUnit = 0vMarginRate = 0vExpireDate = ''vMultiply, vPriceUnit, vMarginRate, vExpireDate = tvapi1.GetInstrumentInfoOut(self.ui.edtIns.text(), vMultiply, vPriceUnit, vMarginRate, vExpireDate)self.ui.textEdit_3.append("查詢合約:{} 合約乘數:{} 最小變動單位:{} 保證金比率:{} 合約到期日:{}\n".format(self.ui.edtIns.text(),vMultiply, vPriceUnit, vMarginRate, vExpireDate))elif (self.ui.rb17.isChecked()):vmaxi=0vopen=.0vhight=.0vclose=.0vlow=.0vvloumes=0vuptime=""tmppe=1counts=0vmaxi,vopen,vclose,vhight,vlow,vvloumes,counts,vuptime = tvapi1.GetBars(self.ui.edtIns.text(),tmppe,0,vmaxi,vopen,vclose,vhight,vlow,vvloumes,counts,vuptime)self.ui.textEdit_3.append("合約{}K線數據 周期:{} 計數器:{} 長度:{} 序號:{} open:{} vclose:{} vhight:{} vlow:{} vvloumes:{} counts{} vuptime:{}\n".format(self.ui.edtIns.text(),tmppe,counts,vmaxi,0,vopen,vclose,vhight,vlow,vvloumes,counts,vuptime))if (vmaxi>=1):for row in range(vmaxi):vmaxi,vopen,vclose,vhight,vlow,vvloumes,counts,vuptime = tvapi1.GetBars(self.ui.edtIns.text(),tmppe,row,vmaxi,vopen,vclose,vhight,vlow,vvloumes,counts,vuptime)self.ui.textEdit_3.append("合約{}K線數據 周期:{} 計數器:{} 長度:{} 序號:{} open:{} vclose:{} vhight:{} vlow:{} vvloumes:{} counts{} vuptime:{}\n".format(self.ui.edtIns.text(),tmppe,counts,vmaxi,row,vopen,vclose,vhight,vlow,vvloumes,counts,vuptime))elif (self.ui.rb18.isChecked()):vinfoid=0vinfo =""self.ui.textEdit_3.append("==========CZCE======添加蘋果AP2305合約交易時間段=========================\n")vinfoid,vinfo = tvapi1.AppendExchangeTradeTimes("CZCE","AP2305",9,0,75,0,vinfoid,vinfo); #開盤時間段 標志位是 0 收盤時間段標志位是9 其他為1self.ui.textEdit_3.append("添加{} 合約{}交易時間段{}:{} :{} vinfoid:{}\n".format("CZCE","AP2305",9,0,vinfo,vinfoid)) vinfoid,vinfo = tvapi1.AppendExchangeTradeTimes("CZCE","AP2305",10,30,60,1,vinfoid,vinfo); #開盤時間段 標志位是 0 收盤時間段標志位是9 其他為1self.ui.textEdit_3.append("添加{} 合約{}交易時間段{}:{} :{} vinfoid:{}\n".format("CZCE","AP2305",9,0,vinfo,vinfoid))vinfoid,vinfo = tvapi1.AppendExchangeTradeTimes("CZCE","AP2305",13,30,90,9,vinfoid,vinfo); #開盤時間段 標志位是 0 收盤時間段標志位是9 其他為1self.ui.textEdit_3.append("添加{} 合約{}交易時間段{}:{} :{} vinfoid:{}\n".format("CZCE","AP2305",9,0,vinfo,vinfoid)) self.ui.textEdit_3.append("==========CZCE======添加蘋果所有合約交易時間段=========================\n")vinfoid,vinfo = tvapi1.AppendExchangeTradeTimes("CZCE","AP999",9,0,75,0,vinfoid,vinfo); #開盤時間段 標志位是 0 收盤時間段標志位是9 其他為1self.ui.textEdit_3.append("添加{} 合約{}交易時間段{}:{} :{} vinfoid:{}\n".format("CZCE","AP999",9,0,vinfo,vinfoid)) vinfoid,vinfo = tvapi1.AppendExchangeTradeTimes("CZCE","AP999",10,30,60,1,vinfoid,vinfo); #開盤時間段 標志位是 0 收盤時間段標志位是9 其他為1self.ui.textEdit_3.append("添加{} 合約{}交易時間段{}:{} :{} vinfoid:{}\n".format("CZCE","AP999",9,0,vinfo,vinfoid))vinfoid,vinfo = tvapi1.AppendExchangeTradeTimes("CZCE","AP999",13,30,90,9,vinfoid,vinfo); #開盤時間段 標志位是 0 收盤時間段標志位是9 其他為1self.ui.textEdit_3.append("添加{} 合約{}交易時間段{}:{} :{} vinfoid:{}\n".format("CZCE","AP999",9,0,vinfo,vinfoid))self.ui.textEdit_3.append("==========CZCE======刪除合約蘋果2305交易時間段=========================\n")vinfoid,vinfo = tvapi1.DeleteExchangeTradeTimes("CZCE","AP2305",vinfoid,vinfo)self.ui.textEdit_3.append("刪除{} 合約{}交易時間段{}:{} :{} vinfoid:{}\n".format("CZCE","AP999",9,0,vinfo,vinfoid))elif (self.ui.rb19.isChecked()):self.ui.textEdit_3.append("==========SHFE======螺紋合約交易時間段=========================\n")tvapi1.GetOutExchangeTradeTimes("SHFE","rb9999") self.ui.textEdit_3.append('================獲取全部交易所全部合約交易時間段=========================')tvapi1.GetOutExchangeTradeTimes("","")# 查詢操作結束def printFunc_OuttextEdit(self,vstr): self.ms.text_OuttextEdit.emit(self.ui.textEdit_3,vstr)def pF_OuttextEdit(self,pt,vstr):#pt.append(vstr)def printFunc(self,vstr,vint): #登錄過程中查詢相關信息時的進度條顯示 線程調用顯示進度條。self.ms.text_print.emit(self.ui.label_7,self.ui.progressBar,vstr,vint)def pF(self,pt,pb,vstr,int1):pt.setText(vstr)pb.setValue(int1)def printFunc_MarketData(self,InstrumentID,LastPrice,Volume,BidPrice1,BidVolume1,AskPrice1,AskVolume1,BidPrice5,BidVolume5,AskPrice5,AskVolume5,UpdateTime): #訂閱行情推送信息的 線程調用刷新行情表格。self.ms.text_MarketData.emit(self.ui.tableView_4,InstrumentID,LastPrice,Volume,BidPrice1,BidVolume1,AskPrice1,AskVolume1,BidPrice5,BidVolume5,AskPrice5,AskVolume5,UpdateTime)def pF_MarketData(self,ptv,InstrumentID,LastPrice,Volume,BidPrice1,BidVolume1,AskPrice1,AskVolume1,BidPrice5,BidVolume5,AskPrice5,AskVolume5,UpdateTime):finded = 0findrow = -1tmpmodel = ptv.model()j = tmpmodel.rowCount()for row in range(j):if (tmpmodel.item(row,0).text()==InstrumentID or tmpmodel.item(row,0).text()==""):k = 0 for column in [InstrumentID,LastPrice,Volume,BidPrice1,BidVolume1,AskPrice1,AskVolume1,BidPrice5,BidVolume5,AskPrice5,AskVolume5,UpdateTime]:#item = QStandardItem(f"{column}")#tmpmodel.setItem(findrow,k,QStandardItem(f"{column}"))tmpmodel.item(row,k).setText(f"{column}")k = k+1finded = 1breakj = 0if (finded==0):item0 = QStandardItem('%s' % InstrumentID)item1 = QStandardItem('%.2f' % LastPrice)item2 = QStandardItem('%d' % Volume)item3 = QStandardItem('%.2f' % BidPrice1)item4 = QStandardItem('%d' % BidVolume1)item5 = QStandardItem('%.2f' % AskPrice1)item6 = QStandardItem('%d' % AskVolume1)item7 = QStandardItem('%.2f' % BidPrice5)item8 = QStandardItem('%d' % BidVolume5)item9 = QStandardItem('%.2f' % AskPrice5)item10 = QStandardItem('%d' % AskVolume5)item11 = QStandardItem('%s' % UpdateTime)tmpmodel.appendRow([item0,item1,item2,item3,item4,item5,item6,item7,item8,item9,item10,item11])def AppText(self,*args):try:self.ui.textEdit_3.append(str(args))except BaseException as e:traceback.print_exc()def AppText2(self,*args):try:self.ui.textEdit_3.append(str(args))except BaseException as e:traceback.print_exc()def AppText3(self,*args):try:self.ui.textEdit_3.append(str(args))except BaseException as e:traceback.print_exc()def Login(self): #登錄按鈕事件errmsg=""errid = 1errid,errmsg = tvapi1.Login("config.ini",self.ui.UserName.text(),self.ui.PassWord.text(),errid,errmsg)Mui.AppText([errid,errmsg])def LogOut(self):#退出登錄按鈕事件tvapi1.LogOut()self.ui.textEdit_3.clear()def bSubIns(self):tvapi1.SubscribeDepthMD(self.ui.edtIns.text());#訂閱深度五檔行情def bUnSubIns(self):tvapi1.UnSubscribeMD(self.ui.edtIns.text());#訂閱深度五檔行情def printFunc_OnOrder(self,vins): #根據訂單回報推送的合約信息 線程調用刷新此合約持倉數據表格。self.ms.text_OnOrder.emit(tvapi1,self.ui.gridpositions,vins)def pF_OnOrder(self,vtv,ptv,vins):LongPostion = 0LongYdPostion = 0LongFrozen = 0LongSuspendPostion = 0LPrice = 0.0LongProfit =0.0ShortPostion =0ShortYDPostion = 0ShortFrozen = 0ShortSuspendPostion = 0SPrice= 0.0shortfit= 0.0bidprice= 0.0askprice =0.0try:LongPostion, LongYdPostion, LongFrozen, LongSuspendPostion,LPrice,LongProfit,ShortPostion,ShortYDPostion,ShortFrozen,\ShortSuspendPostion,SPrice,shortfit,bidprice,askprice = vtv.GetPositionPlus(vins,LongPostion,\LongYdPostion, LongFrozen,LongSuspendPostion,LPrice,LongProfit,ShortPostion,ShortYDPostion,ShortFrozen,ShortSuspendPostion,SPrice,shortfit,bidprice,askprice)finded = 0findrow = -1tmpmodel = ptv.model()j = tmpmodel.rowCount()finded = 0for row in range(j):if (tmpmodel.item(row,0).text()==vins and tmpmodel.item(row,1).text()==" 賣"):k = 2for column in [ShortPostion,ShortYDPostion,ShortFrozen,ShortSuspendPostion,SPrice,shortfit]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row,k,item)tmpmodel.item(row,k).setText(f"{column}")k = k+1m = 2for column in [LongPostion, LongYdPostion, LongFrozen, LongSuspendPostion,LPrice,LongProfit]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row+1,m,item)tmpmodel.item(row+1,m).setText(f"{column}")m = m+1finded = 1breakif (tmpmodel.item(row,0).text()==""):k = 0for column in [vins," 賣",ShortPostion,ShortYDPostion,ShortFrozen,ShortSuspendPostion,SPrice,shortfit]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row,k,item)tmpmodel.item(row,k).setText(f"{column}")k = k+1m = 0for column in [vins,"買 ",LongPostion, LongYdPostion, LongFrozen, LongSuspendPostion,LPrice,LongProfit]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row+1,m,item)tmpmodel.item(row+1,m).setText(f"{column}")m = m+1finded = 1breakif (finded==0):item0 = QStandardItem('%s' % vins)item1 = QStandardItem('%s' % " 賣")item2 = QStandardItem('%d' % ShortPostion)item3 = QStandardItem('%d' % ShortYDPostion)item4 = QStandardItem('%d' % ShortFrozen)item5 = QStandardItem('%d' % ShortSuspendPostion)item6 = QStandardItem('%.2f' % SPrice)item7 = QStandardItem('%.2f' % shortfit)item8 = QStandardItem('%.2f' % bidprice)item9 = QStandardItem('%.2f' % askprice)tmpmodel.appendRow([item0,item1,item2,item3,item4,item5,item6,item7,item8,item9])item0 = QStandardItem('%s' % vins)item1 = QStandardItem('%s' % "買 ")item2 = QStandardItem('%d' % LongPostion)item3 = QStandardItem('%d' % LongYdPostion)item4 = QStandardItem('%d' % LongFrozen)item5 = QStandardItem('%d' % LongSuspendPostion)item6 = QStandardItem('%.2f' % LPrice)item7 = QStandardItem('%.2f' % LongProfit)item8 = QStandardItem('%.2f' % bidprice)item9 = QStandardItem('%.2f' % askprice)tmpmodel.appendRow([item0,item1,item2,item3,item4,item5,item6,item7,item8,item9])except BaseException as e:traceback.print_exc()def printFunc_PositionProfit(self): #每秒定時刷新持倉盈虧的 線程調用刷新持倉表格。self.ms.text_PositionProfit.emit(tvapi1,self.ui.gridpositions)def pF_PositionProfit(self,vtv,ptv):finded = 0findrow = -1tmpmodel = ptv.model()j = tmpmodel.rowCount()LongPostion = 0LongYdPostion = 0LongFrozen = 0LongSuspendPostion = 0LPrice = 0.0LongProfit =0.0ShortPostion =0ShortYDPostion = 0ShortFrozen = 0ShortSuspendPostion = 0SPrice= 0.0shortfit= 0.0bidprice= 0.0askprice =0.0for row in range(j):if (tmpmodel.item(row,1).text()==" 賣"):LongPostion, LongYdPostion, LongFrozen, LongSuspendPostion,LPrice,LongProfit,ShortPostion,ShortYDPostion,ShortFrozen,\ShortSuspendPostion,SPrice,shortfit,bidprice,askprice = vtv.GetPositionPlus(tmpmodel.item(row,0).text(),LongPostion,\LongYdPostion, LongFrozen,LongSuspendPostion,LPrice,LongProfit,ShortPostion,ShortYDPostion,ShortFrozen,ShortSuspendPostion,SPrice,shortfit,bidprice,askprice)k = 6for column in [SPrice,shortfit,bidprice,askprice]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row,k,item)tmpmodel.item(row,k).setText(f"{column}")k = k+1m = 6for column in [LPrice,LongProfit,bidprice,askprice]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row+1,m,item)tmpmodel.item(row+1,m).setText(f"{column}")m = m+1def printFunc_OnOrderLst(self,OrderID,OrderLocalID,OrderSysID,BrokerOrderSeq,InstrumentID,IsBuy,IsOpen,OrderStatus, Volume,TradedVolume,Price,ErrorID,InsertTime,ErrorMsg): #訂單回報信息推送后添加到訂單列表表格 的線程調用刷新訂單列表表格self.ms.text_OnOrderLst.emit(self.ui.tableView_2,OrderID,OrderLocalID,OrderSysID,BrokerOrderSeq,InstrumentID,IsBuy,IsOpen,OrderStatus, Volume,TradedVolume,Price,ErrorID,InsertTime,ErrorMsg)def pF_OnOrderLst(self,ptv,OrderID,OrderLocalID,OrderSysID,BrokerOrderSeq,InstrumentID,IsBuy,IsOpen,OrderStatus, Volume,TradedVolume,Price,ErrorID,InsertTime,ErrorMsg):if (IsBuy==0):tmpbuy = '買 'else:tmpbuy = ' 賣'if (IsOpen==0):tmpopen = '開 'else:tmpopen = ' 平'tmpmodel = ptv.model()j = tmpmodel.rowCount()finded = 0for row in range(j):if (tmpmodel.item(row,0).text()==""):k = 0for column in [OrderID,InstrumentID,IsBuy,IsOpen,Volume,TradedVolume,Price,Price,InsertTime,ErrorMsg]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row,k,item)tmpmodel.item(row,k).setText(f"{column}")k = k+1finded = 1breakif (tmpmodel.item(row,0).text()==str(OrderID)):k = 4for column in [Volume,TradedVolume,Price,Price,InsertTime,ErrorMsg]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(row,k,item)tmpmodel.item(row,k).setText(f"{column}")k = k+1finded = 1breakif (finded==0):"""item0 = QStandardItem('%d' % OrderID)item1 = QStandardItem('%s' % InstrumentID)item2 = QStandardItem('%s' % tmpbuy)item3 = QStandardItem('%s' % tmpopen)item4 = QStandardItem('%d' % Volume)item5 = QStandardItem('%d' % TradedVolume)item6 = QStandardItem('%.2f' % Price)item7 = QStandardItem('%.2f' % Price)item8 = QStandardItem('%s' % InsertTime)item9 = QStandardItem('%s' % ErrorMsg)"""#tmpmodel.appendRow([item0,item1,item2,item3,item4,item5,item6,item7,item8,item9])tmpmodel.insertRow(0,[QStandardItem('%d' % OrderID),QStandardItem('%s' % InstrumentID),QStandardItem('%s' % tmpbuy),QStandardItem('%s' % tmpopen),\QStandardItem('%d' % Volume),QStandardItem('%d' % TradedVolume),QStandardItem('%.2f' % Price),QStandardItem('%.2f' % Price),\QStandardItem('%s' % InsertTime),QStandardItem('%s' % ErrorMsg)])def printFunc_OutBars(self,InstrumentID,Period,Counts,Hight,Low,Open,Close,CreatTime): #獲取賬戶資金信息的線程調用賬戶資金表格self.ms.text_OutBars.emit(tvapi1,self.ui.textEdit_3,InstrumentID,Period,Counts,Hight,Low,Open,Close,CreatTime)def pF_OutBars(self,vtv,vedt3,InstrumentID,Period,Counts,Hight,Low,Open,Close,CreatTime):vedt3.append(str(["OnOutBars:",InstrumentID,"周期",Period,"計數器",Counts,"最高",Hight,"最低",Low,"開",Open,"平",Close,"時間",CreatTime]))ma10 = .0 ma10 = vtv.MA(InstrumentID,Period,10,ma10);ema12 = .0 ema12 = vtv.EMA(InstrumentID,Period,12,ema12);ema26 = .0 ema26 = vtv.EMA(InstrumentID,Period,26,ema26);diff1 = .0dea1 = .0macd1 = MyUseVar.MinDoublediff1,dea1 = vtv.MACD(InstrumentID,Period,diff1,dea1);if ((diff1>MyUseVar.MinDouble) and (dea1>MyUseVar.MinDouble)):macd1 = 2*(diff1-dea1)Defdiff1 = .0Defdea1 = .0Defmacd1 = MyUseVar.MinDoubleDefdiff1,Defdea1 = vtv.DefMACD(InstrumentID,Period,12,26,9,Defdiff1,Defdea1);if ((Defdiff1>MyUseVar.MinDouble) and (Defdea1>MyUseVar.MinDouble)):Defmacd1 = 2*(Defdiff1-Defdea1)vedt3.append("InstrumentID:{0} Period:{1} Ma10:{2} ---macd:{3} ---diff:{4} ---dea:{5} ema12:{6} ema26:{7}\n".format(InstrumentID, Period, ma10,macd1,diff1,dea1,ema12,ema26))vedt3.append("InstrumentID:{0} Period:{1} Ma10:{2} Defmacd:{3} Defdiff:{4} Defdea:{5} ema12:{6} ema26:{7}\n".format(InstrumentID, Period, ma10, Defmacd1,Defdiff1,Defdea1,ema12,ema26))def printFunc_Account(self): #獲取賬戶資金信息的線程調用賬戶資金表格self.ms.text_Account.emit(tvapi1,self.ui.tableView,self.ui.label_10)def pF_Account(self,vtv,ptv,vlab):vlab.setText("當前時間:%s" % time.strftime("%Y-%m_%d %H:%M:%S",time.localtime()))PreBalance = .0Balance = .0PreMargin =.0Available =.0WithdrawQuota =.0ExchangeMargin =.0CloseProfit =.0PositionProfit =.0tmpmodel = ptv.model()j = 0PreBalance,Balance,PreMargin,Available,WithdrawQuota,ExchangeMargin,CloseProfit,PositionProfit = vtv.GetAccount(PreBalance,Balance,PreMargin,Available,WithdrawQuota,ExchangeMargin,CloseProfit ,PositionProfit)for column in [PreBalance,Balance,PreMargin,Available,WithdrawQuota,ExchangeMargin ,PositionProfit,CloseProfit]:#item = QStandardItem(f"{column}") #持續增加內存 不采用。#tmpmodel.setItem(0,j,item)tmpmodel.item(0,j).setText(f"{column}")j = j+1ptv.resizeColumnsToContents()def btnopencloseclick(self):MyUseVar.BeginOpenClose = 1 - MyUseVar.BeginOpenClose if (MyUseVar.BeginOpenClose==0):self.ui.btnopenclose.setText("開始進行循環開平倉測試")else:self.ui.btnopenclose.setText("停止進行循環開平倉測試")tvapi1.SubscribeDepthMD(self.ui.edtIns.text());#訂閱深度五檔行情#=============OnTmr()===================以下代碼為定時刷新賬戶資金、持倉盈虧數據及循環開平倉操作代碼====================================================#def OnInitFinished(self):事件中啟用printFunc_OpenClose線程循環def printFunc_OpenClose(self): #登錄過程中查詢相關信息時的進度條顯示 線程調用顯示進度條。while True:#print("Interval:",MyUseVar.Interval,"BeginOpenClose:",MyUseVar.BeginOpenClose,"RunFlag:",MyUseVar.RunFlag,"vWaitCancleInt:",MyUseVar.vWaitCancleInt,"vWaitOrderInt:",MyUseVar.vWaitOrderInt)time.sleep(MyUseVar.Interval)#延時1秒 #延時50毫秒#print("vWaitInOrder:",MyUseVar.vWaitInOrder,"BeginOpenClose:",MyUseVar.BeginOpenClose,"RunFlag:",MyUseVar.RunFlag,"vWaitCancleInt:",MyUseVar.vWaitCancleInt,"vWaitOrderInt:",MyUseVar.vWaitOrderInt)if (MyUseVar.RunFlag==1 and MyUseVar.BeginOpenClose==1):self.ms.text_OpenClose.emit(tvapi1,self.ui.textEdit) #加入此代碼后循環中占用內存會逐步增大,不知為何NewSec = time.strftime("%S",time.localtime())if (MyUseVar.RefSec!=NewSec):MyUseVar.RefSec = NewSecif (MyUseVar.RunFlag==1):self.ms.text_Account.emit(tvapi1,self.ui.tableView,self.ui.label_10) #加入此代碼后循環中占用內存會逐步增大,不知為何self.ms.text_PositionProfit.emit(tvapi1,self.ui.gridpositions) #加入此代碼后循環中占用內存會逐步增大,不知為何#self.snapshot2 = tracemalloc.take_snapshot() #建立一個新的內存快照#self.top_stats = self.snapshot2.compare_to(self.snapshot1, 'lineno') #比較兩個內存快照#for stat in self.top_stats[:10]: #打印內存快照區別# print(stat)def pF_OpenClose(self,vtv,vte):MyUseVar.sInstrumentID = self.ui.edtIns.text()if (MyUseVar.vloop==0): #獲取持倉倉位 訂單是否可撤 vd1=.0vd2=.0vte.append("===================================================================================")MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,\vd1,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,vd2 = vtv.GetPosition(MyUseVar.sInstrumentID,\MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,\MyUseVar.MyPostion.LongFrozen,vd1,MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,vd2)vte.append("{6} 多頭倉位:{0} 昨倉:{1} 凍結倉位:{2} 空頭倉位:{3} 昨倉:{4} 凍結倉位:{5}".\format(MyUseVar.MyPostion.LongPostion,MyUseVar.MyPostion.LongYDPostion,MyUseVar.MyPostion.LongFrozen,\MyUseVar.MyPostion.ShortPostion,MyUseVar.MyPostion.ShortYDPostion,\MyUseVar.MyPostion.ShortFrozen,MyUseVar.sInstrumentID))MyUseVar.vIsCanC = 0MyUseVar.vIsCanC1 = 0MyUseVar.vIsCanC2 = 0MyUseVar.vIsCanC3 = 0if (MyUseVar.MyPostion.LongOrder > 0 or MyUseVar.MyPostion.LongOrder1 > 0 orMyUseVar.MyPostion.ShortOrder > 0 or MyUseVar.MyPostion.ShortOrder1 > 0 ): #有訂單號時 判斷是否有可撤訂單if (MyUseVar.MyPostion.LongOrder>0):MyUseVar.vIsCanC = vtv.IsOrderOpen(MyUseVar.MyPostion.LongOrder,MyUseVar.vIsCanC);vte.append("LongOrder訂單:{0} 是否可撤:{1} (0 :不可撤 1:可撤)".format(MyUseVar.MyPostion.LongOrder,MyUseVar.vIsCanC))if (MyUseVar.MyPostion.LongOrder1>0):MyUseVar.vIsCanC1 = vtv.IsOrderOpen(MyUseVar.MyPostion.LongOrder1,MyUseVar.vIsCanC1);vte.append("LongOrder1訂單:{0} 是否可撤:{1} (0 :不可撤 1:可撤)".format(MyUseVar.MyPostion.LongOrder1,MyUseVar.vIsCanC1))if (MyUseVar.MyPostion.ShortOrder>0):MyUseVar.vIsCanC2 = vtv.IsOrderOpen(MyUseVar.MyPostion.ShortOrder,MyUseVar.vIsCanC2);vte.append("ShortOrder訂單:{0} 是否可撤:{1} (0 :不可撤 1:可撤)".format(MyUseVar.MyPostion.ShortOrder,MyUseVar.vIsCanC2))if (MyUseVar.MyPostion.ShortOrder1>0):MyUseVar.vIsCanC3 = vtv.IsOrderOpen(MyUseVar.MyPostion.ShortOrder1,MyUseVar.vIsCanC3);vte.append("ShortOrder1訂單:{0} 是否可撤:{1} (0 :不可撤 1:可撤)".format(MyUseVar.MyPostion.ShortOrder1,MyUseVar.vIsCanC3))#結束判斷訂單是否可撤if (MyUseVar.vIsCanC==1 or MyUseVar.vIsCanC1==1 or MyUseVar.vIsCanC2==1 or MyUseVar.vIsCanC3==1 ):MyUseVar.vloop = 1else:MyUseVar.vloop = 4#結束vloop=0 步驟if (MyUseVar.vloop==1): #有訂單可撤時 等待時間MyUseVar.vWaitInCancle = MyUseVar.vWaitInCancle +1if (MyUseVar.vWaitInCancle>=MyUseVar.vWaitCancleInt):MyUseVar.vWaitInCancle = 0MyUseVar.vloop = 2#結束判斷撤單后時間間隔#結束vloop=1 步驟if (MyUseVar.vloop==2): #有訂單可撤 撤單if (MyUseVar.vIsCanC==1): #longorder可撤vtv.CancelOrder(MyUseVar.MyPostion.LongOrder, MyUseVar.vIsCanC)vte.append("LongOrder訂單:{0} 空頭撤單 狀態:{1}【0:撤單成功 其它:撤單不成功】".format(MyUseVar.MyPostion.LongOrder,MyUseVar.vIsCanC))if (MyUseVar.vIsCanC1==1): #longorder可撤vtv.CancelOrder(MyUseVar.MyPostion.LongOrder1, MyUseVar.vIsCanC)vte.append("LongOrder1訂單:{0} 空頭撤單 狀態:{1}【0:撤單成功 其它:撤單不成功】".format(MyUseVar.MyPostion.LongOrder1,MyUseVar.vIsCanC))if (MyUseVar.vIsCanC2==1): #longorder可撤vtv.CancelOrder(MyUseVar.MyPostion.ShortOrder, MyUseVar.vIsCanC)vte.append("ShortOrder訂單:{0} 空頭撤單 狀態:{1}【0:撤單成功 其它:撤單不成功】".format(MyUseVar.MyPostion.ShortOrder,MyUseVar.vIsCanC))if (MyUseVar.vIsCanC3==1): #longorder可撤vtv.CancelOrder(MyUseVar.MyPostion.ShortOrder1, MyUseVar.vIsCanC)vte.append("ShortOrder1訂單:{0} 空頭撤單 狀態:{1}【0:撤單成功 其它:撤單不成功】".format(MyUseVar.MyPostion.ShortOrder1,MyUseVar.vIsCanC))MyUseVar.vloop=3#有訂單可撤 撤單結束 vloop==2if (MyUseVar.vloop==3): #有訂單可撤時 等待時間MyUseVar.vWaitInCancle = MyUseVar.vWaitInCancle +1if (MyUseVar.vWaitInCancle>=MyUseVar.vWaitCancleInt):MyUseVar.vWaitInCancle = 0MyUseVar.vloop = 4#結束判斷撤單后時間間隔#結束vloop=1 步驟if (MyUseVar.vloop==4): #循環開平倉開始 random.randint(1,10)vrandtvol = random.randint(1,MyUseVar.vVolT) # 產生隨機開平倉手數量#==================多頭開平倉操作=================================if (MyUseVar.MyPostion.LongPostion>0 and MyUseVar.MyPostion.LongPostion<vrandtvol):if (MyUseVar.MyPostion.LongOrderFlag == 1 ) :#上次平倉vrandvol = random.randint(1,MyUseVar.MyPostion.LongPostion); # 產生隨機開平倉手數量MyUseVar.MyPostion.LongOrder, MyUseVar.MyPostion.LongOrder1 = vtv.Sell(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyBidPrice, MyUseVar.MyPostion.LongOrder, MyUseVar.MyPostion.LongOrder1)vte.append("訂單:{0} 訂單:{2} 繼續平多頭倉位:{1} 價格:{3:.2f}".format(MyUseVar.MyPostion.LongOrder,vrandvol, MyUseVar.MyPostion.LongOrder1,MyUseVar.vMyBidPrice))else: # MyPostion.LongOrderFlag != 1時vrandvol = random.randint(1,MyUseVar.vVolT); # 產生隨機開平倉手數量MyUseVar.MyPostion.LongOrder = vtv.Buy(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyAskPrice, MyUseVar.MyPostion.LongOrder)vte.append("訂單:{0} 繼續多頭買開倉:{1} 價格:{2:.2f}".format(MyUseVar.MyPostion.LongOrder,vrandvol,MyUseVar.vMyAskPrice))#結束 上次平倉 MyPostion.LongOrderFlag = 1else: # 條件:MyPostion.LongPostion>0 and MyPostion.LongPostion<vrandtvol不成立 時if (MyUseVar.MyPostion.LongPostion>vrandtvol):# 持倉量多 平多頭多余倉位vrandvol = random.randint(1,vrandtvol);MyUseVar.MyPostion.LongOrder, MyUseVar.MyPostion.LongOrder1 = vtv.Sell(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyBidPrice,MyUseVar.MyPostion.LongOrder, MyUseVar.MyPostion.LongOrder1)vte.append("訂單:{0} 訂單:{2} 平多頭多余倉位:{1} 價格:{3:.2f}".format(MyUseVar.MyPostion.LongOrder,vrandvol, MyUseVar.MyPostion.LongOrder1,MyUseVar.vMyBidPrice))# 結束 MyPostion.LongPostion>vrandtvolif (MyUseVar.MyPostion.LongPostion<=0): #無持倉時vrandvol = random.randint(1,MyUseVar.vVolT);MyUseVar.MyPostion.LongOrder = vtv.Buy(MyUseVar.sInstrumentID, vrandvol ,MyUseVar.vMyAskPrice, MyUseVar.MyPostion.LongOrder)vte.append("訂單:{0} 多頭買開倉:{1} 價格:{2:.2f}".format(MyUseVar.MyPostion.LongOrder,vrandvol,MyUseVar.vMyAskPrice ))# 結束 無持倉時if ((MyUseVar.MyPostion.LongPostion<=vrandtvol) and (MyUseVar.MyPostion.LongPostion>0)):vrandvol = random.randint(1,MyUseVar.MyPostion.LongPostion);MyUseVar.MyPostion.LongOrder, MyUseVar.MyPostion.LongOrder1 = vtv.Sell(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyBidPrice, MyUseVar.MyPostion.LongOrder, MyUseVar.MyPostion.LongOrder1)MyUseVar.MyPostion.LongOrderFlag = 1;vte.append("訂單:{0} 訂單:{2} 多頭平倉:{1} 價格:{3:.2f}".format(MyUseVar.MyPostion.LongOrder,vrandvol , MyUseVar.MyPostion.LongOrder1,MyUseVar.vMyBidPrice))# 結束 持倉時#結束 (MyPostion.LongPostion>0 and MyPostion.LongPostion<vrandtvol):#==================多頭開平倉操作=================================#==================空頭開平倉操作=================================if (MyUseVar.MyPostion.ShortPostion>0 and MyUseVar.MyPostion.ShortPostion<vrandtvol):if (MyUseVar.MyPostion.ShortOrderFlag == 1 ) :#上次平倉vrandvol = random.randint(1,MyUseVar.MyPostion.ShortPostion); # 產生隨機開平倉手數量MyUseVar.MyPostion.ShortOrder, MyUseVar.MyPostion.ShortOrder1 = vtv.Cover(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyAskPrice, MyUseVar.MyPostion.ShortOrder, MyUseVar.MyPostion.ShortOrder1)vte.append("訂單:{0} 訂單:{2} 繼續平空頭倉位:{1} 價格:{3:.2f}".format(MyUseVar.MyPostion.ShortOrder,vrandvol, MyUseVar.MyPostion.ShortOrder1,MyUseVar.vMyAskPrice))else: # MyPostion.ShortOrderFlag != 1時vrandvol = random.randint(1,MyUseVar.vVolT); # 產生隨機開平倉手數量MyUseVar.MyPostion.ShortOrder = vtv.Short(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyBidPrice, MyUseVar.MyPostion.ShortOrder)vte.append("訂單:{0} 繼續空頭賣開倉:{1} 價格:{2:.2f}".format(MyUseVar.MyPostion.ShortOrder,vrandvol,MyUseVar.vMyBidPrice))#結束 上次平倉 MyPostion.ShortOrderFlag = 1else: # 條件:MyPostion.ShortPostion>0 and MyPostion.ShortPostion<vrandtvol不成立 時if (MyUseVar.MyPostion.ShortPostion>vrandtvol):# 持倉量多 平多頭多余倉位vrandvol = random.randint(1,vrandtvol);MyUseVar.MyPostion.ShortOrder, MyUseVar.MyPostion.ShortOrder1 = vtv.Cover(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyAskPrice,MyUseVar.MyPostion.ShortOrder, MyUseVar.MyPostion.ShortOrder1)vte.append("訂單:{0} 訂單:{2} 平空頭多余倉位:{1} 價格:{3:.2f}".format(MyUseVar.MyPostion.ShortOrder,vrandvol, MyUseVar.MyPostion.ShortOrder1,MyUseVar.vMyAskPrice))# 結束 MyPostion.ShortPostion>vrandtvolif (MyUseVar.MyPostion.ShortPostion<=0): #無持倉時vrandvol = random.randint(1,MyUseVar.vVolT);MyUseVar.MyPostion.ShortOrder = vtv.Short(MyUseVar.sInstrumentID, vrandvol ,MyUseVar.vMyBidPrice, MyUseVar.MyPostion.ShortOrder)vte.append("訂單:{0} 空頭賣開倉:{1} 價格:{2:.2f}".format(MyUseVar.MyPostion.ShortOrder,vrandvol,MyUseVar.vMyBidPrice ))# 結束 無持倉時if ((MyUseVar.MyPostion.ShortPostion<=vrandtvol) and (MyUseVar.MyPostion.ShortPostion>0)):vrandvol = random.randint(1,MyUseVar.MyPostion.ShortPostion);MyUseVar.MyPostion.ShortOrder, MyUseVar.MyPostion.ShortOrder1 = vtv.Cover(MyUseVar.sInstrumentID, vrandvol,MyUseVar.vMyAskPrice, MyUseVar.MyPostion.ShortOrder, MyUseVar.MyPostion.ShortOrder1)MyUseVar.MyPostion.ShortOrderFlag = 1;vte.append("訂單:{0} 訂單:{2} 空頭平倉:{1} 價格:{3:.2f}".format(MyUseVar.MyPostion.ShortOrder,vrandvol , MyUseVar.MyPostion.ShortOrder1,MyUseVar.vMyAskPrice))# 結束 持倉時#結束 (MyPostion.ShortPostion>0 and MyPostion.ShortPostion<vrandtvol):#==================空頭開平倉操作=================================MyUseVar.vloop = 5#結束循環開平倉 vloop=4 步驟if (MyUseVar.vloop==5): #有等待時間MyUseVar.vWaitInOrder = MyUseVar.vWaitInOrder +1if (MyUseVar.vWaitInOrder>=MyUseVar.vWaitOrderInt):MyUseVar.vWaitInOrder = 0MyUseVar.vloop = 0vte.append("===================================================================================")#結束時間間隔#結束vloop=5 步驟 pass#try:#except BaseException as e:# traceback.print_exc()#=============OnTmr()===================以上代碼為定時刷新賬戶資金、持倉盈虧數據及循環開平倉操作代碼====================================================if __name__ == "__main__":app = QApplication([])#sys.argv#MainWindow = QtWidgets.QMainWindow()Mui = Ui_UiMainWindow()Mui.ui.show()Mui.ui.textEdit_3.append("QQ:426075")tvapi1 = win32com.client.DispatchWithEvents("TVQhtICtpClientAPI.com.1",myevents) #創建CTPCOM組件實例 并將事件回調映射到自定義類事件中sys.exit(app.exec_())#app.exec_() # -*- coding: mbcs -*- # Created by makepy.py version 0.5.01 # By python version 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] # From type library 'TopViewQHTCtpCom.dll' # On Mon Jan 16 09:54:20 2023 '' makepy_version = '0.5.01' python_version = 0x30a01f0import win32com.client.CLSIDToClass, pythoncom, pywintypes import win32com.client.util from pywintypes import IID from win32com.client import Dispatch# The following 3 lines may need tweaking for the particular server # Candidates are pythoncom.Missing, .Empty and .ArgNotFound defaultNamedOptArg=pythoncom.Empty defaultNamedNotOptArg=pythoncom.Empty defaultUnnamedArg=pythoncom.EmptyCLSID = IID('{22113AE6-06DA-4875-AE8A-1F4AE4219D3B}') MajorVersion = 1 MinorVersion = 0 LibraryFlags = 8 LCID = 0x0from win32com.client import DispatchBaseClass class ITVQhtICtpClientAPI(DispatchBaseClass):CLSID = IID('{FD3E2400-1A18-45E4-8DAF-DE8840F22C8D}')coclass_clsid = IID('{4F356EF1-932E-48D1-B7A4-CFDE79752627}')def About(self):return self._oleobj_.InvokeTypes(20, LCID, 1, (24, 0), (),)def AppendExchangeTradeTimes(self, ExchangeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, hour=defaultNamedNotOptArg, minute=defaultNamedNotOptArg, TradeTimes=defaultNamedNotOptArg, Flag=defaultNamedNotOptArg, InfoID=pythoncom.Missing, InfoMsg=pythoncom.Missing):return self._ApplyTypes_(40, 1, (24, 0), ((8, 1), (8, 1), (3, 1), (3, 1), (3, 1), (3, 1), (16387, 2), (16392, 2)), 'AppendExchangeTradeTimes', None,ExchangeID, InstrumentID, hour, minute, TradeTimes, Flag, InfoID, InfoMsg)def Buy(self, pszInstrumentID=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, OrderID=pythoncom.Missing):return self._ApplyTypes_(6, 1, (24, 0), ((8, 1), (3, 1), (5, 1), (16387, 2)), 'Buy', None,pszInstrumentID, Volume, Price, OrderID)def CancelOrder(self, OrderID=defaultNamedNotOptArg, Status=pythoncom.Missing):return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), (16387, 2)), 'CancelOrder', None,OrderID, Status)def Cover(self, pszInstrumentID=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, OrderID=pythoncom.Missing, OrderID1=pythoncom.Missing):return self._ApplyTypes_(8, 1, (24, 0), ((8, 1), (3, 1), (5, 1), (16387, 2), (16387, 2)), 'Cover', None,pszInstrumentID, Volume, Price, OrderID, OrderID1)def CreateBars(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, Counts=pythoncom.Missing, IsOk=pythoncom.Missing):return self._ApplyTypes_(32, 1, (24, 0), ((8, 1), (3, 1), (16387, 2), (16387, 2)), 'CreateBars', None,InstrumentID, Period, Counts, IsOk)def DefMACD(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, Fast=defaultNamedNotOptArg, Slow=defaultNamedNotOptArg, Signal=defaultNamedNotOptArg, Diff=pythoncom.Missing, Dea=pythoncom.Missing):return self._ApplyTypes_(38, 1, (24, 0), ((8, 1), (3, 1), (3, 1), (3, 1), (3, 1), (16389, 2), (16389, 2)), 'DefMACD', None,InstrumentID, Period, Fast, Slow, Signal, Diff, Dea)def DeleteBars(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, IsOk=pythoncom.Missing):return self._ApplyTypes_(33, 1, (24, 0), ((8, 1), (3, 1), (16387, 2)), 'DeleteBars', None,InstrumentID, Period, IsOk)def DeleteExchangeTradeTimes(self, ExchangeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, InfoID=pythoncom.Missing, InfoMsg=pythoncom.Missing):return self._ApplyTypes_(41, 1, (24, 0), ((8, 1), (8, 1), (16387, 2), (16392, 2)), 'DeleteExchangeTradeTimes', None,ExchangeID, InstrumentID, InfoID, InfoMsg)def EMA(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, Counts=defaultNamedNotOptArg, EMA=pythoncom.Missing):return self._ApplyTypes_(35, 1, (24, 0), ((8, 1), (3, 1), (3, 1), (16389, 2)), 'EMA', None,InstrumentID, Period, Counts, EMA)def Free(self):return self._oleobj_.InvokeTypes(22, LCID, 1, (24, 0), (),)def GetAPIVersion(self):# Result is a Unicode objectreturn self._oleobj_.InvokeTypes(3, LCID, 1, (8, 0), (),)def GetAccount(self, PreBalance=pythoncom.Missing, Balance=pythoncom.Missing, PreMargin=pythoncom.Missing, Available=pythoncom.Missing, WithdrawQuota=pythoncom.Missing, ExchangeMargin=pythoncom.Missing, CloseProfit=pythoncom.Missing, PositionProfit=pythoncom.Missing):return self._ApplyTypes_(14, 1, (24, 0), ((16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2)), 'GetAccount', None,PreBalance, Balance, PreMargin, Available, WithdrawQuota, ExchangeMargin, CloseProfit, PositionProfit)def GetBars(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, index=defaultNamedNotOptArg, Max=pythoncom.Missing, Open=pythoncom.Missing, Close=pythoncom.Missing, Hight=pythoncom.Missing, Low=pythoncom.Missing, Volume=pythoncom.Missing, Counts=pythoncom.Missing, UpdateTime=pythoncom.Missing):return self._ApplyTypes_(39, 1, (24, 0), ((8, 1), (3, 1), (3, 1), (16387, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16387, 2), (16387, 2), (16392, 2)), 'GetBars', None,InstrumentID, Period, index, Max, Open, Close, Hight, Low, Volume, Counts, UpdateTime)def GetHisOrderList(self, InstrumentID=defaultNamedNotOptArg, GetFlag=pythoncom.Missing):return self._ApplyTypes_(18, 1, (24, 0), ((8, 1), (16387, 2)), 'GetHisOrderList', None,InstrumentID, GetFlag)def GetInstrumentInfo(self, InstrumentID=defaultNamedNotOptArg, Multiply=pythoncom.Missing, PriceUnit=pythoncom.Missing, MarginRate=pythoncom.Missing, ExpireDate=pythoncom.Missing):return self._ApplyTypes_(12, 1, (24, 0), ((8, 1), (16389, 2), (16389, 2), (16389, 2), (16392, 2)), 'GetInstrumentInfo', None,InstrumentID, Multiply, PriceUnit, MarginRate, ExpireDate)def GetInstrumentInfoOut(self, InstrumentID=defaultNamedNotOptArg, Multiply=pythoncom.Missing, PriceUnit=pythoncom.Missing, MarginRate=pythoncom.Missing, ExpireDate=pythoncom.Missing):return self._ApplyTypes_(37, 1, (24, 0), ((8, 1), (16389, 2), (16389, 2), (16389, 2), (16392, 2)), 'GetInstrumentInfoOut', None,InstrumentID, Multiply, PriceUnit, MarginRate, ExpireDate)def GetInstrumentRatio(self, InstrumentID=defaultNamedNotOptArg, OpenRatioByMoney=pythoncom.Missing, OpenRatioByVolume=pythoncom.Missing, CloseRatioByMoney=pythoncom.Missing, CloseRatioByVolume=pythoncom.Missing, CloseTodayRatioByMoney=pythoncom.Missing, CloseTodayRatioByVolume=pythoncom.Missing):return self._ApplyTypes_(26, 1, (24, 0), ((8, 1), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2)), 'GetInstrumentRatio', None,InstrumentID, OpenRatioByMoney, OpenRatioByVolume, CloseRatioByMoney, CloseRatioByVolume, CloseTodayRatioByMoney, CloseTodayRatioByVolume)def GetMarketData(self, InstrumentID=defaultNamedNotOptArg, YdClose=pythoncom.Missing, YdSettlement=pythoncom.Missing, Open=pythoncom.Missing, Last=pythoncom.Missing, Bid1=pythoncom.Missing, Ask1=pythoncom.Missing, Bid1Volume=pythoncom.Missing, Ask1Volume=pythoncom.Missing, Highest=pythoncom.Missing, Lowest=pythoncom.Missing, TradedVolume=pythoncom.Missing, TradedAmmount=pythoncom.Missing):return self._ApplyTypes_(23, 1, (24, 0), ((8, 1), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16387, 2), (16387, 2), (16389, 2), (16389, 2), (16387, 2), (16389, 2)), 'GetMarketData', None,InstrumentID, YdClose, YdSettlement, Open, Last, Bid1, Ask1, Bid1Volume, Ask1Volume, Highest, Lowest, TradedVolume, TradedAmmount)def GetOutExchangeTradeTimes(self, ExchangeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg):return self._oleobj_.InvokeTypes(42, LCID, 1, (24, 0), ((8, 1), (8, 1)),ExchangeID, InstrumentID)def GetPosition(self, InstrumentID=defaultNamedNotOptArg, LongPosition=pythoncom.Missing, LongYdPosition=pythoncom.Missing, LongFrozen=pythoncom.Missing, LongPositionPrice=pythoncom.Missing, ShortPosition=pythoncom.Missing, ShortYdPosition=pythoncom.Missing, ShortFrozen=pythoncom.Missing, ShortPositionPrice=pythoncom.Missing):return self._ApplyTypes_(17, 1, (24, 0), ((8, 1), (16387, 2), (16387, 2), (16387, 2), (16389, 2), (16387, 2), (16387, 2), (16387, 2), (16389, 2)), 'GetPosition', None,InstrumentID, LongPosition, LongYdPosition, LongFrozen, LongPositionPrice, ShortPosition, ShortYdPosition, ShortFrozen, ShortPositionPrice)def GetPositionDetail(self, InstrumentID=defaultNamedNotOptArg):return self._oleobj_.InvokeTypes(13, LCID, 1, (24, 0), ((8, 1),),InstrumentID)def GetPositionPlus(self, InstrumentID=defaultNamedNotOptArg, LongPosition=pythoncom.Missing, LongYdPosition=pythoncom.Missing, LongFrozen=pythoncom.Missing, LongSuspendPostion=pythoncom.Missing, LongPositionPrice=pythoncom.Missing, LongPositionProfit=pythoncom.Missing, ShortPosition=pythoncom.Missing, ShortYdPosition=pythoncom.Missing, ShortFrozen=pythoncom.Missing, ShortSuspendPostion=pythoncom.Missing, ShortPositionPrice=pythoncom.Missing, ShortPositionProfit=pythoncom.Missing, BidPrice=pythoncom.Missing, AskPrice=pythoncom.Missing):return self._ApplyTypes_(31, 1, (24, 0), ((8, 1), (16387, 2), (16387, 2), (16387, 2), (16387, 2), (16389, 2), (16389, 2), (16387, 2), (16387, 2), (16387, 2), (16387, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2)), 'GetPositionPlus', None,InstrumentID, LongPosition, LongYdPosition, LongFrozen, LongSuspendPostion, LongPositionPrice, LongPositionProfit, ShortPosition, ShortYdPosition, ShortFrozen, ShortSuspendPostion, ShortPositionPrice, ShortPositionProfit, BidPrice, AskPrice)def GetRealAccount(self, PreBalance=pythoncom.Missing, Balance=pythoncom.Missing, PreMargin=pythoncom.Missing, Available=pythoncom.Missing, WithdrawQuota=pythoncom.Missing, ExchangeMargin=pythoncom.Missing, CloseProfit=pythoncom.Missing, PositionProfit=pythoncom.Missing):return self._ApplyTypes_(27, 1, (24, 0), ((16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2), (16389, 2)), 'GetRealAccount', None,PreBalance, Balance, PreMargin, Available, WithdrawQuota, ExchangeMargin, CloseProfit, PositionProfit)def GetRealPosition(self, InstrumentID=defaultNamedNotOptArg, LongPosition=pythoncom.Missing, LongYdPosition=pythoncom.Missing, LongFrozen=pythoncom.Missing, LongPositionPrice=pythoncom.Missing, ShortPosition=pythoncom.Missing, ShortYdPosition=pythoncom.Missing, ShortFrozen=pythoncom.Missing, ShortPositionPrice=pythoncom.Missing):return self._ApplyTypes_(28, 1, (24, 0), ((8, 1), (16387, 2), (16387, 2), (16387, 2), (16389, 2), (16387, 2), (16387, 2), (16387, 2), (16389, 2)), 'GetRealPosition', None,InstrumentID, LongPosition, LongYdPosition, LongFrozen, LongPositionPrice, ShortPosition, ShortYdPosition, ShortFrozen, ShortPositionPrice)def GetTradeInfo(self, InstrumentID=defaultNamedNotOptArg):return self._oleobj_.InvokeTypes(15, LCID, 1, (24, 0), ((8, 1),),InstrumentID)def GetTradingDay(self):# Result is a Unicode objectreturn self._oleobj_.InvokeTypes(10, LCID, 1, (8, 0), (),)def IsOrderOpen(self, OrderID=defaultNamedNotOptArg, CanCacel=pythoncom.Missing):return self._ApplyTypes_(11, 1, (24, 0), ((3, 1), (16387, 2)), 'IsOrderOpen', None,OrderID, CanCacel)def LogOut(self):return self._oleobj_.InvokeTypes(21, LCID, 1, (24, 0), (),)def Login(self, vConfigIiniFile=defaultNamedNotOptArg, vuserid=defaultNamedNotOptArg, vpassword=defaultNamedNotOptArg, ErrorID=pythoncom.Missing, RegResultInfo=pythoncom.Missing):return self._ApplyTypes_(1, 1, (24, 0), ((8, 1), (8, 1), (8, 1), (16387, 2), (16392, 2)), 'Login', None,vConfigIiniFile, vuserid, vpassword, ErrorID, RegResultInfo)def MA(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, Counts=defaultNamedNotOptArg, MA=pythoncom.Missing):return self._ApplyTypes_(34, 1, (24, 0), ((8, 1), (3, 1), (3, 1), (16389, 2)), 'MA', None,InstrumentID, Period, Counts, MA)def MACD(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, Diff=pythoncom.Missing, Dea=pythoncom.Missing):return self._ApplyTypes_(36, 1, (24, 0), ((8, 1), (3, 1), (16389, 2), (16389, 2)), 'MACD', None,InstrumentID, Period, Diff, Dea)def PasswordUpdate(self, NewPassWord=defaultNamedNotOptArg):return self._oleobj_.InvokeTypes(24, LCID, 1, (24, 0), ((8, 1),),NewPassWord)def PlaceOrder(self, pszInstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, OrderID=pythoncom.Missing):return self._ApplyTypes_(19, 1, (24, 0), ((8, 1), (3, 1), (3, 1), (3, 1), (5, 1), (16387, 2)), 'PlaceOrder', None,pszInstrumentID, IsBuy, IsOpen, Volume, Price, OrderID)def PrintOrderInfo(self):return self._oleobj_.InvokeTypes(25, LCID, 1, (24, 0), (),)def Sell(self, pszInstrumentID=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, OrderID=pythoncom.Missing, OrderID1=pythoncom.Missing):return self._ApplyTypes_(9, 1, (24, 0), ((8, 1), (3, 1), (5, 1), (16387, 2), (16387, 2)), 'Sell', None,pszInstrumentID, Volume, Price, OrderID, OrderID1)def SetOrderCloseMode(self, CloseMode=defaultNamedNotOptArg, SetOk=pythoncom.Missing):return self._ApplyTypes_(30, 1, (24, 0), ((3, 1), (16387, 2)), 'SetOrderCloseMode', None,CloseMode, SetOk)def SettlementInfoConfirm(self):return self._oleobj_.InvokeTypes(16, LCID, 1, (24, 0), (),)def Short(self, pszInstrumentID=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, OrderID=pythoncom.Missing):return self._ApplyTypes_(7, 1, (24, 0), ((8, 1), (3, 1), (5, 1), (16387, 2)), 'Short', None,pszInstrumentID, Volume, Price, OrderID)def SubscribeDepthMD(self, InstrumentID=defaultNamedNotOptArg):return self._oleobj_.InvokeTypes(29, LCID, 1, (24, 0), ((8, 1),),InstrumentID)def SubscribeMD(self, InstrumentID=defaultNamedNotOptArg):return self._oleobj_.InvokeTypes(4, LCID, 1, (24, 0), ((8, 1),),InstrumentID)def UnSubscribeMD(self, InstrumentID=defaultNamedNotOptArg):return self._oleobj_.InvokeTypes(5, LCID, 1, (24, 0), ((8, 1),),InstrumentID)_prop_map_get_ = {}_prop_map_put_ = {}def __iter__(self):"Return a Python iterator for this object"try:ob = self._oleobj_.InvokeTypes(-4,LCID,3,(13, 10),())except pythoncom.error:raise TypeError("This object does not support enumeration")return win32com.client.util.Iterator(ob, None)class _ITVQhtICtpClientAPIEvents:CLSID = CLSID_Sink = IID('{BF886C94-57F1-4532-B4A4-3ADA86317BDC}')coclass_clsid = IID('{4F356EF1-932E-48D1-B7A4-CFDE79752627}')_public_methods_ = [] # For COM Server support_dispid_to_func_ = {1 : "OnMarketData",2 : "OnEventsInfo",3 : "OnInstrumentStatus",4 : "OnTradeConnected",5 : "OnTradeDisconnected",6 : "OnMDConnected",7 : "OnMDDisconnected",8 : "OnOrder",9 : "OnTrade",10 : "OnOrderCanceled",11 : "OnOrderActionFailed",12 : "OnInitFinished",13 : "OnGetPositionDetail",14 : "OnGetInstrument",15 : "OnRspError",16 : "OnOutPosition",17 : "OnDepthMarketData",18 : "OnPushCancleOrder",19 : "OnRspQryOrder",20 : "OnRspQryTrade",21 : "OnOutProgress",22 : "OnOutBars",23 : "OnOutExchangeTradeTimes",}def __init__(self, oobj = None):if oobj is None:self._olecp = Noneelse:import win32com.server.utilfrom win32com.server.policy import EventHandlerPolicycpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer)cp=cpc.FindConnectionPoint(self.CLSID_Sink)cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy))self._olecp,self._olecp_cookie = cp,cookiedef __del__(self):try:self.close()except pythoncom.com_error:passdef close(self):if self._olecp is not None:cp,cookie,self._olecp,self._olecp_cookie = self._olecp,self._olecp_cookie,None,Nonecp.Unadvise(cookie)def _query_interface_(self, iid):import win32com.server.utilif iid==self.CLSID_Sink: return win32com.server.util.wrap(self)# Event Handlers# If you create handlers, they should have the following prototypes: # def OnMarketData(self, InstrumentID=defaultNamedNotOptArg, BidPrice1=defaultNamedNotOptArg, BidVolume1=defaultNamedNotOptArg, AskPrice1=defaultNamedNotOptArg # , AskVolume1=defaultNamedNotOptArg, OpenPrice=defaultNamedNotOptArg, HighestPrice=defaultNamedNotOptArg, LowestPrice=defaultNamedNotOptArg, LastPrice=defaultNamedNotOptArg # , OpenInterest=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, UpperLimitPrice=defaultNamedNotOptArg, LowerLimitPrice=defaultNamedNotOptArg, PreSettlementPrice=defaultNamedNotOptArg # , AveragePrice=defaultNamedNotOptArg, UpdateTime=defaultNamedNotOptArg, UpdateMilliSecond=defaultNamedNotOptArg): # def OnEventsInfo(self, InfoID=defaultNamedNotOptArg, MsgInfo=defaultNamedNotOptArg): # def OnInstrumentStatus(self, InstrumentID=defaultNamedNotOptArg, ExchangeID=defaultNamedNotOptArg, EnterTime=defaultNamedNotOptArg, NewState=defaultNamedNotOptArg): # def OnTradeConnected(self): # def OnTradeDisconnected(self): # def OnMDConnected(self): # def OnMDDisconnected(self): # def OnOrder(self, OrderID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg # , Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, TradedVolume=defaultNamedNotOptArg, AvgTradePrice=defaultNamedNotOptArg, OrderStatus=defaultNamedNotOptArg # , OrderSysID=defaultNamedNotOptArg, BrokerOrderSeq=defaultNamedNotOptArg, OrderLocalID=defaultNamedNotOptArg, InsertTime=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg # , ErrorMsg=defaultNamedNotOptArg, HedgeType=defaultNamedNotOptArg): # def OnTrade(self, OrderID=defaultNamedNotOptArg, OrderSysID=defaultNamedNotOptArg, OrderLocalID=defaultNamedNotOptArg, TradeID=defaultNamedNotOptArg # , InstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, ThisTradePrice=defaultNamedNotOptArg # , TradeTime=defaultNamedNotOptArg, OrderStatus=defaultNamedNotOptArg): # def OnOrderCanceled(self, OrderID=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg, ErrorMsg=defaultNamedNotOptArg): # def OnOrderActionFailed(self, OrderID=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg, ErrorMsg=defaultNamedNotOptArg): # def OnInitFinished(self): # def OnGetPositionDetail(self, InstrumentID=defaultNamedNotOptArg, OpenDate=defaultNamedNotOptArg, OrderID=defaultNamedNotOptArg, TradeID=defaultNamedNotOptArg # , Direction=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, CloseVolume=defaultNamedNotOptArg, OpenPrice=defaultNamedNotOptArg, PositionProfitByDate=defaultNamedNotOptArg # , PositionProfitByTrade=defaultNamedNotOptArg, Margin=defaultNamedNotOptArg, LastSettlementPrice=defaultNamedNotOptArg, SettlementPrice=defaultNamedNotOptArg, CloseProfitByDate=defaultNamedNotOptArg # , CloseProfitByTrade=defaultNamedNotOptArg, CloseAmount=defaultNamedNotOptArg, TimeFirstVolume=defaultNamedNotOptArg, MarginRateByMoney=defaultNamedNotOptArg, MarginRateByVolume=defaultNamedNotOptArg): # def OnGetInstrument(self, ExchangeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, ExchangeInstID=defaultNamedNotOptArg, InstrumentName=defaultNamedNotOptArg # , ProductClass=defaultNamedNotOptArg, MaxMarketOrderVolume=defaultNamedNotOptArg, MinMarketOrderVolume=defaultNamedNotOptArg, MaxLimitOrderVolume=defaultNamedNotOptArg, MinLimitOrderVolume=defaultNamedNotOptArg # , VolumeMultiple=defaultNamedNotOptArg, PriceTick=defaultNamedNotOptArg, ExpireDate=defaultNamedNotOptArg, IsTrading=defaultNamedNotOptArg, LongMarginRatio=defaultNamedNotOptArg # , ShortMarginRatio=defaultNamedNotOptArg, OptionsType=defaultNamedNotOptArg, ProductID=defaultNamedNotOptArg, CombinationType=defaultNamedNotOptArg, bIsLast=defaultNamedNotOptArg): # def OnRspError(self, ErrorID=defaultNamedNotOptArg, ErrorMsg=defaultNamedNotOptArg): # def OnOutPosition(self, InstrumentID=defaultNamedNotOptArg, LongPostion=defaultNamedNotOptArg, LongYDPostion=defaultNamedNotOptArg, LongFrozen=defaultNamedNotOptArg # , LongSuspendPostion=defaultNamedNotOptArg, LongPositionPrice=defaultNamedNotOptArg, LongProfit=defaultNamedNotOptArg, ShortPostion=defaultNamedNotOptArg, ShortYDPostion=defaultNamedNotOptArg # , ShortFrozen=defaultNamedNotOptArg, ShortSuspendPostion=defaultNamedNotOptArg, ShortPositionPrice=defaultNamedNotOptArg, ShortProfit=defaultNamedNotOptArg): # def OnDepthMarketData(self, InstrumentID=defaultNamedNotOptArg, BidPrice1=defaultNamedNotOptArg, BidVolume1=defaultNamedNotOptArg, AskPrice1=defaultNamedNotOptArg # , AskVolume1=defaultNamedNotOptArg, BidPrice2=defaultNamedNotOptArg, BidVolume2=defaultNamedNotOptArg, AskPrice2=defaultNamedNotOptArg, AskVolume2=defaultNamedNotOptArg # , BidPrice3=defaultNamedNotOptArg, BidVolume3=defaultNamedNotOptArg, AskPrice3=defaultNamedNotOptArg, AskVolume3=defaultNamedNotOptArg, BidPrice4=defaultNamedNotOptArg # , BidVolume4=defaultNamedNotOptArg, AskPrice4=defaultNamedNotOptArg, AskVolume4=defaultNamedNotOptArg, BidPrice5=defaultNamedNotOptArg, BidVolume5=defaultNamedNotOptArg # , AskPrice5=defaultNamedNotOptArg, AskVolume5=defaultNamedNotOptArg, OpenPrice=defaultNamedNotOptArg, HighestPrice=defaultNamedNotOptArg, LowestPrice=defaultNamedNotOptArg # , LastPrice=defaultNamedNotOptArg, OpenInterest=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, UpperLimitPrice=defaultNamedNotOptArg, LowerLimitPrice=defaultNamedNotOptArg # , PreSettlementPrice=defaultNamedNotOptArg, AveragePrice=defaultNamedNotOptArg, UpdateTime=defaultNamedNotOptArg, UpdateMilliSecond=defaultNamedNotOptArg): # def OnPushCancleOrder(self, OrderID=defaultNamedNotOptArg, InsertTime=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg # , IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg, TradedVolume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, OrderStatus=defaultNamedNotOptArg): # def OnRspQryOrder(self, OrderID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg # , Volume=defaultNamedNotOptArg, Price=defaultNamedNotOptArg, TradedVolume=defaultNamedNotOptArg, AvgTradePrice=defaultNamedNotOptArg, OrderStatus=defaultNamedNotOptArg # , OrderSysID=defaultNamedNotOptArg, BrokerOrderSeq=defaultNamedNotOptArg, OrderLocalID=defaultNamedNotOptArg, InsertTime=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg # , ErrorMsg=defaultNamedNotOptArg, HedgeType=defaultNamedNotOptArg): # def OnRspQryTrade(self, OrderID=defaultNamedNotOptArg, TradeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, OrderSysID=defaultNamedNotOptArg # , OrderLocalID=defaultNamedNotOptArg, BrokerOrderSeq=defaultNamedNotOptArg, IsBuy=defaultNamedNotOptArg, IsOpen=defaultNamedNotOptArg, Volume=defaultNamedNotOptArg # , Price=defaultNamedNotOptArg, TradeDate=defaultNamedNotOptArg, TradeTime=defaultNamedNotOptArg): # def OnOutProgress(self, ProFlag=defaultNamedNotOptArg, MaxInt=defaultNamedNotOptArg, Position=defaultNamedNotOptArg): # def OnOutBars(self, InstrumentID=defaultNamedNotOptArg, Period=defaultNamedNotOptArg, Counts=defaultNamedNotOptArg, Hight=defaultNamedNotOptArg # , Low=defaultNamedNotOptArg, Open=defaultNamedNotOptArg, Close=defaultNamedNotOptArg, CreatTime=defaultNamedNotOptArg): # def OnOutExchangeTradeTimes(self, ExchangeID=defaultNamedNotOptArg, InstrumentID=defaultNamedNotOptArg, OpenTime=defaultNamedNotOptArg, CloseTime=defaultNamedNotOptArg # , TradeMins=defaultNamedNotOptArg, Flag=defaultNamedNotOptArg):from win32com.client import CoClassBaseClass # This CoClass is known by the name 'TVQhtICtpClientAPI.com.1' class TVQhtICtpClientAPI(CoClassBaseClass): # A CoClassCLSID = IID('{4F356EF1-932E-48D1-B7A4-CFDE79752627}')coclass_sources = [_ITVQhtICtpClientAPIEvents,]default_source = _ITVQhtICtpClientAPIEventscoclass_interfaces = [ITVQhtICtpClientAPI,]default_interface = ITVQhtICtpClientAPIITVQhtICtpClientAPI_vtables_dispatch_ = 1 ITVQhtICtpClientAPI_vtables_ = [(( 'Login' , 'vConfigIiniFile' , 'vuserid' , 'vpassword' , 'ErrorID' , 'RegResultInfo' , ), 1, (1, (), [ (8, 1, None, None) , (8, 1, None, None) , (8, 1, None, None) , (16387, 2, None, None) , (16392, 2, None, None) , ], 1 , 1 , 4 , 0 , 56 , (3, 0, None, None) , 0 , )),(( 'CancelOrder' , 'OrderID' , 'Status' , ), 2, (2, (), [ (3, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 64 , (3, 0, None, None) , 0 , )),(( 'GetAPIVersion' , 'vVersion' , ), 3, (3, (), [ (16392, 10, None, None) , ], 1 , 1 , 4 , 0 , 72 , (3, 0, None, None) , 0 , )),(( 'SubscribeMD' , 'InstrumentID' , ), 4, (4, (), [ (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 80 , (3, 0, None, None) , 0 , )),(( 'UnSubscribeMD' , 'InstrumentID' , ), 5, (5, (), [ (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 88 , (3, 0, None, None) , 0 , )),(( 'Buy' , 'pszInstrumentID' , 'Volume' , 'Price' , 'OrderID' , ), 6, (6, (), [ (8, 1, None, None) , (3, 1, None, None) , (5, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 96 , (3, 0, None, None) , 0 , )),(( 'Short' , 'pszInstrumentID' , 'Volume' , 'Price' , 'OrderID' , ), 7, (7, (), [ (8, 1, None, None) , (3, 1, None, None) , (5, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 104 , (3, 0, None, None) , 0 , )),(( 'Cover' , 'pszInstrumentID' , 'Volume' , 'Price' , 'OrderID' , 'OrderID1' , ), 8, (8, (), [ (8, 1, None, None) , (3, 1, None, None) , (5, 1, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 112 , (3, 0, None, None) , 0 , )),(( 'Sell' , 'pszInstrumentID' , 'Volume' , 'Price' , 'OrderID' , 'OrderID1' , ), 9, (9, (), [ (8, 1, None, None) , (3, 1, None, None) , (5, 1, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 120 , (3, 0, None, None) , 0 , )),(( 'GetTradingDay' , 'TradingDay' , ), 10, (10, (), [ (16392, 10, None, None) , ], 1 , 1 , 4 , 0 , 128 , (3, 0, None, None) , 0 , )),(( 'IsOrderOpen' , 'OrderID' , 'CanCacel' , ), 11, (11, (), [ (3, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 136 , (3, 0, None, None) , 0 , )),(( 'GetInstrumentInfo' , 'InstrumentID' , 'Multiply' , 'PriceUnit' , 'MarginRate' , 'ExpireDate' , ), 12, (12, (), [ (8, 1, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16392, 2, None, None) , ], 1 , 1 , 4 , 0 , 144 , (3, 0, None, None) , 0 , )),(( 'GetPositionDetail' , 'InstrumentID' , ), 13, (13, (), [ (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 152 , (3, 0, None, None) , 0 , )),(( 'GetAccount' , 'PreBalance' , 'Balance' , 'PreMargin' , 'Available' , 'WithdrawQuota' , 'ExchangeMargin' , 'CloseProfit' , 'PositionProfit' , ), 14, (14, (), [ (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 160 , (3, 0, None, None) , 0 , )),(( 'GetTradeInfo' , 'InstrumentID' , ), 15, (15, (), [ (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 168 , (3, 0, None, None) , 0 , )),(( 'SettlementInfoConfirm' , ), 16, (16, (), [ ], 1 , 1 , 4 , 0 , 176 , (3, 0, None, None) , 0 , )),(( 'GetPosition' , 'InstrumentID' , 'LongPosition' , 'LongYdPosition' , 'LongFrozen' , 'LongPositionPrice' , 'ShortPosition' , 'ShortYdPosition' , 'ShortFrozen' , 'ShortPositionPrice' , ), 17, (17, (), [ (8, 1, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 184 , (3, 0, None, None) , 0 , )),(( 'GetHisOrderList' , 'InstrumentID' , 'GetFlag' , ), 18, (18, (), [ (8, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 192 , (3, 0, None, None) , 0 , )),(( 'PlaceOrder' , 'pszInstrumentID' , 'IsBuy' , 'IsOpen' , 'Volume' , 'Price' , 'OrderID' , ), 19, (19, (), [ (8, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (5, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 200 , (3, 0, None, None) , 0 , )),(( 'About' , ), 20, (20, (), [ ], 1 , 1 , 4 , 0 , 208 , (3, 0, None, None) , 0 , )),(( 'LogOut' , ), 21, (21, (), [ ], 1 , 1 , 4 , 0 , 216 , (3, 0, None, None) , 0 , )),(( 'Free' , ), 22, (22, (), [ ], 1 , 1 , 4 , 0 , 224 , (3, 0, None, None) , 0 , )),(( 'GetMarketData' , 'InstrumentID' , 'YdClose' , 'YdSettlement' , 'Open' , 'Last' , 'Bid1' , 'Ask1' , 'Bid1Volume' , 'Ask1Volume' , 'Highest' , 'Lowest' , 'TradedVolume' , 'TradedAmmount' , ), 23, (23, (), [ (8, 1, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 232 , (3, 0, None, None) , 0 , )),(( 'PasswordUpdate' , 'NewPassWord' , ), 24, (24, (), [ (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 240 , (3, 0, None, None) , 0 , )),(( 'PrintOrderInfo' , ), 25, (25, (), [ ], 1 , 1 , 4 , 0 , 248 , (3, 0, None, None) , 0 , )),(( 'GetInstrumentRatio' , 'InstrumentID' , 'OpenRatioByMoney' , 'OpenRatioByVolume' , 'CloseRatioByMoney' , 'CloseRatioByVolume' , 'CloseTodayRatioByMoney' , 'CloseTodayRatioByVolume' , ), 26, (26, (), [ (8, 1, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 256 , (3, 0, None, None) , 0 , )),(( 'GetRealAccount' , 'PreBalance' , 'Balance' , 'PreMargin' , 'Available' , 'WithdrawQuota' , 'ExchangeMargin' , 'CloseProfit' , 'PositionProfit' , ), 27, (27, (), [ (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 264 , (3, 0, None, None) , 0 , )),(( 'GetRealPosition' , 'InstrumentID' , 'LongPosition' , 'LongYdPosition' , 'LongFrozen' , 'LongPositionPrice' , 'ShortPosition' , 'ShortYdPosition' , 'ShortFrozen' , 'ShortPositionPrice' , ), 28, (28, (), [ (8, 1, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 272 , (3, 0, None, None) , 0 , )),(( 'SubscribeDepthMD' , 'InstrumentID' , ), 29, (29, (), [ (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 280 , (3, 0, None, None) , 0 , )),(( 'SetOrderCloseMode' , 'CloseMode' , 'SetOk' , ), 30, (30, (), [ (3, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 288 , (3, 0, None, None) , 0 , )),(( 'GetPositionPlus' , 'InstrumentID' , 'LongPosition' , 'LongYdPosition' , 'LongFrozen' , 'LongSuspendPostion' , 'LongPositionPrice' , 'LongPositionProfit' , 'ShortPosition' , 'ShortYdPosition' , 'ShortFrozen' , 'ShortSuspendPostion' , 'ShortPositionPrice' , 'ShortPositionProfit' , 'BidPrice' , 'AskPrice' , ), 31, (31, (), [ (8, 1, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 296 , (3, 0, None, None) , 0 , )),(( 'CreateBars' , 'InstrumentID' , 'Period' , 'Counts' , 'IsOk' , ), 32, (32, (), [ (8, 1, None, None) , (3, 1, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 304 , (3, 0, None, None) , 0 , )),(( 'DeleteBars' , 'InstrumentID' , 'Period' , 'IsOk' , ), 33, (33, (), [ (8, 1, None, None) , (3, 1, None, None) , (16387, 2, None, None) , ], 1 , 1 , 4 , 0 , 312 , (3, 0, None, None) , 0 , )),(( 'MA' , 'InstrumentID' , 'Period' , 'Counts' , 'MA' , ), 34, (34, (), [ (8, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 320 , (3, 0, None, None) , 0 , )),(( 'EMA' , 'InstrumentID' , 'Period' , 'Counts' , 'EMA' , ), 35, (35, (), [ (8, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 328 , (3, 0, None, None) , 0 , )),(( 'MACD' , 'InstrumentID' , 'Period' , 'Diff' , 'Dea' , ), 36, (36, (), [ (8, 1, None, None) , (3, 1, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 336 , (3, 0, None, None) , 0 , )),(( 'GetInstrumentInfoOut' , 'InstrumentID' , 'Multiply' , 'PriceUnit' , 'MarginRate' , 'ExpireDate' , ), 37, (37, (), [ (8, 1, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16392, 2, None, None) , ], 1 , 1 , 4 , 0 , 344 , (3, 0, None, None) , 0 , )),(( 'DefMACD' , 'InstrumentID' , 'Period' , 'Fast' , 'Slow' , 'Signal' , 'Diff' , 'Dea' , ), 38, (38, (), [ (8, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , ], 1 , 1 , 4 , 0 , 352 , (3, 0, None, None) , 0 , )),(( 'GetBars' , 'InstrumentID' , 'Period' , 'index' , 'Max' , 'Open' , 'Close' , 'Hight' , 'Low' , 'Volume' , 'Counts' , 'UpdateTime' , ), 39, (39, (), [ (8, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (16387, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16389, 2, None, None) , (16387, 2, None, None) , (16387, 2, None, None) , (16392, 2, None, None) , ], 1 , 1 , 4 , 0 , 360 , (3, 0, None, None) , 0 , )),(( 'AppendExchangeTradeTimes' , 'ExchangeID' , 'InstrumentID' , 'hour' , 'minute' , 'TradeTimes' , 'Flag' , 'InfoID' , 'InfoMsg' , ), 40, (40, (), [ (8, 1, None, None) , (8, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (3, 1, None, None) , (16387, 2, None, None) , (16392, 2, None, None) , ], 1 , 1 , 4 , 0 , 368 , (3, 0, None, None) , 0 , )),(( 'DeleteExchangeTradeTimes' , 'ExchangeID' , 'InstrumentID' , 'InfoID' , 'InfoMsg' , ), 41, (41, (), [ (8, 1, None, None) , (8, 1, None, None) , (16387, 2, None, None) , (16392, 2, None, None) , ], 1 , 1 , 4 , 0 , 384 , (3, 0, None, None) , 0 , )),(( 'GetOutExchangeTradeTimes' , 'ExchangeID' , 'InstrumentID' , ), 42, (42, (), [ (8, 1, None, None) , (8, 1, None, None) , ], 1 , 1 , 4 , 0 , 392 , (3, 0, None, None) , 0 , )), ]RecordMap = {###'tagMyStructField1': '{00000000-0000-0000-0000-000000000000}', # Record disabled because it doesn't have a non-null GUID }CLSIDToClassMap = {'{BF886C94-57F1-4532-B4A4-3ADA86317BDC}' : _ITVQhtICtpClientAPIEvents,'{FD3E2400-1A18-45E4-8DAF-DE8840F22C8D}' : ITVQhtICtpClientAPI,'{4F356EF1-932E-48D1-B7A4-CFDE79752627}' : TVQhtICtpClientAPI, } CLSIDToPackageMap = {} win32com.client.CLSIDToClass.RegisterCLSIDsFromDict( CLSIDToClassMap ) VTablesToPackageMap = {} VTablesToClassMap = {'{FD3E2400-1A18-45E4-8DAF-DE8840F22C8D}' : 'ITVQhtICtpClientAPI', }NamesToIIDMap = {'_ITVQhtICtpClientAPIEvents' : '{BF886C94-57F1-4532-B4A4-3ADA86317BDC}','ITVQhtICtpClientAPI' : '{FD3E2400-1A18-45E4-8DAF-DE8840F22C8D}', }總結
以上是生活随笔為你收集整理的上期技术CTPAPI封装COM组件ctp开放平台openctp环境7_24小时x64组件python_delphi调用演示程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab同步电机三相短路,基于Mat
- 下一篇: SAS|数据集合并