コード例 #1
0
    def from_json(cls, data: Dict[str, Any]) -> "GatewayInFlightOrder":
        """
        Initialize an InFlightOrder using a JSON object
        :param data: JSON data
        :return: Formatted InFlightOrder
        """
        order = GatewayInFlightOrder(
            client_order_id=data["client_order_id"],
            trading_pair=data["trading_pair"],
            order_type=getattr(OrderType, data["order_type"]),
            trade_type=getattr(TradeType, data["trade_type"]),
            amount=Decimal(data["amount"]),
            price=Decimal(data["price"]),
            exchange_order_id=data["exchange_order_id"],
            initial_state=OrderState(int(data["last_state"])),
            creation_timestamp=data.get("creation_timestamp", -1),
        )
        order.executed_amount_base = Decimal(data["executed_amount_base"])
        order.executed_amount_quote = Decimal(data["executed_amount_quote"])
        order.order_fills.update({
            key: TradeUpdate.from_json(value)
            for key, value in data.get("order_fills", {}).items()
        })
        order._nonce = data["nonce"]
        order._cancel_tx_hash = data["cancel_tx_hash"]
        order._gas_price = Decimal(data["gas_price"])

        order.check_filled_condition()

        return order
コード例 #2
0
    def test_json_deserialization(self):
        token_amount = TokenAmount(token="COINALPHA", amount=Decimal("20.6"))
        fee = DeductedFromReturnsTradeFee(percent=Decimal("0.5"),
                                          percent_token="COINALPHA",
                                          flat_fees=[token_amount])
        trade_update = TradeUpdate(
            trade_id="12345",
            client_order_id="OID1",
            exchange_order_id="EOID1",
            trading_pair="HBOT-COINALPHA",
            fill_timestamp=1640001112,
            fill_price=Decimal("1000.11"),
            fill_base_amount=Decimal("2"),
            fill_quote_amount=Decimal("2000.22"),
            fee=fee,
        )

        self.assertEqual(trade_update,
                         TradeUpdate.from_json(trade_update.to_json()))