zhouaini528 / bybit-php

Bybit API Like the official document interface, Support for arbitrary extension.
MIT License
24 stars 12 forks source link

privates->postOrderCreate() signature issue #2

Closed RobertGasch closed 3 years ago

RobertGasch commented 3 years ago

I am working with your API and things generally seem to work well. GET requests I had no problem with (getPositionList, getTradingRecords, getWalletBalance, etc.). However, postOrderCreate always returns this:

"ret_code" => 10004 "ret_msg" => "error sign! origin_string[api_key=xxxxxxxxxxxxxx&order_type=Market&qty=1&reduce_only=true&side=Sell&symbol=BTCUSD&time_in_force=GoodTillCancel&timestamp=1609525189785]" "ext_code" => "" "ext_info" => "" "result" => null "time_now" => "1609525190.137879"

At first I thought that it might be a problem with POST requests, but postOrderCancel() passes the sign check (it returns an error because I'm supplying an invalid order-id but the signature check passes OK) ...

For the postOrderCreate request which fails, the params passed to your API are:

"side" => "Sell" "symbol" => "BTCUSD" "order_type" => "Market" "qty" => 1 "reduce_only" => true "time_in_force" => "GoodTillCancel"

and the full request which is sent to bybit is this:

"body" => "{"api_key":"xxxxxxxxxxxxxx","order_type":"Market","qty":1,"reduce_only":true,"side":"Sell","symbol":"BTCUSD","time_in_force":"GoodTillCancel","timestamp":1609525189785,"sign":"7c12c29a413c401e8c8bdf9a740c40d3974e699c07c22bd05b8eee1d2d7d5878"}

As the signature is constructed in Request.php in a generic manner, I'm not sure what could be causing this. Can you offer any suggestions?

RobertGasch commented 3 years ago

More info: if I remove the "reduce_only" parameter, the postOrderCreate() call works. So it is somehow related to how a boolean is treated/encoded.

I tried passing a string "true"/"false" as the reduce_only param, but this caused another error (but it made the underlying sign-issue) go away.

Maybe this helps in diagnosing what's wrong. Appreciate any hints you can offer ...

zhouaini528 commented 3 years ago

Sorry to reply to you now. I just tested and have a problem like yours, I am now looking for the cause

zhouaini528 commented 3 years ago

Sorry to keep you waiting. I have found the problem and fixed it, you can use it. The parameters you pass in are as follows

$bybit->privates()->postOrderCreate([
    //'order_link_id'=>'xxxxxxxxxxxxxx',
    'side'=>'Sell',
    'symbol'=>'BTCUSDT',
    'order_type'=>'Limit',
    'qty'=>'0.25',
    'price'=>'40000',
    'time_in_force'=>'GoodTillCancel',

    //Both string type and boolean type are compatible
    'reduce_only'=>'false',
    'close_on_trigger'=>'false',
    //or set
    'reduce_only'=>false,
    'close_on_trigger'=>false
]);

Remember version composer update , current version 1.0.2

RobertGasch commented 3 years ago

Confirmed as fixed, thank you very much!