【问题标题】:Binance order: Timestamp for this request was 1000ms ahead of the server's time币安订单:此请求的时间戳比服务器时间提前 1000 毫秒
【发布时间】:2022-06-27 00:58:03
【问题描述】:

我正在编写一些 Python 代码来使用 Binance API 创建订单:

from binance.client import Client

client = Client(API_KEY, SECRET_KEY)

client.create_order(symbol='BTCUSDT',
                    recvWindow=59999, #The value can't be greater than 60K
                    side='BUY',
                    type='MARKET',
                    quantity = 0.004)

很遗憾,我收到以下错误消息:

"BinanceAPIException: APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time."

我已经检查了币安服务器时间和我的本地时间之间的差异(以毫秒为单位):

import time
import requests
import json
url = "https://api.binance.com/api/v1/time"
t = time.time()*1000
r = requests.get(url)

result = json.loads(r.content)

print(int(t)-result["serverTime"]) 

OUTPUT: 6997

看来60000的recvWindow还是不够用(但可能不会超过60K)。我仍然得到同样的错误。 有人知道我该如何解决这个问题吗?

非常感谢!

【问题讨论】:

  • 始终将完整的错误消息(从单词“Traceback”开始)作为文本(不是屏幕截图,不是指向外部门户的链接)(不是在 cmets 中)。还有其他有用的信息。
  • 也许您的问题是您计算机中的日期和时间。你的第二个代码给了我负值-250,但你有正值
  • documentation 显示 if (timestamp < (serverTime + 1000) && (serverTime - timestamp) <= recvWindow) { 可以重写为 (serverTime - recvWindow) <= timestamp < (serverTime + 1000) 并且可能您的 timestamp 满足 (serverTime - recvWindow) <= timestamp 但不满足 timestamp < (serverTime + 1000) - 这可能是您的错误 Timestamp for this request was 1000ms ahead of the server's time
  • 您可以将timestamp < (serverTime + 1000) 写为timestamp - serverTime < 1000,这与您的int(t)-result["serverTime"] 相同,但您得到6997,这不满足6997 < 1000 至于我,您必须更正时钟/系统中的时间。或者您可能需要更快的连接。

标签: python datetime cryptoapi binance-api-client


【解决方案1】:

手动将时钟拨回 1 秒,确保所有时间更新均已关闭。夏令时、自动同步等。

【讨论】:

    【解决方案2】:

    可能是 PC 的时间不同步。

    您可以在 Windows 上执行此操作 -> 设置 -> 时间和语言 -> 日期和时间 -> '立即同步'

    我也分享了图片。enter image description here

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 2016-03-04
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多