php-binance-api
                                
                                 php-binance-api copied to clipboard
                                
                                    php-binance-api copied to clipboard
                            
                            
                            
                        stop loss after the order
Hello
suppose I open a buy order using this
$order = $api->marketBuy("CHRUSDT", 300);
can I send a stop loss limit after the order ? If yes how can I send it ?
Thank you
Yes you can,
Place a STOP LOSS order
// When the stop is reached, a stop order becomes a market order
$type = "STOP_LOSS"; // Set the type STOP_LOSS (market) or STOP_LOSS_LIMIT, and TAKE_PROFIT (market) or TAKE_PROFIT_LIMIT
$quantity = 1;
$price = 0.5; // Try to sell it for 0.5 btc
$stopPrice = 0.4; // Sell immediately if price goes below 0.4 btc
$order = $api->sell("BNBBTC", $quantity, $price, $type, ["stopPrice"=>$stopPrice]);
print_r($order);
Thank you , as it seems it does not work for all crypto right ? I received error that I cannot set stop loss for CHRUSDT.
True, same with ADAUSDT. I have changed the type to "STOP_LOSS_LIMIT"
Thank you , could you show me what php code you use exactly with STOP_LOSS_LIMIT ?
This is how my function look like.
    public function CreateStopLossOrder($Symbol,$Quantity,$SellPrice,$LimitPrice)
    {
        $PricePresission = $this->GetPricePression($Symbol);
        $LotPresission = $this->GetLotPression($Symbol);
        $Type = "STOP_LOSS_LIMIT"; 
        $SellPrice = $this->numberFormatPrecision($SellPrice, $PricePresission, '.');
        $LimitPrice = $this->numberFormatPrecision($LimitPrice, $PricePresission, '.');
        $Quantity  = $this->numberFormatPrecision($Quantity, $LotPresission, '.');
        try{
            $order = $this->API->sell($Symbol, $Quantity, $SellPrice, $Type,["stopPrice" => $LimitPrice,'timeInForce' => 'GTC']);
            $json = json_encode($order);
            $bytes = file_put_contents($this->ResourceDir.$Symbol.".json", $json);
            return true;
        }catch (\Exception $e){
            $this->HandleException($e,__LINE__,__FUNCTION__,$Symbol);
            return false;
        }
    }
using this way you can put stop loss when you buy , right ? (not after the buy order)
Depends. What do you want to do.
If you want to buy at 1 dollar and sell at 1.1 dollar you can buy with a take profit.
I do not buy with the api, i manually buy with a limit price on binance, My script handles the stoploss, and sell orders so i dont need to look when to go out of a trade is have.
Hi @sitenzo
Is this similar to the OCO function in Binance? Im looking to place a order with take-profit and SL trigger