Ejemplo n.º 1
0
    def connect(self, userid: str, password: str, client_id: int,
                server_ip: str, server_port: int, quote_protocol: str):
        """"""
        if self.api:
            return

        self.userid = userid
        self.password = password
        self.client_id = client_id
        self.server_ip = server_ip
        self.server_port = server_port

        if quote_protocol == "CTP":
            self.quote_protocol = XTP_PROTOCOL_TYPE.XTP_PROTOCOL_TCP
        else:
            self.quote_protocol = XTP_PROTOCOL_TYPE.XTP_PROTOCOL_UDP

        # Create API object
        path = str(get_folder_path(self.gateway_name.lower()))

        self.api = API.QuoteApi.CreateQuoteApi(
            self.client_id, path, XTP_LOG_LEVEL.XTP_LOG_LEVEL_TRACE)

        self.api.RegisterSpi(self)
        self.gateway.write_log("行情接口初始化成功")

        # Login to server
        Thread(target=self.login).start()
Ejemplo n.º 2
0
    def connect(self, userid: str, password: str, client_id: int,
                server_ip: str, server_port: int, software_key: str):
        """"""
        if self.api:
            return

        self.userid = userid
        self.password = password
        self.client_id = client_id
        self.server_ip = server_ip
        self.server_port = server_port
        self.software_key = software_key

        # Create API object
        path = str(get_folder_path(self.gateway_name.lower()))

        self.api = API.TraderApi.CreateTraderApi(
            self.client_id, path, XTP_LOG_LEVEL.XTP_LOG_LEVEL_TRACE)

        self.api.RegisterSpi(self)
        self.api.SetSoftwareKey(self.software_key)
        self.api.SubscribePublicTopic(XTP_TE_RESUME_TYPE.XTP_TERT_RESTART)

        self.gateway.write_log("交易接口初始化成功")

        # Login to server
        Thread(target=self.login).start()
Ejemplo n.º 3
0
 def connect(self, address: str, userid: str, password: str, brokerid: int):
     """
     Start connection to server.
     """
     self.userid = userid
     self.password = password
     self.brokerid = brokerid
     
     # If not connected, then start connection first.
     if not self.connect_status:
         path = get_folder_path(self.gateway_name.lower())
         self.createFtdcMdApi(str(path) + "\\Md")
         
         self.registerFront(address)
         self.init()
     # If already connected, then login immediately.
     elif not self.login_status:
         self.login()
Ejemplo n.º 4
0
 def connect(self, address: str, userid: str, password: str, brokerid: int, auth_code: str, appid: str):
     """
     Start connection to server.
     """
     self.userid = userid
     self.password = password
     self.brokerid = brokerid
     self.auth_code = auth_code
     self.appid = appid
     
     if not self.connect_status:
         path = get_folder_path(self.gateway_name.lower())
         self.createFtdcTraderApi(str(path) + "\\Td")
         
         self.subscribePrivateTopic(0)
         self.subscribePublicTopic(0)
         
         self.registerFront(address)
         self.init()            
     else:
         self.authenticate()
Ejemplo n.º 5
0
    def connect(self, address: str, userid: str, password: str, brokerid: int):
        """
        Start connection to server.
        """
        self.userid = userid
        self.password = password
        self.brokerid = brokerid
        self.address = address

        if not self.connect_status:
            path = get_folder_path(self.gateway_name.lower())
            self.createFtdcTraderApi(str(path) + "\\Td")

            self.subscribePrivateTopic(0)
            self.subscribePublicTopic(0)
            self.subscribeUserTopic(0)

            self.registerFront(address)
            self.init()
        else:
            if not self.login_status:
                self.login()