Exemple #1
0
    def test_is_done(self):
        order = NdaxInFlightOrder.from_json(self._example_json())

        self.assertFalse(order.is_done)

        for status in ["FullyExecuted", "Canceled", "Rejected", "Expired"]:
            order.last_state = status
            self.assertTrue(order.is_done)
Exemple #2
0
    def test_is_failure(self):
        order = NdaxInFlightOrder.from_json(self._example_json())

        for status in ["Working", "FullyExecuted", "Canceled", "Expired"]:
            order.last_state = status
            self.assertFalse(order.is_failure)

        order.last_state = "Rejected"
        self.assertTrue(order.is_failure)
 def restore_tracking_states(self, saved_states: Dict[str, Any]):
     """
     Restore in-flight orders from the saved tracking states(from local db). This is such that the connector can pick
     up from where it left off before Hummingbot client was terminated.
     :param saved_states: The saved tracking_states.
     """
     self._in_flight_orders.update({
         client_oid: NdaxInFlightOrder.from_json(order_json)
         for client_oid, order_json in saved_states.items()
     })
Exemple #4
0
    def test_update_with_trade_update(self):
        order = NdaxInFlightOrder.from_json(self._example_json())

        trade_update_for_different_order_id = {
            "OMSId": 1,
            "TradeId": 213,
            "OrderId": 5,
            "AccountId": 4,
            "ClientOrderId": 0,
            "InstrumentId": 1,
            "Side": "Buy",
            "Quantity": 0.01,
            "Price": 95,
            "Value": 0.95,
            "TradeTime": 635978008210426109,
            "ContraAcctId": 3,
            "OrderTradeRevision": 1,
            "Direction": "NoChange"
        }

        update_result = order.update_with_trade_update(
            trade_update_for_different_order_id)
        self.assertFalse(update_result)

        valid_trade_update = {
            "OMSId": 1,
            "TradeId": 213,
            "OrderId": 1,
            "AccountId": 4,
            "ClientOrderId": 0,
            "InstrumentId": 1,
            "Side": "Buy",
            "Quantity": 0.1,
            "Price": 35000,
            "Value": 3500,
            "TradeTime": 635978008210426109,
            "ContraAcctId": 3,
            "OrderTradeRevision": 1,
            "Direction": "NoChange"
        }

        update_result = order.update_with_trade_update(valid_trade_update)
        self.assertTrue(update_result)
        self.assertEqual(
            Decimal("0.1") +
            Decimal(self._example_json()["executed_amount_base"]),
            order.executed_amount_base)
        self.assertEqual(
            Decimal("3500") +
            Decimal(self._example_json()["executed_amount_quote"]),
            order.executed_amount_quote)

        repeated_trade_update = valid_trade_update
        update_result = order.update_with_trade_update(repeated_trade_update)
        self.assertFalse(update_result)
Exemple #5
0
    def test_create_from_json(self):
        order = NdaxInFlightOrder.from_json(self._example_json())

        self.assertEqual("C1", order.client_order_id)
        self.assertEqual("1", order.exchange_order_id)
        self.assertEqual("BTC-USDT", order.trading_pair)
        self.assertEqual(OrderType.LIMIT, order.order_type)
        self.assertEqual(TradeType.BUY, order.trade_type)
        self.assertEqual(Decimal("35000"), order.price)
        self.assertEqual(Decimal("1.1"), order.amount)
        self.assertEqual(Decimal("0.5"), order.executed_amount_base)
        self.assertEqual(Decimal("15000"), order.executed_amount_quote)
        self.assertEqual(order.base_asset, order.fee_asset)
        self.assertEqual(Decimal("0"), order.fee_paid)
        self.assertEqual("Working", order.last_state)
 def start_tracking_order(self, order_id: str,
                          exchange_order_id: Optional[str],
                          trading_pair: str, trade_type: TradeType,
                          price: Decimal, amount: Decimal,
                          order_type: OrderType):
     """
     Starts tracking an order by simply adding it into _in_flight_orders dictionary.
     """
     self._in_flight_orders[order_id] = NdaxInFlightOrder(
         client_order_id=order_id,
         exchange_order_id=exchange_order_id,
         trading_pair=trading_pair,
         order_type=order_type,
         trade_type=trade_type,
         price=price,
         amount=amount)
    def test_instance_creation(self):
        order = NdaxInFlightOrder(client_order_id="C1",
                                  exchange_order_id="1",
                                  trading_pair="BTC-USDT",
                                  order_type=OrderType.LIMIT,
                                  trade_type=TradeType.SELL,
                                  price=Decimal("35000"),
                                  amount=Decimal("1.1"))

        self.assertEqual("C1", order.client_order_id)
        self.assertEqual("1", order.exchange_order_id)
        self.assertEqual("BTC-USDT", order.trading_pair)
        self.assertEqual(OrderType.LIMIT, order.order_type)
        self.assertEqual(TradeType.SELL, order.trade_type)
        self.assertEqual(Decimal("35000"), order.price)
        self.assertEqual(Decimal("1.1"), order.amount)
        self.assertEqual(Decimal("0"), order.executed_amount_base)
        self.assertEqual(Decimal("0"), order.executed_amount_quote)
        self.assertEqual(order.quote_asset, order.fee_asset)
        self.assertEqual(Decimal("0"), order.fee_paid)
        self.assertEqual(WORKING_LOCAL_STATUS, order.last_state)
Exemple #8
0
    def test_mark_as_filled(self):
        order = NdaxInFlightOrder.from_json(self._example_json())

        order.mark_as_filled()
        self.assertEqual("FullyExecuted", order.last_state)
Exemple #9
0
    def test_to_json(self):
        order = NdaxInFlightOrder.from_json(self._example_json())

        self.assertEqual(self._example_json(), order.to_json())