def ReqOrderInsert(self, instrumentid, comboffsetflag, direction, limitprice, volumetotaloriginal=1): #instrumentid = raw_input('请输入合约号:') #orderpricetype = raw_input('任意价1 限价2 最优价3 最新价4:') #comboffsetflag = raw_input('开仓0平仓1平今3平昨4:') #direction = raw_input('买0 卖1:') #limitprice = input('价格:') #volumetotaloriginal = raw_input('数量:') req = ApiStruct.InputOrder( BrokerID=self.brokerID, InvestorID=self.userID, InstrumentID=instrumentid, UserID=self.userID, OrderPriceType=str(2), Direction=str(direction), CombOffsetFlag=str(comboffsetflag), CombHedgeFlag='1', LimitPrice=float(limitprice), VolumeTotalOriginal=int(volumetotaloriginal), TimeCondition='3', VolumeCondition='1', MinVolume=0, ContingentCondition='1', StopPrice=0.0, ForceCloseReason='0', IsAutoSuspend=0) self.requestID += 1 TraderApi.ReqOrderInsert(self, req, self.requestID)
def ReqQrySettlementInfo(self): req = ApiStruct.SettlementInfo(BrokerID=self.brokerID, UserID=self.userID) self.requestID += 1 answer = TraderApi.ReqQrySettlementInfo(self, req, self.requestID) if answer == 0: print "结算查询发送成功" pass
def ReqUserPasswordUpdate(self, oldpass, newpass): req = ApiStruct.UserPasswordUpdate(BrokerID=self.brokerID, InvestorID=self.userID, OldPassword=oldpass, NewPassword=newpass) self.requestID += 1 answer = TraderApi.ReqUserPasswordUpdate(self, req, self.requestID) print 'UserPasswordUpdate...' if answer == 0 else 'error on UserPasswordUpdate'
def ReqSettlementInfoConfirm(self): req = ApiStruct.SettlementInfoConfirm(BrokerID=self.brokerID, InvestorID=self.userID) self.requestID += 1 answer = TraderApi.ReqSettlementInfoConfirm(self, req, self.requestID) if answer == 0: print '结算单确认成功' else: '结算单确认错误'
def ReqOrderAction(self, ordersysid, exchangeid): #ordersysid = raw_input("请输入系统报单号:") #exchangeid = raw_input("请输入交易所SHFE/DCE/CFFE/CZCE:") #req = ApiStruct.OrderAction(InstrumentID=self.instrumentIDs, BrokerID=self.brokerID, InvestorID=self.userID, ActionFlag=b'0', FrontID=1, SessionID=865534192, OrderRef=' 2', ExchangeID='SHFE', LimitPrice=52100.0, RequestID=65537, OrderSysID=' 1036148') req = ApiStruct.OrderAction(BrokerID=self.brokerID, InvestorID=self.userID, ActionFlag=b'0', OrderSysID=str(ordersysid).rjust(12), ExchangeID=str(exchangeid).upper()) self.requestID += 1 TraderApi.ReqOrderAction(self, req, self.requestID)
def RegisterFront(self, front): if isinstance(front, bytes): return TraderApi.RegisterFront(self, front) for front in front: TraderApi.RegisterFront(self, front)
def Create(self): TraderApi.Create(self)
def ReqQryExchange(self): req = ApiStruct.QryExchange(ExchageID='SHFE') self.requestID += 1 TraderApi.ReqQryExchange(self, req, self.requestID)
def ReqQryTrade(self): req = ApiStruct.QryTrade(BrokerID=self.brokerID, InvestorID=self.userID) self.requestID += 1 TraderApi.ReqQryTrade(self, req, self.requestID)
def ReqQryTradingAccount(self): #print self.brokerID, self.userID req = ApiStruct.QryTradingAccount(BrokerID=self.brokerID, InvestorID=self.userID) self.requestID += 1 TraderApi.ReqQryTradingAccount(self, req, self.requestID)
def ReqQryInvestorPositionDetail(self): req = ApiStruct.QryInvestorPositionDetail(BrokerID=self.brokerID, InvestorID=self.userID) self.requestID += 1 TraderApi.ReqQryInvestorPositionDetail(self, req, self.requestID)
def ReqQryDepthMarketData(self): pInstrumentID = raw_input('输入合约名称:') req = ApiStruct.QryDepthMarketData(InstrumentID=pInstrumentID) self.requestID += 1 answer = TraderApi.ReqQryDepthMarketData(self, req, self.requestID) print 'ReqQryDepthMarketData...' if answer == 0 else 'error on ReqQryDepthMarketData'