Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nathanp83 opened this issue Nov 11, 2021 · 18 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@nathanp83
Copy link

nathanp83 commented Nov 11, 2021

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

@valouvaliavlo
Copy link
Contributor

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

@nathanp83
Copy link
Author

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

@GuillaumeDSM
Copy link
Member

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

@nathanp83
Copy link
Author

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

@valouvaliavlo
Copy link
Contributor

Have you test to do it from Windows GUI ?

@nathanp83
Copy link
Author

Have you test to do it from Windows GUI ?

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

@valouvaliavlo
Copy link
Contributor

valouvaliavlo commented Nov 15, 2021

Have you test to do it from Windows GUI ?

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

Two option
image

@nathanp83
Copy link
Author

nathanp83 commented Nov 15, 2021

image

Still happening after syncing it.
image

@valouvaliavlo
Copy link
Contributor

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

@nathanp83
Copy link
Author

nathanp83 commented Nov 18, 2021

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?

@valouvaliavlo
Copy link
Contributor

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

@nathanp83
Copy link
Author

nathanp83 commented Nov 18, 2021

Still happening:
image

Unless I did this incorrectly.
image

@Herklos Herklos added the help wanted Extra attention is needed label Nov 20, 2021
@valouvaliavlo
Copy link
Contributor

valouvaliavlo commented Nov 20, 2021

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

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

@nathanp83
Copy link
Author

nathanp83 commented Nov 22, 2021

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

@shizlkazizl
Copy link

Same issue in Docker on Mac OS(

@GuillaumeDSM
Copy link
Member

Synching your Mac clock should fix the issue

@shizlkazizl
Copy link

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

@canyone2015
Copy link

canyone2015 commented Mar 22, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants