Ejemplo n.º 1
0
    def test_client_order_id_on_order(self, mocked_nonce):
        mocked_nonce.return_value = 8

        result = self.exchange.buy(
            trading_pair=self.trading_pair,
            amount=Decimal("1"),
            order_type=OrderType.LIMIT,
            price=Decimal("2"),
        )
        expected_client_order_id = get_new_client_order_id(
            is_buy=True, trading_pair=self.trading_pair, hbot_order_id_prefix=huobi_utils.BROKER_ID
        )

        self.assertEqual(result, expected_client_order_id)

        result = self.exchange.sell(
            trading_pair=self.trading_pair,
            amount=Decimal("1"),
            order_type=OrderType.LIMIT,
            price=Decimal("2"),
        )
        expected_client_order_id = get_new_client_order_id(
            is_buy=False, trading_pair=self.trading_pair, hbot_order_id_prefix=huobi_utils.BROKER_ID
        )

        self.assertEqual(result, expected_client_order_id)
    def test_client_order_id_on_order(self, mocked_nonce):
        mocked_nonce.return_value = 7

        result = self.exchange.buy(
            trading_pair=self.trading_pair,
            amount=Decimal("1"),
            order_type=OrderType.LIMIT,
            price=Decimal("2"),
        )
        expected_client_order_id = get_new_client_order_id(
            is_buy=True,
            trading_pair=self.trading_pair,
            hbot_order_id_prefix=CONSTANTS.HBOT_ORDER_ID,
            max_id_len=CONSTANTS.MAX_ID_LEN,
        )

        self.assertEqual(result, expected_client_order_id)

        result = self.exchange.sell(
            trading_pair=self.trading_pair,
            amount=Decimal("1"),
            order_type=OrderType.LIMIT,
            price=Decimal("2"),
        )
        expected_client_order_id = get_new_client_order_id(
            is_buy=False,
            trading_pair=self.trading_pair,
            hbot_order_id_prefix=CONSTANTS.HBOT_ORDER_ID,
            max_id_len=CONSTANTS.MAX_ID_LEN,
        )

        self.assertEqual(result, expected_client_order_id)
Ejemplo n.º 3
0
    def test_get_new_client_order_id(self):
        host_prefix = "hbot"

        id0 = get_new_client_order_id(is_buy=True, trading_pair=self.trading_pair)
        id1 = get_new_client_order_id(is_buy=True, trading_pair=self.trading_pair, hbot_order_id_prefix=host_prefix)

        self.assertFalse(id0.startswith(host_prefix))
        self.assertTrue(id1.startswith(host_prefix))

        id2 = get_new_client_order_id(is_buy=True, trading_pair=self.trading_pair, max_id_len=len(id0) - 2)

        self.assertEqual(len(id0) - 2, len(id2))
Ejemplo n.º 4
0
    def sell(self,
             trading_pair: str,
             amount: Decimal,
             order_type=OrderType.MARKET,
             price: Decimal = s_decimal_NaN,
             **kwargs) -> str:
        """
        Creates a promise to create a sell order using the parameters

        :param trading_pair: the token pair to operate with
        :param amount: the order amount
        :param order_type: the type of order to create (MARKET, LIMIT, LIMIT_MAKER)
        :param price: the order price

        :return: the id assigned by the connector to the order (the client id)
        """
        order_id = get_new_client_order_id(
            is_buy=False, trading_pair=trading_pair, max_id_len=CONSTANTS.MAX_ORDER_ID_LEN
        )

        safe_ensure_future(self._create_order(
            trade_type=TradeType.SELL,
            order_id=order_id,
            trading_pair=trading_pair,
            amount=amount,
            order_type=order_type,
            price=price))
        return order_id
Ejemplo n.º 5
0
    def test_rest_auth_post_order_size_too_high(self):
        new_order_id = get_new_client_order_id(
            is_buy=True,
            trading_pair="LA-USDT",
            hbot_order_id_prefix=CONSTANTS.HBOT_ORDER_ID_PREFIX,
            max_id_len=CONSTANTS.MAX_ORDER_ID_LEN,
        )

        base_id, quote_id = self.ev_loop.run_until_complete(
            self.get_tag_by_id(self.trading_pair))
        result = self.ev_loop.run_until_complete(
            self.rest_auth_post(
                json={
                    "baseCurrency": base_id,
                    "quoteCurrency": quote_id,
                    "side": "BID",
                    "condition": "GTC",
                    "type": "LIMIT",
                    "clientOrderId": new_order_id,
                    "price": "10103.000000000000000000000000019",  # false
                    "quantity": "3.21",
                    "timestamp": 1568185507
                }))
        if "status" not in result:
            print(f"Unexpected response for API call: {result}")
        assert "status" in result.keys()
        assert "FAILURE" == result['status']
        assert 'VALIDATION_ERROR' == result['error']
        assert 'price' in result['errors']
