Exemplo n.º 1
0
 def subscribe(self):
     ss = SubscribeRequest()
     ss.sym_type = SYMBOL_TYPE.CTP
     ss.content = str(self.sym.text())
     m = Event(EventType.SUBSCRIBE)
     m.msg_type = MSG_TYPE.MSG_TYPE_SUBSCRIBE_MARKET_DATA
     m.data = ss
     self.subscribe_signal.emit(m)
Exemplo n.º 2
0
 def place_order_ctp(self, of):
     try:
         m = Event(EventType.ORDER)
         m.msg_type = MSG_TYPE.MSG_TYPE_ORDER_CTP
         m.destination = self.gateway.currentText()
         m.source = '0'
         ot = OrderType.DEFAULT
         if (of.OrderPriceType == THOST_FTDC_OPT_AnyPrice) and (
                 of.ContingentCondition
                 in [THOST_FTDC_CC_Touch, THOST_FTDC_CC_TouchProfit]):
             ot = OrderType.STP
         elif (of.OrderPriceType == THOST_FTDC_OPT_LimitPrice) and (
                 of.ContingentCondition
                 in [THOST_FTDC_CC_Touch, THOST_FTDC_CC_TouchProfit]):
             ot = OrderType.STPLMT
         elif (of.OrderPriceType == THOST_FTDC_OPT_AnyPrice) and (
                 of.ContingentCondition
                 == THOST_FTDC_CC_Immediately) and (of.TimeCondition
                                                    == THOST_FTDC_TC_GFD):
             ot = OrderType.MKT
         elif (of.OrderPriceType == THOST_FTDC_OPT_LimitPrice) and (
                 of.ContingentCondition
                 == THOST_FTDC_CC_Immediately) and (of.TimeCondition
                                                    == THOST_FTDC_TC_GFD):
             ot = OrderType.LMT
         elif (of.ContingentCondition == THOST_FTDC_CC_Immediately) and (
                 of.TimeCondition
                 == THOST_FTDC_TC_IOC) and (of.VolumeCondition
                                            == THOST_FTDC_VC_AV):
             ot = OrderType.FAK
         elif (of.ContingentCondition == THOST_FTDC_CC_Immediately) and (
                 of.TimeCondition
                 == THOST_FTDC_TC_IOC) and (of.VolumeCondition
                                            == THOST_FTDC_VC_CV):
             ot = OrderType.FOK
         o = OrderData(api="CTP.TD",
                       account=m.destination[7:],
                       clientID=0,
                       client_order_id=self.manualorderid,
                       type=ot,
                       orderfield=of)
         # o.api = "CTP.TD"       #self.gateway.currentText()
         # o.account = m.destination[7:]
         # o.clientID = 0
         # o.client_order_id = self.manualorderid
         # # o.create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
         # o.orderfield = of
         m.data = o
         self.order_signal.emit(m)
         self.manualorderid = self.manualorderid + 1
     except:
         print('place ctp order error')
Exemplo n.º 3
0
 def place_order_paper(self, of):
     try:
         m = Event(EventType.ORDER)
         m.msg_type = MSG_TYPE.MSG_TYPE_ORDER_PAPER
         m.destination = self.gateway.currentText()
         m.source = '0'
         o = OrderData()
         o.api = "PAPER.TD"  # self.api_type.currentText()
         o.account = "manual"
         o.clientID = 0
         o.client_order_id = self.manualorderid
         self.manualorderid = self.manualorderid + 1
         # o.create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
         o.orderfield = of
         m.data = o
         self.order_signal.emit(m)
     except:
         print('place paper order error')
Exemplo n.º 4
0
 def place_local_order_ctp(self, of):
     try:
         m = Event(EventType.ORDER)
         m.msg_type = MSG_TYPE.MSG_TYPE_ORDER_CTP
         m.destination = self.gateway.currentText()
         m.source = '0'
         ot = OrderType.LPT
         if of.ContingentCondition in [
                 THOST_FTDC_CC_Touch, THOST_FTDC_CC_TouchProfit
         ]:
             of.ContingentCondition = THOST_FTDC_CC_Immediately
         o = OrderData(api="CTP.TD",
                       account=m.destination[7:],
                       clientID=0,
                       client_order_id=self.manualorderid,
                       type=ot,
                       orderfield=of)
         m.data = o
         self.order_signal.emit(m)
         self.manualorderid = self.manualorderid + 1
     except:
         print('place ctp local order error')
