OctoBot icon indicating copy to clipboard operation
OctoBot copied to clipboard

Timestamp for this request was 1000ms ahead of the server's time."} (4 failures in a row)

Open nathanp83 opened this issue 3 years ago • 18 comments

Step 1: Have you searched for this issue before posting it?

Yes

Step 2: Describe your environment

  • OS : Windows 10
  • Python Version: _____ (python -V)
  • In case you are not using a binary version:
    • Branch: Master | Dev
    • Last Commit ID: _____ (git log --format="%H" -n 1)

Step 3: Describe the problem:

Describe the bug Failed to run job action, exception: InvalidNonce: binanceus {"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."} (4 failures in a row) (InvalidNonce)

Expected behavior Should be no timestamp issues with using the suggested "Network Time" application.

Steps to reproduce:

  1. Start OctoBot
  2. Enable Live Trading
  3. Wait for everything to load and observe the issue happening very frequently.

Observed Results:

  • What happened? Timestamp for this request was 1000ms ahead of servers time
  • What did you expect to happen? In previous version of software, this never happened.

Relevant code exceptions or logs:

If applicable, add screenshots to help explain your problem.

2021-11-10 18:59:46 ERROR  AsyncJob-_open_orders_fetch_and_push events.py:81       binanceus {"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."}
Traceback (most recent call last):
  File "octobot_commons\async_job.py", line 193, in octobot_commons.async_job.AsyncJob._run
  File "octobot_trading\personal_data\orders\channel\orders_updater.py", line 100, in _open_orders_fetch_and_push
  File "octobot_trading\exchanges\implementations\spot_ccxt_exchange.py", line 210, in get_open_orders
  File "octobot_trading\exchanges\connectors\ccxt_exchange.py", line 315, in get_open_orders
  File "octobot_trading\exchanges\connectors\ccxt_exchange.py", line 316, in octobot_trading.exchanges.connectors.ccxt_exchange.CCXTExchange.get_open_orders
  File "ccxt\async_support\binance.py", line 2370, in fetch_open_orders
  File "ccxt\async_support\binance.py", line 4169, in request
  File "ccxt\async_support\base\exchange.py", line 97, in fetch2
  File "ccxt\async_support\base\exchange.py", line 162, in fetch
  File "ccxt\async_support\binance.py", line 4149, in handle_errors
  File "ccxt\base\exchange.py", line 520, in throw_exactly_matched_exception
ccxt.base.errors.InvalidNonce: binanceus {"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."}
2021-11-10 18:59:46 ERROR  AsyncJob-_open_orders_fetch_and_push events.py:81       Failed to run job action, exception: InvalidNonce: binanceus {"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."} (3 failures in a row) (InvalidNonce)
2021-11-10 18:59:46 DEBUG  OctoBot Channel      logger.py:267      

2021-11-10 18:59:45 DEBUG  ErrorsUploader       errors_uploader.py:91       Uploaded 1 errors

image image

nathanp83 avatar Nov 11 '21 03:11 nathanp83

Hi @nathanp83 It's surely you ethernet connection. Are you on cable or wifi ?

valouvaliavlo avatar Nov 11 '21 22:11 valouvaliavlo

Hi @valouvaliavlo Cable. Never had this issue with previous software version using the exact setup I have now.

nathanp83 avatar Nov 11 '21 22:11 nathanp83

Hi @nathanp83 ! Could you try this please ? Sometimes Windows clock can get out of sync. https://docs.octobot.online/installation/installation-troubleshoot#time-synchronization

GuillaumeDSM avatar Nov 12 '21 10:11 GuillaumeDSM

Hi GuillaumeDSM

I tried that method before installing NetTime and had no luck. Trying again and the results:: PS C:\WINDOWS\system32> net stop w32time The Windows Time service is not started.

More help is available by typing NET HELPMSG 3521.

PS C:\WINDOWS\system32> net start w32time The Windows Time service is starting. The Windows Time service was started successfully.

PS C:\WINDOWS\system32> w32tm /resync Sending resync command to local computer The command completed successfully. PS C:\WINDOWS\system32> w32tm /query /status Leap Indicator: 0(no warning) Stratum: 4 (secondary reference - syncd by (S)NTP) Precision: -23 (119.209ns per tick) Root Delay: 0.0784478s Root Dispersion: 8.6217400s ReferenceId: 0x287706E4 (source IP: 40.119.6.228) Last Successful Sync Time: 11/12/2021 9:06:31 AM Source: time.windows.com,0x9 Poll Interval: 10 (1024s)

PS C:\WINDOWS\system32>

Still showing error in the logs: image

nathanp83 avatar Nov 12 '21 17:11 nathanp83

Have you test to do it from Windows GUI ?

valouvaliavlo avatar Nov 15 '21 01:11 valouvaliavlo

Have you test to do it from Windows GUI ?

I am sorry, I don't understand your question.

nathanp83 avatar Nov 15 '21 21:11 nathanp83

Have you test to do it from Windows GUI ?

I am sorry, I don't understand your question.

Two option image

valouvaliavlo avatar Nov 15 '21 21:11 valouvaliavlo

image

Still happening after syncing it. image

