Binance订单:此请求的时间戳比服务器时间早1000毫秒
我正在编写一些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."
我已经检查了Binance服务器时间和我的本地时间之间的差异(以毫秒为单位):
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)。我仍然遇到同样的错误。 有人知道我该如何解决这个问题吗?
非常感谢!
I am writing some Python code to create an order with the 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)
Unfortunately I get the following error message:
"BinanceAPIException: APIError(code=-1021): Timestamp for this request was 1000ms ahead of the server's time."
I already checked the difference (in miliseconds) between the Binance server time and my local 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
It seems that the recvWindow of 60000 is still not sufficient (but it may not exceed 60K). I still get the same error.
Does anybody know how I can solve this issue?
Many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
可能是电脑时间不同步。
您可以使用 Windows -> 来完成此操作设置->时间与时间语言->日期和时间时间-> “立即同步”。
屏幕截图:
Probably the PC's time is out of sync.
You can do it using Windows -> Setting-> Time & Language -> Date & Time -> 'Sync Now'.
Screenshot:
我实际上使用了公认的解决方案,因为在任何情况下都希望拥有正确的窗口时间。
尽管如此,这里有一个替代代码解决方案(它创建一个 Binance 类并计算时间偏移):
然后调用如下函数:
完整线程的链接在这里: https://github.com/sammchardy/python-binance/issues/249
I actually used the accepted solution as it is desirable to have the correct windows time in any event.
Nevertheless, here is an alternative code solution (which makes a Binance class and computes the time offset) for the same:
and then call function like this:
The link to the full thread is here: https://github.com/sammchardy/python-binance/issues/249
手动将时钟调慢 1 秒,确保所有时间更新均已关闭。夏令时、自动同步等。
Manually set your clock back 1 second, ensure that ALL time updates are off. Daylights savings, autosync etc.
我在linux上找到了答案!
我在 kali linux 上的一个我正在学习开发的 python 交易应用程序上遇到了同样的问题!
当记录运行 main.py 文件的错误信息警告和调试日志时,我最初得到了这个响应!
在 Linux 上设置时间与在 Windows 上设置时间的过程不同,我仍在探索该选项!
通过在命令提示符中执行此操作,这对我有用!
输入
timedatectl
:NTP 服务处于非活动状态,因此将该值设置为 true 将更正时间:
仔细检查以确保其处于活动状态:
I found the answer on linux!
I had the same problem in kali linux on a python trading application i am learning to develop!
When logging the error info warnings and debug logs running the main.py file I get this response intially!
Setting the time on Linux is not the procedure for windows and I am still exploring that option!
This worked for me by following this in the command prompt!
Enter
timedatectl
:The NTP service was inactive, so setting the value to true will correct the time:
Double-check to make sure it's active:
Binance服务器时间落后于您的服务器时间,因为Binance服务器不经常与ntp服务器同步。
解决方法:
如果您使用:npm binance
Binance server time is behind your server time, because Binance servers do not sync often with ntp servers.
Workaround:
its if you use: npm binance
对于 C#,我创建了此方法来运行命令行以在 Windows 上重新同步时间,然后再在
Binance
上运行 API:For C#, I created this method to run command line to resync time on windows before running an API on
Binance
:将以下脚本保存为 SyncWindowsTimeWithBinance.ps1 并以管理员身份运行。它从 Binance 获取当前日期时间,添加时区差异(此处为 +4),并相应地调整(同步)Windows 时间。
当 Windows 时间同步不起作用或者您想借助代码同步数据时,它非常有用。
Save the following script as
SyncWindowsTimeWithBinance.ps1
and run it as administrator. It gets the current datetime from Binance, adds the timezone difference (+4 here), and adjusts (synchronizes) the Windows time accordingly.It is useful when Windows time synchronization is not working or you want to synchronize data with the help of code.
确保没有服务以某种方式阻止同步。
在我的特定课程中,FortiClient VPN 的自动启动遇到了麻烦。
我添加了禁用它的具体步骤:
右键单击任务栏上的 FortiClient 图标,然后选择“关闭 FortiClient”。
转到命令提示符并输入:
net stop fortishield
[ENTER]RUN ->
msconfig
并转到“服务”选项卡。取消选中服务 FortiClient Service Scheduler 并[应用] - 现在不要重新启动 PC。运行->服务并搜索 FortiClient 服务调度程序。右键->属性并将启动类型更改为:手动
重新启动。它也适用于 Win 7 32 位。问候
然后按照此问题所选答案中的说明进行操作:https://stackoverflow.com/a/72763542/7389293< /a>
来源:https://community.fortinet.com/t5/Support-Forum/Cant-stop-FortiClient-from-starting-on-startup/mp/5078/highlight/true#M4988
Be sure there's not a service blocking somehow the synchronization.
In my specific clase, the automatic start up of FortiClient VPN was in the way.
I add to follow the specific steps for disabling it:
Right-click on the FortiClient icon on the taskbar and select "Shutdown FortiClient".
Go to command prompt and enter:
net stop fortishield
[ENTER]RUN ->
msconfig
and go to services tab. Uncheck the service FortiClient Service Scheduler and [APPLY] - Do not restart the PC now.RUN -> services and search for FortiClient Service Scheduler. Right-click -> Properties and change the startup type to: Manual
Reboot. It also worked on Win 7 32bit. Regards
Then follow the instructions from the selected answer for this question: https://stackoverflow.com/a/72763542/7389293
It should work now:
Source: https://community.fortinet.com/t5/Support-Forum/Cant-stop-FortiClient-from-starting-on-startup/m-p/5078/highlight/true#M4988