zhouaini528 / binance-php

Binance API Like the official document interface, Support for arbitrary extension.
MIT License
107 stars 43 forks source link

OCO order doesnt work #22

Closed ajmalazeez007 closed 3 years ago

ajmalazeez007 commented 3 years ago

When I try OCO order with sample code provided, I get the following error.

Array ( [code] => -1104 [msg] => Not all sent parameters were read; read '7' parameter(s) but was sent '9'. [_method] => POST [_url] => https://api.binance.com/api/v3/order/ocosymbol=LTCBTC&side=SELL&type=LIMIT&quantity=0.1&price=200&stopPrice=0.1&timeInForce=GTC×tamp=1623257733000 [_httpcode] => 400 )

So I modified the code as by removing type and timeInForce after referring to officila Binance documentation, I get the below error.

Array ( [code] => -1013 [msg] => Stop loss orders are not supported for this symbol. [_method] => POST [_url] => https://api.binance.com/api/v3/order/ocosymbol=LTCBTC&side=SELL&quantity=0.1&price=200&stopPrice=0.1×tamp=1623257816000 [_httpcode] => 400 )

What is the fix for his?

numairawan commented 3 years ago

Use "stopLimitTimeInForce" instead of "timeInForce" and you cant use type parameter in OCO orders.

EXAMPLE

//New OCO (TRADE)
try {
    $result=$binance->trade()->postOrderOco([
        'symbol'=>'LTCBTC',
        'side'=>'SELL',
        'quantity'=>'0.1',
        'price'=>'200',
        'stopPrice'=>'0.1',
        'stopLimitPrice'=>'0.1',
        'stopLimitTimeInForce'=>'GTC',
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r(json_decode($e->getMessage(),true));
}