コード例 #1
0
ファイル: binances_gateway.py プロジェクト: phybrain/mytrader
    def on_order(self, packet: dict) -> None:
        """"""
        ord_data = packet["o"]
        key = (ord_data["o"], ord_data["f"])
        order_type = ORDERTYPE_BINANCES2VT.get(key, None)
        if not order_type:
            return

        order = OrderData(
            symbol=ord_data["s"],
            exchange=Exchange.BINANCE,
            orderid=str(ord_data["c"]),
            type=order_type,
            direction=DIRECTION_BINANCES2VT[ord_data["S"]],
            price=float(ord_data["p"]),
            volume=float(ord_data["q"]),
            traded=float(ord_data["z"]),
            last_traded_volume=float(ord_data["l"]),
            status=STATUS_BINANCES2VT[ord_data["X"]],
            datetime=generate_datetime(packet["E"]),
            gateway_name=self.gateway_name
        )

        # Push trade event
        trade_volume = float(ord_data["l"])
        if trade_volume:
            trade_data = TradeData(
                symbol=order.symbol,
                exchange=order.exchange,
                orderid=order.orderid,
                tradeid=ord_data["t"],
                direction=order.direction,
                price=float(ord_data["L"]),
                volume=trade_volume,
                datetime=generate_datetime(ord_data["T"]),
                gateway_name=self.gateway_name,
            )
            order.trade_data = trade_data

        else:
            order.trade_data = None

        self.gateway.on_order(order)
コード例 #2
0
    def on_order(self, packet: dict):
        """"""
        if packet["C"] == "":
            orderid = packet["c"]
        else:
            orderid = packet["C"]

        order = OrderData(
            symbol=packet["s"].lower(),
            exchange=Exchange.BINANCE,
            orderid=orderid,
            type=ORDERTYPE_BINANCE2VT[packet["o"]],
            direction=DIRECTION_BINANCE2VT[packet["S"]],
            price=float(packet["p"]),
            volume=float(packet["q"]),
            traded=float(packet["z"]),
            status=STATUS_BINANCE2VT[packet["X"]],
            datetime=generate_datetime(packet["O"]),
            gateway_name=self.gateway_name
        )

        # Push trade event
        trade_volume = float(packet["l"])
        if trade_volume:
            trade_data = TradeData(
                symbol=order.symbol,
                exchange=order.exchange,
                orderid=order.orderid,
                tradeid=packet["t"],
                direction=order.direction,
                price=float(packet["L"]),
                volume=trade_volume,
                datetime=generate_datetime(packet["T"]),
                gateway_name=self.gateway_name,
            )

            order.trade_data = trade_data
        else:
            order.trade_data = None

        self.gateway.on_order(order)