示例#1
0
 def _order2zp(self, order):
     zp_order = ZPOrder(
         id=order.client_order_id,
         asset=symbol_lookup(order.symbol),
         amount=int(order.qty) if order.side == 'buy' else -int(order.qty),
         stop=float(order.stop_price) if order.stop_price else None,
         limit=float(order.limit_price) if order.limit_price else None,
         dt=order.submitted_at,
         commission=0,
     )
     zp_order.status = ZP_ORDER_STATUS.OPEN
     if order.canceled_at:
         zp_order.status = ZP_ORDER_STATUS.CANCELLED
     if order.failed_at:
         zp_order.status = ZP_ORDER_STATUS.REJECTED
     if order.filled_at:
         zp_order.status = ZP_ORDER_STATUS.FILLED
         zp_order.filled = int(order.filled_qty)
     return zp_order
    def tdx_order_to_zipline_order(self, order):
        """
        status
        0	已报
        1	部分成交
        2	全部成交
        3	部分撤单
        4	全部撤单
        5	交易所拒单
        6	柜台未接受

        :param order:
        :return:
        """
        if order.status == "3" or '4' == order.status:
            zp_status = ZP_ORDER_STATUS.CANCELLED
        elif order.status == "0":
            zp_status = ZP_ORDER_STATUS.OPEN
        elif order.status == "1":
            zp_status = ZP_ORDER_STATUS.FILLED
        elif order.status == "2":
            zp_status = ZP_ORDER_STATUS.HELD
        elif order.status == "5" or order.status == "6":
            zp_status = ZP_ORDER_STATUS.REJECTED


        zp_order_id = self._tdx_to_zp_order_id(order.order_id)

        od = ZPOrder(
            dt=order.dt,
            asset=symbol(order.symbol),
            amount=order.amount,
            filled=order.filled,
            stop=None,
            limit=order.price,  # TODO 市价单和限价单
            id=zp_order_id,
        )
        od.broker_order_id = order.order_id
        od.status = zp_status

        return od
示例#3
0
    def tdx_order_to_zipline_order(self, order):
        if order.status is not None and 'CANCEL' == order.status:
            zp_status = ZP_ORDER_STATUS.CANCELLED
        elif order.filled == 0:
            zp_status = ZP_ORDER_STATUS.OPEN
        else:
            zp_status = ZP_ORDER_STATUS.FILLED

        zp_order_id = self._tdx_to_zp_order_id(order.order_id)

        od = ZPOrder(
            dt=pd.to_datetime(order.dt),
            asset=symbol(order.symbol),
            amount=order.amount,
            filled=order.filled,
            stop=None,
            limit=order.price,  # TODO 市价单和限价单
            id=zp_order_id,
        )
        od.broker_order_id = order.order_id
        od.status = zp_status

        return od
示例#4
0
    def tdx_order_to_zipline_order(self, order):
        if order.status == '已撤':
            zp_status = ZP_ORDER_STATUS.CANCELLED
        elif order.filled == 0:
            zp_status = ZP_ORDER_STATUS.OPEN
        else:
            zp_status = ZP_ORDER_STATUS.FILLED

        zp_order_id = self._tdx_to_zp_order_id(order.order_id)

        od = ZPOrder(
            dt=pd.to_datetime(order.dt),
            asset=symbol(order.symbol),
            amount=order.amount,
            filled=order.filled,
            stop=None,
            limit=order.price,  # TODO 市价单和限价单
            id=zp_order_id,
        )
        od.broker_order_id = order.order_id
        od.status = zp_status

        return od