'Binance.net wrapper Set TP and SL Problem c#
i use Binance.net wrapper , i can open position (Futures) , but i cant set tp and sl after open position
var orderData = await binanceClient.UsdFuturesApi.Trading.PlaceOrderAsync(
"BTCUSDT",
OrderSide.Sell,
FuturesOrderType.Limit,
0.002m,
ep,
timeInForce: TimeInForce.GoodTillCanceled);
please help me
Solution 1:[1]
this library or Binance's api doesn't help you to create one order with TP/SL at one request. You should split it into 3 orders. For example to Buy/Long
var limitOrderResult = await _binanceClient.UsdFuturesApi.Trading.PlaceOrderAsync(
symbol: "BTCUSDT",
side: OrderSide.Buy,
type: FuturesOrderType.Limit,
quantity: 1,
price: 0.002m,
orderResponseType: OrderResponseType.Result,
positionSide: PositionSide.Long,
workingType: WorkingType.Mark,
timeInForce: TimeInForce.GoodTillCanceled
);
Once the limitOrder is successful
if (limitOrderResult.Success) {
// take profit
var tpOrderResult = await _binanceClient.UsdFuturesApi.Trading.PlaceOrderAsync(
symbol: "BTCUSDT",
side: OrderSide.Sell,
type: FuturesOrderType.TakeProfitMarket,
quantity: 1,
stopPrice: 0.003m, // take profit price
orderResponseType: OrderResponseType.Result,
positionSide: PositionSide.Long,
workingType: WorkingType.Mark,
timeInForce: TimeInForce.GoodTillCanceled,
closePosition: true // add this
);
// stop loss
var slOrderResultTask = _binanceClient.UsdFuturesApi.Trading.PlaceOrderAsync(
symbol: "BTCUSDT",
side: OrderSide.Sell,
type: FuturesOrderType.StopMarket,
quantity: 1,
stopPrice: 0.001, // stop loss price
orderResponseType: OrderResponseType.Result,
positionSide: PositionSide.Long,
workingType: WorkingType.Mark,
timeInForce: TimeInForce.GoodTillCanceled,
closePosition: true // add this
);
}
UPDATED (2022 April 23)
You should add closePosition: true for place order TP & SL
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |