def test_uuid32(self):
        with mock.patch(
                'hummingbot.connector.exchange.ascend_ex.ascend_ex_utils.random.choice'
        ) as random_choice_mock:
            random_choice_mock.return_value = 'a'

            uuid32 = utils.uuid32()
            self.assertEqual("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", uuid32)
예제 #2
0
    async def cancel_all(self, timeout_seconds: float):
        """
        Cancels all in-flight orders and waits for cancellation results.
        Used by bot's top level stop and exit commands (cancelling outstanding orders on exit)
        :param timeout_seconds: The timeout at which the operation will be canceled.
        :returns List of CancellationResult which indicates whether each order is successfully cancelled.
        """
        cancellation_results = []
        try:
            tracked_orders: Dict[
                str, AscendExInFlightOrder] = self._in_flight_orders.copy()

            api_params = {
                "orders": [{
                    'id':
                    ascend_ex_utils.uuid32(),
                    "orderId":
                    await order.get_exchange_order_id(),
                    "symbol":
                    ascend_ex_utils.convert_to_exchange_trading_pair(
                        order.trading_pair),
                    "time":
                    int(time.time() * 1e3)
                } for order in tracked_orders.values()]
            }

            await self._api_request(method="delete",
                                    path_url=CONSTANTS.ORDER_BATCH_PATH_URL,
                                    data=api_params,
                                    is_auth_required=True,
                                    force_auth_path_url="order/batch")

            open_orders = await self.get_open_orders()

            for cl_order_id, tracked_order in tracked_orders.items():
                open_order = [
                    o for o in open_orders if o.client_order_id == cl_order_id
                ]
                if not open_order:
                    cancellation_results.append(
                        CancellationResult(cl_order_id, True))
                    self.trigger_event(
                        MarketEvent.OrderCancelled,
                        OrderCancelledEvent(self.current_timestamp,
                                            cl_order_id))
                    self.stop_tracking_order(cl_order_id)
                else:
                    cancellation_results.append(
                        CancellationResult(cl_order_id, False))
        except Exception:
            self.logger().network(
                "Failed to cancel all orders.",
                exc_info=True,
                app_warning_msg=
                "Failed to cancel all orders on AscendEx. Check API key and network connection."
            )
        return cancellation_results
예제 #3
0
    async def cancel_all(self, timeout_seconds: float):
        """
        Cancels all in-flight orders and waits for cancellation results.
        Used by bot's top level stop and exit commands (cancelling outstanding orders on exit)
        :param timeout_seconds: The timeout at which the operation will be canceled.
        :returns List of CancellationResult which indicates whether each order is successfully cancelled.
        """
        order_ids_to_cancel = []
        cancel_payloads = []
        successful_cancellations = []
        failed_cancellations = []

        for order in filter(lambda active_order: not active_order.is_done,
                            self._in_flight_order_tracker.active_orders.values()):
            if order.exchange_order_id is not None:
                cancel_payloads.append({
                    "id": ascend_ex_utils.uuid32(),
                    "orderId": order.exchange_order_id,
                    "symbol": ascend_ex_utils.convert_to_exchange_trading_pair(order.trading_pair),
                    "time": int(time.time() * 1e3),
                })
                order_ids_to_cancel.append(order.client_order_id)
            else:
                failed_cancellations.append(CancellationResult(order.client_order_id, False))

        if cancel_payloads:
            try:
                api_params = {"orders": cancel_payloads}
                await self._api_request(
                    method="delete",
                    path_url=CONSTANTS.ORDER_BATCH_PATH_URL,
                    data=api_params,
                    is_auth_required=True,
                    force_auth_path_url="order/batch",
                )

                successful_cancellations = [CancellationResult(order_id, True) for order_id in order_ids_to_cancel]

            except Exception:
                self.logger().network(
                    "Failed to cancel all orders.",
                    exc_info=True,
                    app_warning_msg="Failed to cancel all orders on AscendEx. Check API key and network connection.",
                )
        return successful_cancellations + failed_cancellations