byBIT API PHP about unified margin account

Viewed 40

I made php code to get create order on unified margin account as follows

 function get_signed_params($public_key, $secret_key, $params) {
      $params = array_merge(['api_key' => $public_key], $params);
      ksort($params);
      //decode return value of http_build_query to make sure signing by plain parameter 
      //string
      $signature = hash_hmac('sha256', urldecode(http_build_query($params)), $secret_key);
      return http_build_query($params) . "&sign=$signature";
    }

   $params = [
    'category' => 'linear', 
    'symbol' => 'BTCUSD', 
    'side' => 'Buy', 
    'orderType' => 'Market', 
    'qty' => '0.005', 
    //'price' => '200', 
    'timeInForce' => 'GoodTillCancel',
    'timestamp' => time() //* 1000,
    //'position_idx' => 0
   ];

    $url = 'https://api.bybit.com/unified/v3/private/order/create';

    $public_key = 'bAxxxxxxxxxxxxxxx';
    $secret_key = 'Ncxxxxxxxxxxxxxxxxxxxxx';

    echo "create order <br/>";
    $qs=get_signed_params($public_key, $secret_key, $params);
    $curl_url=$url."?".$qs;
    $curl=curl_init($curl_url);
    //echo $curl_url;
    curl_setopt($curl, CURLOPT_URL, $curl_url);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $qs);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    //#curl_setopt($curl, CURLOPT_PROXY,"127.0.0.1:1087");
    $response=curl_exec($curl);
    echo $response;

and I got error message

create order
{"retCode":4007,"retMsg":"request params error","result":null,"retExtInfo":null,"time":1663244086558}

what is err code 4007 ?

and where is error on parameters

0 Answers
Related