Example #1
0
    def test_cancel_order_already_canceled(self, time_mock):
        self._simulate_trading_rules_initialized()

        resp = Response()
        resp.status_code = 429
        resp._content = b'{"errors": [{"msg": "Order with specified id: EOID1 is already canceled"}]}'

        time_mock.return_value = 1640001112.223

        time_mock.side_effect = DydxApiError(resp)

        self.exchange.start_tracking_order(
            order_side=TradeType.BUY,
            client_order_id="OID1",
            order_type=OrderType.LIMIT,
            created_at=1640001112.223,
            hash="hashcode",
            trading_pair=self.trading_pair,
            price=Decimal(1000),
            amount=Decimal(1),
            leverage=Decimal(1),
            position="position",
        )

        self.assertTrue("OID1" in self.exchange.in_flight_orders)

        self.async_run_with_timeout(self.exchange.cancel_order(
            client_order_id="OID1"
        ))

        self.assertFalse("OID1" in self.exchange.in_flight_orders)
Example #2
0
    def test_update_funding_fails_on_other_dydx_api_error(self, get_markets_mock: AsyncMock):
        resp = Response()
        resp.status_code = 430
        resp._content = b'{"errors": [{"msg": "Some other dydx API error."}]}'
        get_markets_mock.return_value = DydxApiError(resp)

        self.async_run_with_timeout(self.exchange._update_funding_rates())

        self.check_is_logged(log_level="NETWORK", message="dYdX API error.")
Example #3
0
    def test_update_funding_fails_on_rate_limit(self, get_markets_mock: AsyncMock):
        resp = Response()
        resp.status_code = 429
        resp._content = b'{"errors": [{"msg": "Too many requests"}]}'
        get_markets_mock.return_value = DydxApiError(resp)

        self.async_run_with_timeout(self.exchange._update_funding_rates())

        self.check_is_logged(log_level="NETWORK", message="Rate-limit error.")