如何使用编程语言Python更改最大的加密货币交易所之一币安的服务器时间?
from binance.client import Client
from datetime import datetime
# client = Client('api_key' , 'api_secret') # Binance API key
raw_server_time = client.get_server_time()
server_time = datetime.fromtimestamp(raw_server_time['serverTime']/1000.0)
server_time
由于我在法国,结果如下:
>>> datetime.datetime(2020, 5, 23, 12, 49, 10, 13000)
proxies = {
'http': 'http://168.169.146.12:8080'
}
# in the Client instantiation
client = Client(api_key, api_secret, {'proxies': proxies})
# or on an individual call
client.get_all_orders(symbol='BTCUSDT', requests_params={'proxies': proxies})
但是我收到以下错误消息。
>>> BinanceAPIException: APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time.
您可以在 python-binance 库的文档页面中找到有关上述代码的更多详细信息。 http 服务器在网站 free-proxy.cz 中找到。下面还提供了纽约代理列表的屏幕截图。
如果您运行的是 Windows 10 或 Windows 11,请执行以下操作:
我有时会在电脑进入睡眠状态后观察到此问题。
我在 Microsoft Visual Code(MVC) 中编写 python 代码时也遇到了这个错误。 当我保持机器人运行时,随着机器人处于活动状态,这种情况也会发生。所以我需要机器人来改变我的电脑时间。我找到了以下解决方案:
以“管理员”身份运行程序并激活 WindowsTime 非常重要。 在“服务”中搜索 WindowsTime 并确保其正在运行/活动。如果需要,启动时自动运行
机器人启动时的这行代码:
import os
os.system('w32tm/resync')
在开始同步时间后,我正在监视来自 binance 的错误响应以查找时间戳错误。当找到时间戳消息时,它将再次重新同步我的计算机时间。
try:
###put for example buy code here###
except Exception as e:
print(e)
substring = 'Timestamp for this request was 1000ms ahead of the server'
if substring in e.message:
os.system('w32tm/resync')
import time
import win32api
client = Client(api_key, api_secret)
server_time = client.get_server_time()
gmtime=time.gmtime(int((server_time["serverTime"])/1000))
win32api.SetSystemTime(gmtime[0],gmtime[1],0,gmtime[2],gmtime[3],gmtime[4],gmtime[5],0) // Needed Administrator Permission
对于 Windows,请尝试以下操作:https://steemit.com/crypto/@biyi/how-to-resolve-binance-s-timestamp-ahead-of-server-s-time-challenge 净停止 w32time w32tm /取消注册 w32tm /注册 网络启动 w32time w32tm /重新同步