Binance.net 包装器设置 TP 和 SL 问题 c#

发布于 2025-01-17 06:38:29 字数 347 浏览 1 评论 0原文

我使用 Binance.net 包装器,我可以开仓(期货),但开仓后我无法设置 tp 和 sl

  var orderData = await binanceClient.UsdFuturesApi.Trading.PlaceOrderAsync(
            "BTCUSDT",
            OrderSide.Sell,
            FuturesOrderType.Limit,
            0.002m,
            ep,
            timeInForce: TimeInForce.GoodTillCanceled);

请帮助我

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由范儿 2025-01-24 06:38:29

该库或币安的 api 无法帮助您在一次请求时创建带有 TP/SL 的订单。您应该将其分成 3 个订单。例如买入/做多

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
                           );

一旦限价订单成功

     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
                         );
    
     }

更新(2022年4月23日)

您应该为下单TP&添加closePosition:true SL

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文