nathanp83 avatar Nov 15 '21 21:11 nathanp83

Can you test to manually set a date in the past then sync it ?

valouvaliavlo avatar Nov 17 '21 19:11 valouvaliavlo

From Binance.us troubleshooting this issue: I'm receiving "Error -1021 (Message: Timestamp for this request is outside of the recvWindow)". How can I resolve this? Typically, this error only occurs if there is a desync between the server time and your system time. You may need to sync your system clock. However, this process varies depending on the operating system. For Windows, at your own discretion, you may use a tool like "Atomic Clock". Linux and Mac users can try syncing with "ntpdate" via the command line. If the problem is unable to resolve, it may be latency-related (a network issue), and adjusting your recvWindow may be required

Is this possible?

nathanp83 avatar Nov 18 '21 17:11 nathanp83

There is no option fo recvWindow in OctoBot for now. Maybe can you try this : https://github.com/Drakkar-Software/OctoBot-Tentacles/pull/544

valouvaliavlo avatar Nov 18 '21 22:11 valouvaliavlo

Still happening: image

Unless I did this incorrectly. image

nathanp83 avatar Nov 18 '21 22:11 nathanp83

Can you try this : "timeDifference": 2000, "adjustForTimeDifference": True

if still don't work : "timeDifference": -2000, "adjustForTimeDifference": True

valouvaliavlo avatar Nov 20 '21 18:11 valouvaliavlo

Upgraded to Version 0.4.3 and observe the same issue. Tried both changes.

nathanp83 avatar Nov 22 '21 05:11 nathanp83

Same issue in Docker on Mac OS(

shizlkazizl avatar Jul 27 '22 08:07 shizlkazizl

Synching your Mac clock should fix the issue

GuillaumeDSM avatar Jul 27 '22 17:07 GuillaumeDSM

Clock synchronization did not help. I've tried using time.apple.com or time.euro.apple.com servers, but that didn't work.

shizlkazizl avatar Aug 01 '22 20:08 shizlkazizl

I created a Python script that updates the system time every 15 minutes. This should solve the delay problem. (Windows)

UpdateSysTime.py
import ctypes
import os
import sys
import time


def run_as_admin(argv=None, debug=False):
    shell32 = ctypes.windll.shell32
    if argv is None and shell32.IsUserAnAdmin():
        return True
    if argv is None:
        argv = sys.argv
    if hasattr(sys, '_MEIPASS'):
        arguments = argv[1:]
    else:
        arguments = argv
    argument_line = ' '.join(arguments)
    executable = sys.executable
    if debug:
        print('Command line: ', executable, argument_line)
    ret = shell32.ShellExecuteW(None, "runas", executable, argument_line, None, 1)
    if int(ret) <= 32:
        return False
    return None


if __name__ == '__main__':
    ret = run_as_admin()
    if ret is True:
        print(f'Success(ret={ret}): admin.')
        os.system('net stop w32time')
        os.system('net start w32time')
        try:
            loop = True
            while loop:
                try:
                    os.system('w32tm /resync')
                    os.system('w32tm /query /status')
                    time.sleep(60 * 15)
                except KeyboardInterrupt:
                    while True:
                        r = input('Exit program? [y/n]')
                        if r.lower() == 'y':
                            loop = False
                            break
                        elif r.lower() == 'n':
                            break
        except:
            pass
    elif ret is None:
        print(f'Error(ret={ret}): not admin.')


This script can be combined with the launch of Octobot.

OctobotLaunch.py
import ctypes
import os
import subprocess
import sys
import time


def run_as_admin(argv=None, debug=False):
    shell32 = ctypes.windll.shell32
    if argv is None and shell32.IsUserAnAdmin():
        return True
    if argv is None:
        argv = sys.argv
    if hasattr(sys, '_MEIPASS'):
        arguments = argv[1:]
    else:
        arguments = argv
    argument_line = ' '.join(arguments)
    executable = sys.executable
    if debug:
        print('Command line: ', executable, argument_line)
    ret = shell32.ShellExecuteW(None, "runas", executable, argument_line, None, 1)
    if int(ret) <= 32:
        return False
    return None


if __name__ == '__main__':
    ret = run_as_admin()
    if ret is True:
        print(f'Success(ret={ret}): admin.')
        process = subprocess.Popen(["./OctoBot_windows_x64.exe"], stdin=subprocess.PIPE)
        print(f"PID: {process.pid}")
        os.system('net stop w32time')
        os.system('net start w32time')
        try:
            loop = True
            while loop:
                try:
                    os.system('w32tm /resync')
                    os.system('w32tm /query /status')
                    time.sleep(60 * 15)
                except KeyboardInterrupt:
                    while True:
                        r = input('Exit program? [y/n]')
                        if r.lower() == 'y':
                            loop = False
                            process.terminate()
                            break
                        elif r.lower() == 'n':
                            break
        except:
            process.terminate()
        print('Process terminated')
    elif ret is None:
        print(f'Error(ret={ret}): not admin.')


</details>

Thus, Octobot will be launched, and the system time will be updated every 15 minutes.

canyone2015 avatar Mar 22 '24 11:03 canyone2015