Binance.Net icon indicating copy to clipboard operation
Binance.Net copied to clipboard

Futures PlaceOrder and - set up take profit

Open Adamszsz opened this issue 3 years ago • 10 comments

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?

Adamszsz avatar May 11 '21 13:05 Adamszsz

Binance.Net/Enums/OrderType

namespace Binance.Net.Enums
{
    /// <summary>
    /// The type of an order
    /// </summary>
    public enum OrderType
    {
        /// <summary>
        /// Limit orders will be placed at a specific price. If the price isn't available in the order book for that asset the order will be added in the order book for someone to fill.
        /// </summary>
        Limit,
        /// <summary>
        /// Market order will be placed without a price. The order will be executed at the best price available at that time in the order book.
        /// </summary>
        Market,
        /// <summary>
        /// Stop loss order. Will execute a market order when the price drops below a price to sell and therefor limit the loss
        /// </summary>
        StopLoss,
        /// <summary>
        /// Stop loss order. Will execute a limit order when the price drops below a price to sell and therefor limit the loss
        /// </summary>
        StopLossLimit,
        /// <summary>
        /// Stop loss order. Will execute a market order when the price drops below a price to sell and therefor limit the loss
        /// </summary>
        Stop,
        /// <summary>
        /// Stop loss order. Will be executed at the best price available at that time in the order book
        /// </summary>
        StopMarket,
        /// <summary>
        /// Take profit order. Will execute a market order when the price rises above a price to sell and therefor take a profit
        /// </summary>
        TakeProfit,
        /// <summary>
        /// Take profit order. Will be executed at the best price available at that time in the order book
        /// </summary>
        TakeProfitMarket,
        /// <summary>
        /// Take profit order. Will execute a limit order when the price rises above a price to sell and therefor take a profit
        /// </summary>
        TakeProfitLimit,
        /// <summary>
        /// Same as a limit order, however it will fail if the order would immediately match, therefor preventing taker orders
        /// </summary>
        LimitMaker,
        /// <summary>
        /// Trailing stop order will be placed without a price. The order will be executed at the best price available at that time in the order book.
        /// </summary>
        TrailingStopMarket,
        /// <summary>
        /// 
        /// </summary>
        Liquidation
    }
}

HypsyNZ avatar May 18 '21 02:05 HypsyNZ

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

mkleo21 avatar Aug 07 '21 04:08 mkleo21

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

mimfa avatar Aug 24 '21 08:08 mimfa

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

gitaweb avatar Oct 28 '21 01:10 gitaweb

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?

KingIthra avatar Dec 17 '21 17:12 KingIthra

Can anyone solve this problem?

sinaptech avatar Mar 07 '22 23:03 sinaptech

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

eros1453 avatar Mar 07 '22 23:03 eros1453

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

eros1453 avatar Mar 07 '22 23:03 eros1453

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 avatar Mar 08 '22 00:03 eros1453

binance-test

eros1453 avatar Mar 08 '22 00:03 eros1453