Exemplo n.º 5
0
 def qry(self):
     qry = Event(EventType.QRY)
     if (self.qry_type.currentText() == 'Account'):
         qry.msg_type = MSG_TYPE.MSG_TYPE_QRY_ACCOUNT
     if (self.qry_type.currentText() == 'Position'):
         qry.msg_type = MSG_TYPE.MSG_TYPE_QRY_POS
     if (self.qry_type.currentText() == 'Contract'):
         qc = QryContractRequest()
         qc.sym_type = SYMBOL_TYPE.CTP
         qc.content = self.qry_content.text()
         qry.msg_type = MSG_TYPE.MSG_TYPE_QRY_CONTRACT
         qry.data = qc
     if (self.qry_type.currentText() == 'Order'):
         qry.msg_type = MSG_TYPE.MSG_TYPE_QRY_ORDER
     if (self.qry_type.currentText() == 'Trade'):
         qry.msg_type = MSG_TYPE.MSG_TYPE_QRY_TRADE
     if (self.qry_type.currentText() == 'PositionDetail'):
         qry.msg_type = MSG_TYPE.MSG_TYPE_QRY_POSDETAIL
     self.qry_signal.emit(qry)
Exemplo n.º 6
0
    def generate_request(self):
        print("ctp request at ", datetime.now())
        if (self.request_type.currentText() == 'Order'):
            of = CtpOrderField()
            of.InstrumentID = self.sym.text()
            of.OrderPriceType = self.orderfielddict['pricetype'][
                self.order_price_type.currentIndex()]
            of.Direction = self.orderfielddict['direction'][
                self.direction_type.currentIndex()]
            of.CombOffsetFlag = self.orderfielddict['orderflag'][
                self.order_flag_type.currentIndex()]
            of.CombHedgeFlag = self.orderfielddict['hedge'][
                self.hedge_type.currentIndex()]
            of.TimeCondition = self.orderfielddict['timecondition'][
                self.time_condition_type.currentIndex()]
            of.GTDDate = self.time_condition_time.text()
            of.VolumeCondition = self.orderfielddict['volumecondition'][
                self.volume_condition_type.currentIndex()]
            of.ContingentCondition = self.orderfielddict['condition'][
                self.order_condition_type.currentIndex()]
            of.ForceCloseReason = THOST_FTDC_FCC_NotForceClose
            try:
                of.LimitPrice = float(self.limit_price.text())
                of.VolumeTotalOriginal = int(self.order_quantity.text())
                of.MinVolume = int(self.order_minquantity.text())
                of.StopPrice = float(self.stop_price.text())
            except:
                print('ctp request error,please check numerical field')
                return

            self.orderfield_signal.emit(of)
        elif (self.request_type.currentText() == 'LocalOrder'):
            of = CtpOrderField()
            of.InstrumentID = self.sym.text()
            of.OrderPriceType = self.orderfielddict['pricetype'][
                self.order_price_type.currentIndex()]
            of.Direction = self.orderfielddict['direction'][
                self.direction_type.currentIndex()]
            of.CombOffsetFlag = self.orderfielddict['orderflag'][
                self.order_flag_type.currentIndex()]
            of.CombHedgeFlag = self.orderfielddict['hedge'][
                self.hedge_type.currentIndex()]
            of.TimeCondition = self.orderfielddict['timecondition'][
                self.time_condition_type.currentIndex()]
            of.GTDDate = self.time_condition_time.text()
            of.VolumeCondition = self.orderfielddict['volumecondition'][
                self.volume_condition_type.currentIndex()]
            of.ContingentCondition = self.orderfielddict['condition'][
                self.order_condition_type.currentIndex()]
            of.ForceCloseReason = THOST_FTDC_FCC_NotForceClose
            try:
                of.LimitPrice = float(self.limit_price.text())
                of.VolumeTotalOriginal = int(self.order_quantity.text())
                of.MinVolume = int(self.order_minquantity.text())
                of.StopPrice = float(self.stop_price.text())
            except:
                print('ctp request error,please check numerical field')
                return
            if of.StopPrice <= 0:
                QtWidgets.QMessageBox().information(
                    None, 'Error', 'Stop Price must be positive number !',
                    QtWidgets.QMessageBox.Ok)
                return
            self.local_orderfield_signal.emit(of)

        elif (self.request_type.currentText() == 'CancelAll'):
            ss = CancelAllRequest()
            ss.sym_type = SYMBOL_TYPE.CTP
            ss.content = str(self.sym.text())
            m = Event(EventType.CANCEL)
            m.msg_type = MSG_TYPE.MSG_TYPE_CANCEL_ALL
            m.data = ss
            self.cancelall_signal.emit(m)