Reputation: 81
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.
Upvotes: 3
Views: 10316
Reputation: 1
Отложенный ордер на продажу (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')
Upvotes: 0
Reputation: 388
By API you can make it with this structure
API POST https://fapi.binance.com/fapi/v1/order
{
"side": "BUY",
"stopPrice": 40100,
"symbol": "BTCUSDT"
}
Upvotes: 1
Reputation: 81
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.
Upvotes: 3