2

I am using the python-binance API wrapper. After successfully sending a 'normal' MARKET order, I want to send in a STOP_LOSS_LIMIT order. If I'm not mistaken this is a subtype of Stop-Limit orders. This is what they are called in the Binance UI on the app.

Anyway, this is my code for the STOP_LOSS_LIMIT order:

order2 = client.create_order(
   symbol='BTCUSDT',
   side=SIDE_SELL,
   type=ORDER_TYPE_STOP_LOSS_LIMIT,
   TimeInForce=TIME_IN_FORCE_GTC,
   stopPrice='33000',
   price = '30000'
   )

I get the following response:

Not all sent parameters were read; read '7' parameter(s) but was sent '8'.

Obviously there is something fundamentally wrong with the code. Can someone provide me with an example for this type of orders. What are the necessary parameters and what do they do. Please do not link me the official documentation. Sadly, there are no examples for these types.

3 Answers3

3

Seems like what I was trying to achieve is not possible with Spot trading. Once I switched to Futures, it all worked out. This is how I set the leverage to 1:

client.futures_change_leverage(symbol='BNBUSDT', leverage=1) 

I conclude that Stop Loss/Take Profit orders do not work with Spot trading, either by design (which actually makes sense), or because of some bugs.

Anyway, if anyone ever hits the same wall, this is how to set a stop loss order on existing Futures (buy) orders in python-binance

FuturesStopLoss =client.futures_create_order(
   symbol='BNBUSDT',
   type='STOP_MARKET',
   side='SELL',
   stopPrice=220,
   closePosition=True
   )

Changing side to BUY sets a stop loss order on existing sell orders.

P.S. Achieving the same with Spot trading is most likely possible by using Websocket streams and executing Market orders when desired prices are reached. However I did not want to go with that route.

1

By API you can make it with this structure

StopLoss

API POST https://fapi.binance.com/fapi/v1/order

{
  "side": "BUY",
  "stopPrice": 40100,        
  "symbol": "BTCUSDT"
}
Julio Vinachi
  • 381
  • 4
  • 8
0

Отложенный ордер на продажу (Pending sell order)

order = client.order_limit_sell(
    symbol=symbol,
    timeInForce=TIME_IN_FORCE_GTC,
    type=ORDER_TYPE_LIMIT,
    side=SIDE_SELL,
    quantity=2.89,
    price='5.26')
  • 2
    Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?** – Jeremy Caney May 27 '23 at 01:15