zhouaini528 / bybit-php

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

[retCode] => 10002. invalid request, please check your server timestamp #25

Open VaLLDaR opened 5 months ago

VaLLDaR commented 5 months ago

Hi i kept getting this error. Synching my comp time didn't help or helped for short time.

To solve this problem i've modified \vendor\linwj\bybit\src\RequestV5.php

There you will find function called nonce() It need to be changed to this:

 protected function nonce() {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_URL, 'https://api.bybit.com/v5/market/time');
            $output = curl_exec($ch);
            curl_close($ch);
        $data = json_decode($output, true);
            $this->nonce=$data['time'];
    }

Now i always have server time in my request, so this error never appeared ever again.

P.S. hope this will be fixed in further updates.

zhouaini528 commented 5 months ago

Hi i kept getting this error. Synching my comp time didn't help or helped for short time.

To solve this problem i've modified \vendor\linwj\bybit\src\RequestV5.php

There you will find function called nonce() It need to be changed to this:

 protected function nonce() {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_URL, 'https://api.bybit.com/v5/market/time');
            $output = curl_exec($ch);
            curl_close($ch);
      $data = json_decode($output, true);
            $this->nonce=$data['time'];
    }

Now i always have server time in my request, so this error never appeared ever again.

P.S. hope this will be fixed in further updates.

I didn't find the problem in my tests, is it caused by the inconsistency between your server time and the exchange's server time?

What are the details of the error?

VaLLDaR commented 5 months ago

Hi, thanks for you answer. So if there are no other complainants, i guess this is my local problem. My computer somehow doen't synch time properly. I don't want to fix it, because it is easier to use server time :) When i used binance php sdk, i've been experiencing the same problem there. But for binance sdk there already exist function UseServerTime().

VaLLDaR commented 5 months ago

Full error response is next:

Array
(
    [retCode] => 10002
    [retMsg] => invalid request, please check your server timestamp or recv_window param. req_timestamp[1710434116927],server_timestamp[1710434114398],recv_window[5000]
    [result] => Array
        (
        )

    [retExtInfo] => Array
        (
        )

    [time] => 1710434114398
)

Appears on $bybit->order()->postCreate() and other which requiers timestamp