Ejemplo n.º 6
0
 def sell(self,
          trading_pair: str,
          amount: Decimal,
          order_type=OrderType.LIMIT,
          price: Decimal = s_decimal_NaN,
          **kwargs) -> str:
     """
     Sells an amount of base asset (of the given trading pair). This function returns immediately.
     To see an actual order, you'll have to wait for SellOrderCreatedEvent.
     :param trading_pair: The market (e.g. BTC-USDT) to sell from
     :param amount: The amount in base token value
     :param order_type: The order type
     :param price: The price (note: this is no longer optional)
     :returns A new internal order id
     """
     order_id = get_new_client_order_id(
         is_buy=False,
         trading_pair=trading_pair,
         hbot_order_id_prefix=CONSTANTS.HBOT_ORDER_ID,
         max_id_len=CONSTANTS.MAX_ID_LEN,
     )
     safe_ensure_future(
         self._create_order(TradeType.SELL, order_id, trading_pair, amount,
                            order_type, price))
     return order_id
Ejemplo n.º 7
0
    def buy(self,
            trading_pair: str,
            amount: Decimal,
            order_type=OrderType.LIMIT,
            price: Decimal = s_decimal_NaN,
            **kwargs) -> str:
        """
        Creates a promise to create a buy order using the parameters

        :param trading_pair: the token pair to operate with
        :param amount: the order amount
        :param order_type: the type of order to create (MARKET, LIMIT, LIMIT_MAKER)
        :param price: the order price

        :return: the id assigned by the connector to the order (the client id)
        """
        order_id = get_new_client_order_id(
            is_buy=True,
            trading_pair=trading_pair,
            hbot_order_id_prefix=self.client_order_id_prefix,
            max_id_len=self.client_order_id_max_length)
        safe_ensure_future(
            self._create_order(trade_type=TradeType.BUY,
                               order_id=order_id,
                               trading_pair=trading_pair,
                               amount=amount,
                               order_type=order_type,
                               price=price))
        return order_id
 def sell(self,
          trading_pair: str,
          amount: Decimal,
          order_type=OrderType.MARKET,
          price: Decimal = s_decimal_NaN,
          **kwargs) -> str:
     client_order_id: str = get_new_client_order_id(
         is_buy=False,
         trading_pair=trading_pair,
         hbot_order_id_prefix=CONSTANTS.BROKER_ID,
         max_id_len=CONSTANTS.MAX_ORDER_ID_LEN,
     )
     safe_ensure_future(
         self.execute_sell(client_order_id, trading_pair, amount,
                           order_type, price))
     return client_order_id
Ejemplo n.º 9
0
 def buy(self, trading_pair: str, amount: Decimal, order_type: OrderType = OrderType.LIMIT,
         price: Decimal = s_decimal_NaN, **kwargs) -> str:
     """
     Creates a promise to create a buy order using the parameters.
     :param trading_pair: the token pair to operate with
     :param amount: the order amount
     :param order_type: the type of order to create (MARKET, LIMIT, LIMIT_MAKER)
     :param price: the order price
     :return: the id assigned by the connector to the order (the client id)
     """
     client_order_id = get_new_client_order_id(
         is_buy=True,
         trading_pair=trading_pair,
         hbot_order_id_prefix=CONSTANTS.HBOT_ORDER_ID_PREFIX,
         max_id_len=CONSTANTS.MAX_ORDER_ID_LEN,
     )
     safe_ensure_future(self._create_order(TradeType.BUY, client_order_id, trading_pair, amount, order_type, price))
     return client_order_id
Ejemplo n.º 10
0
    def test_rest_auth_post(self):
        new_order_id = get_new_client_order_id(
            is_buy=True,
            trading_pair=self.trading_pair,
            hbot_order_id_prefix=CONSTANTS.HBOT_ORDER_ID_PREFIX,
            max_id_len=CONSTANTS.MAX_ORDER_ID_LEN,
        )
        base_id, quote_id = self.ev_loop.run_until_complete(
            self.get_tag_by_id(self.trading_pair))
        # result = self.ev_loop.run_until_complete(self.rest_auth_post(json=payload.JsonPayload({
        #     "baseCurrency": base_id,
        #     "quoteCurrency": quote_id,
        #     "side": "BID",
        #     "condition": "GTC",
        #     "type": "LIMIT",
        #     "clientOrderId": new_order_id,
        #     "price": "10103.19",
        #     "quantity": ".001",
        #     "timestamp": 1568185507
        # }, dumps=ujson.dumps)))

        result = self.ev_loop.run_until_complete(
            self.rest_auth_post(
                json={
                    "baseCurrency": base_id,
                    "quoteCurrency": quote_id,
                    "side": "BID",
                    "condition": "GTC",
                    "type": "LIMIT",
                    "clientOrderId": new_order_id,
                    "price": "10103.19",
                    "quantity": ".001",
                    "timestamp": 1568185507
                }))
        if "status" not in result:
            print(f"Unexpected response for API call: {result}")
        assert "status" in result.keys()
        assert "SUCCESS" == result['status']