Search code examples
algorithmic-tradinghuobi

How to place this (from web GUI) stop loss order to close short position on huobi using rest API?


I'm trying to place a stop loss to that should trigger to "close" a short position on Huobi via the rest API.

This is the position currently, about 3.4% in profit:

enter image description here

The current order book looks like so:

enter image description here

Via the web interface I can easily enter a stop loss trigger price of 0.066065 USDT like so:

enter image description here

After which this order is actually accepted:

enter image description here

However, via the rest API I don't manage.

I'm using the end-point: POST /linear-swap-api/v1/swap_cross_order

Question:

What POST parameters to send?

When I'm sending this:

{'contract_code': 'TRX-USDT',
 'direction': 'buy',
 'lever_rate': 1,
 'offset': 'close',
 'order_price_type': 'limit',
 'sl_trigger_price': 0.066065,
 'volume': '14'}

I get an error:

The price is not reasonable.

and when I try this:

{'contract_code': 'TRX-USDT',
 'direction': 'buy',
 'lever_rate': 1,
 'offset': 'close',
 'order_price_type': 'market',
 'sl_trigger_price': 0.066065,
 'volume': '14'}

I get Open a position with market price is not available.contracts

In reaction to the last error message I even tried this:

{'contract_code': 'TRX-USDT',
 'direction': 'sell',
 'lever_rate': 1,
 'offset': 'open',
 'order_price_type': 'limit',
 'sl_trigger_price': 0.066065,
 'volume': '14'}

Getting also the: The price is not reasonable.

So ... how do I do this?


Solution

  • Looks like I was using the wrong end-point.

    This is the correct end-point:

    POST /linear-swap-api/v1/swap_cross_trigger_order

    With these parameters:

    {'contract_code': 'TRX-USDT',
     'direction': 'buy',
     'lever_rate': 1,
     'offset': 'close',
     'order_price': 0.06607,
     'order_price_type': 'limit',
     'trigger_price': 0.066065,
     'trigger_type': 'ge',
     'volume': 28}
    

    Leading to the stop loss as desired:

    enter image description here