JKorf / Bybit.Net

A C# .netstandard client library for the Bybit REST and Websocket V5 API focusing on clear usage and models
https://jkorf.github.io/Bybit.Net/
92 stars 64 forks source link

Add partial tp/sl orders to existing position. #234

Closed slavslavin closed 1 week ago

slavslavin commented 2 weeks ago

HI, Is it possible to add tp/sl partial orders after postion has ben opened?

Example: Postion entry price: 100 Quantity: 100 some coins

I want to add next orders: Market takeprofit for 50 coins with price 120 Market stop loss for 50 coins with price 80

Market takeprofit for 50 coins with price 140 Market stop loss for 50 coins with price 60

I use next code to add Take profit order:

await client.V5Api.Trading.PlaceOrderAsync(Category.Linear, symbol,
                                           side: OrderSide.Sell,
                                           type: NewOrderType.Market,
                                           quantity: 50,
                                           timeInForce: TimeInForce.GoodTillCanceled,
                                           reduceOnly: true,
                                           price: null,
                                           closeOnTrigger: false,
                                           clientOrderId: "myClientOrderId",
                                           takeProfitTriggerBy: TriggerType.LastPrice,
                                           takeProfitOrderType: OrderType.Market,
                                           takeProfit: 120,
                                           stopLossTakeProfitMode: StopLossTakeProfitMode.Partial);

Stop loss order:

await client.V5Api.Trading.PlaceOrderAsync(Category.Linear, symbol,
                                           side: OrderSide.Sell,
                                           type: NewOrderType.Market,
                                           quantity: 50,
                                           timeInForce: TimeInForce.GoodTillCanceled,
                                           reduceOnly: true,
                                           price: null,
                                           triggerBy: TriggerType.LastPrice,
                                           closeOnTrigger: false,
                                           clientOrderId: clientOrderId,
                                           stopLossOrderType: OrderType.Market,
                                           stopLoss: 80,
                                           stopLossTakeProfitMode: StopLossTakeProfitMode.Partial);

But it doesnt work.

Could you help me?

JKorf commented 2 weeks ago

Hi, yes that is possible, but for existing positions you should use client.V5Api.Trading.SetTradingStopAsync instead