JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.05k stars 429 forks source link

Futures PlaceOrder and - set up take profit #734

Open Adamszsz opened 3 years ago

Adamszsz commented 3 years ago

I try to find solution about place order. How can i set Take profit when i place order?

var otwarte_pozycje = client.FuturesUsdt.Order.PlaceOrder("BTCUSDT", OrderSide.Sell, OrderType.Limit, 1, PositionSide.Short, TimeInForce.GoodTillCancel, price: 57000M); How can i set take profit or stop loss?

mkleo21 commented 3 years ago

Were you able to make this work? I am not able to set a Stop Loss or Take Profit while placing an order.

mimfa commented 3 years ago

I'm involving with this problem too... Is there anybody to answer us?

gitaweb commented 3 years ago

yeah ,I'm involving with this problem too.. anybody can give us a tips ?

KingIthra commented 2 years ago

December 2021 - I have been trying to place orders along with stop loss and take profit since October 2020. Has anyone been able to do this successfully? I heard you may open an order first and then send two more orders as TP and SL, i have been trying to implement this, No success. Can someone show us an example in code?

sinaptech commented 2 years ago

Can anyone solve this problem?

eros1453 commented 2 years ago

https://github.com/JKorf/Binance.Net/issues/1005

eros1453 commented 2 years ago

This works too but you have to make a market buy order to catch the await for the other orders

eros1453 commented 2 years ago

You can mess with this code its for winform There is some logic you can miss, its getting the data from orderbook and winform app.

`private void BesLongLimitbutton_Click(object sender, EventArgs e) { Task.Run(async () => { LongTradeAmount = tradeable_balance (Convert.ToDecimal(Properties.Settings.Default.TRADEPERCENT) / 100); decimal trade_amount = Math.Round(LongTradeAmount Leverage / bestBid, QUANTITYPRECISION); BesLongOrder_TP = Math.Round(bestAsk, PRICEPRECISION); using (var bfc = new BinanceClient()) { var BesLongorder_SellResult = await bfc.UsdFuturesApi.Trading.PlaceOrderAsync(ASSET, side: OrderSide.Buy, positionSide: PositionSide.Long, type: FuturesOrderType.Limit, quantity: trade_amount, price: bestBid, timeInForce: TimeInForce.GoodTillCrossing) ;

                if (BesLongorder_SellResult.Success)
                {
                    //var startTrail_trailing = bfc.UsdFuturesApi.Trading.PlaceOrder(ASSET, side: OrderSide.Sell, positionSide: PositionSide.Short, type: FuturesOrderType.TrailingStopMarket, quantity: BesLongorder_SellResult.Data.ExecutedQuantity, timeInForce: TimeInForce.GoodTillCanceled, callbackRate: "0.25", activationPrice: BesLongorder_SellResult.Data.Price * 1, 0025);
                    //MessageBox.Show(BesLongorder_SellResult.Data.ToString());
                    long_quantity = trade_amount;
                    long_price = BesLongorder_SellResult.Data.Price;
                    actpr = Math.Round(BesLongOrder_TP * 1.000454545M, PRICEPRECISION);
                    calbck = 0.2M;
                    var startTrail_trailing = await bfc.UsdFuturesApi.Trading.PlaceOrderAsync(ASSET, side: OrderSide.Sell, positionSide: PositionSide.Long, type: FuturesOrderType.TakeProfit, quantity: long_quantity, timeInForce: TimeInForce.GoodTillCanceled, price: long_price, stopPrice: actpr);
                    if (startTrail_trailing.Success)
                    {
                        //MessageBox.Show(startTrail_trailing.Data.ToString());
                    }
                    else
                    {
                        MessageBox.Show($"Order placing failed: {startTrail_trailing.Error.Message}", "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    //LongTrailStop();
                    OpenOrders();
                    OpenPositions();
                }
                else
                {
                    MessageBox.Show($"Order placing failed: {BesLongorder_SellResult.Error.Message}", "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        });
    }`
eros1453 commented 2 years ago

binance-test