コード例 #1
0
ファイル: oes_td.py プロジェクト: Alyle/vnpy
    def send_order(self, vt_req: OrderRequest):
        """"""
        seq_id = self._get_new_seq_index()
        order_id = seq_id

        oes_req = OesOrdReqT()
        oes_req.clSeqNo = seq_id
        oes_req.mktId = EXCHANGE_VT2OES[vt_req.exchange]
        oes_req.ordType = ORDER_TYPE_VT2OES[(vt_req.exchange, vt_req.type)]
        oes_req.bsType = BUY_SELL_TYPE_VT2OES[(vt_req.exchange, vt_req.offset, vt_req.direction)]
        oes_req.invAcctId = ""
        oes_req.securityId = vt_req.symbol
        oes_req.ordQty = int(vt_req.volume)
        oes_req.ordPrice = int(vt_req.price * 10000)
        oes_req.origClOrdId = order_id

        order = vt_req.create_order_data(str(order_id), self.gateway.gateway_name)
        order.direction = Direction.NET  # fix direction into NET: stock only
        self._order_manager.save_order(order_id, order)

        ret = OesApi_SendOrderReq(self._env.ordChannel,
                                  oes_req
                                  )

        if ret >= 0:
            order.status = Status.SUBMITTING
        else:
            order.status = Status.REJECTED
            self.gateway.write_log(_("下单失败"))  # todo: can I stringify error?
            if is_disconnected(ret):
                self.gateway.write_log(_("下单时连接发现连接已断开,正在尝试重连"))
                self._schedule_reconnect_ord_channel()
        self.gateway.on_order(order)

        return order.vt_orderid
コード例 #2
0
ファイル: oes_td.py プロジェクト: hjjwinner/VN_PY_PROJECT
    def send_order(self, vt_req: OrderRequest):
        """"""
        seq_id = self._get_new_seq_index()
        order_id = seq_id

        oes_req = OesOrdReqT()
        oes_req.clSeqNo = seq_id
        oes_req.mktId = EXCHANGE_VT2OES[vt_req.exchange]
        oes_req.ordType = ORDER_TYPE_VT2OES[(vt_req.exchange, vt_req.type)]
        oes_req.bsType = BUY_SELL_TYPE_VT2OES[(vt_req.exchange, vt_req.offset, vt_req.direction)]
        oes_req.invAcctId = ""
        oes_req.securityId = vt_req.symbol
        oes_req.ordQty = int(vt_req.volume)
        oes_req.ordPrice = int(vt_req.price * 10000)
        oes_req.origClOrdId = order_id

        order = vt_req.create_order_data(str(order_id), self.gateway.gateway_name)
        order.direction = Direction.NET  # fix direction into NET: stock only
        self._order_manager.save_order(order_id, order)

        ret = OesApi_SendOrderReq(self._env.ordChannel,
                                  oes_req
                                  )

        if ret >= 0:
            order.status = Status.SUBMITTING
        else:
            order.status = Status.REJECTED
            self.gateway.write_log(_("下单失败"))  # todo: can I stringify error?
            if is_disconnected(ret):
                self.gateway.write_log(_("下单时连接发现连接已断开,正在尝试重连"))
                self._schedule_reconnect_ord_channel()
        self.gateway.on_order(order)

        return order.vt_orderid
コード例 #3
0
ファイル: oes_md.py プロジェクト: TradingHacker/vnpy_charting
 def _message_loop(self):
     """"""
     tcp_channel = self.env.tcpChannel
     timeout_ms = 1000
     while self._alive:
         ret = MdsApi_WaitOnMsg(tcp_channel, timeout_ms, self._on_message)
         if ret < 0:
             # if is_timeout(ret):
             #     pass  # just no message
             if is_disconnected(ret):
                 self.gateway.write_log(_("与行情服务器的连接已断开。"))
                 while self._alive and not self.reconnect():
                     time.sleep(1)
     return
コード例 #4
0
ファイル: oes_md.py プロジェクト: Alyle/vnpy
 def _message_loop(self):
     """"""
     tcp_channel = self.env.tcpChannel
     timeout_ms = 1000
     while self._alive:
         ret = MdsApi_WaitOnMsg(tcp_channel,
                                timeout_ms,
                                self._on_message)
         if ret < 0:
             # if is_timeout(ret):
             #     pass  # just no message
             if is_disconnected(ret):
                 self.gateway.write_log(_("与行情服务器的连接已断开。"))
                 while self._alive and not self.reconnect():
                     time.sleep(1)
     return
コード例 #5
0
ファイル: oes_td.py プロジェクト: TradingHacker/vnpy_charting
    def _message_loop(self):
        """"""
        rpt_channel = self._env.rptChannel
        timeout_ms = 1000

        while self._alive:
            ret = OesApi_WaitReportMsg(rpt_channel, timeout_ms,
                                       self._on_message)
            if ret < 0:
                # if is_timeout(ret):
                #     pass  # just no message
                if is_disconnected(ret):
                    self.gateway.write_log(_("与交易服务器的连接已断开。"))
                    while self._alive and not self.reconnect():
                        pass
        return
コード例 #6
0
ファイル: oes_td.py プロジェクト: Alyle/vnpy
    def _message_loop(self):
        """"""
        rpt_channel = self._env.rptChannel
        timeout_ms = 1000

        while self._alive:
            ret = OesApi_WaitReportMsg(rpt_channel,
                                       timeout_ms,
                                       self._on_message)
            if ret < 0:
                # if is_timeout(ret):
                #     pass  # just no message
                if is_disconnected(ret):
                    self.gateway.write_log(_("与交易服务器的连接已断开。"))
                    while self._alive and not self.reconnect():
                        pass
        return
コード例 #7
0
ファイル: oes_td.py プロジェクト: hjjwinner/VN_PY_PROJECT
    def cancel_order(self, vt_req: CancelRequest):
        """"""
        seq_id = self._get_new_seq_index()

        oes_req = OesOrdCancelReqT()
        order_id = int(vt_req.orderid)
        oes_req.mktId = EXCHANGE_VT2OES[vt_req.exchange]

        oes_req.clSeqNo = seq_id
        oes_req.origClSeqNo = order_id
        oes_req.invAcctId = ""
        oes_req.securityId = vt_req.symbol

        ret = OesApi_SendOrderCancelReq(self._env.ordChannel,
                                        oes_req)
        if ret < 0:
            self.gateway.write_log(_("撤单失败"))  # todo: can I stringify error?
            if is_disconnected(ret):  # is here any other ret code indicating connection lost?
                self.gateway.write_log(_("撤单时连接发现连接已断开,正在尝试重连"))
                self._schedule_reconnect_ord_channel()
コード例 #8
0
ファイル: oes_td.py プロジェクト: Alyle/vnpy
    def cancel_order(self, vt_req: CancelRequest):
        """"""
        seq_id = self._get_new_seq_index()

        oes_req = OesOrdCancelReqT()
        order_id = int(vt_req.orderid)
        oes_req.mktId = EXCHANGE_VT2OES[vt_req.exchange]

        oes_req.clSeqNo = seq_id
        oes_req.origClSeqNo = order_id
        oes_req.invAcctId = ""
        oes_req.securityId = vt_req.symbol

        ret = OesApi_SendOrderCancelReq(self._env.ordChannel,
                                        oes_req)
        if ret < 0:
            self.gateway.write_log(_("撤单失败"))  # todo: can I stringify error?
            if is_disconnected(ret):  # is here any other ret code indicating connection lost?
                self.gateway.write_log(_("撤单时连接发现连接已断开,正在尝试重连"))
                self._schedule_reconnect_ord_channel()