0

Ive been looking the net dry to find a solution to this and i hope you can help me.

The main goal is that i have my client which interacts with Bybit API servers, their servers has a strict time window offset that i need to be in the bounds of and to do it so, i choose the method of resyncing my time since that worked, but more options might be available for this so feel free to let me know if you got other suggestions.

What i am looking for, is a way for me to tell the python script to resync my time. It Could be something like w32tm /resync, however all that ive found out after alot of testing is that any deployed script even adminstrator shell commands can not execute w32tm commands unless a typed password is used, and even trying with a typing emulator to automaticly fake the typing, that didnt work.

So is there another way for me to force a /resync of time?

Im looking forward to hearing your answers and hopefully you can stear me in the right direction.

Best regards.

Mathias.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • Are you trying to do some high-frequency trading, if the time sync is that important? – vonPryz Feb 23 '22 at 14:13
  • Use the NTP protocol to get the correct time from Internet if possible. If you have a network, sync a local server with NTP and all other computers with that server. Syncing A with B without knowing that B has the correct time can lead to trouble. – VPfB Feb 23 '22 at 14:16
  • Well its not highfrequency trading however i would like the bot to be able to deal with such issues if it suddently appears, so it doesnt missout on good trades because i couldnt sync up time automaticly – Mathias Albrechtsen Feb 23 '22 at 14:43
  • @VPfB So you suggest that i make my own NTP server with the time from example Bybits server time, and then sync up to that NTP server with whatever client? Also Syncing A with B is not directly what im doing now, so im just syncing with Windows time servers, however they do occasionally drift away from Bybits Server time, So thats why i need the Resync to the windows NTP server. However your idea is very good by creating my own NTP server, but would it work in your opinion? – Mathias Albrechtsen Feb 23 '22 at 14:48
  • The idea of the NTP is that there is only one correct time on this world (measured by atomic clocks, the best clocks we have) and everybody should be sychronized with it. There are pools of public NTP servers you can use. An own NTP server in a small network is typically sync'ed to 3 to 5 statum 2 or 3 NTP servers "near" you. Its precision is usually in the milliseconds range. – VPfB Feb 23 '22 at 15:16
  • And of course there's a module for it for python. See [ntptime](https://mpython.readthedocs.io/en/master/library/micropython/ntptime.html) – Edo Akse Feb 23 '22 at 15:22
  • @VPfB Thanks i didnt know that. However wouldnt i still need to interact with w32tm or win32 sys to sync up to these NTPs. So how can i make a force sync up with one of these in a python command? Because ive experienced that deployed Powershell commands to modify time doesnt really want to go through, since windows rejects it or does require a typed password, however it being deployed makes it not matter if i type it or not – Mathias Albrechtsen Feb 23 '22 at 15:26
  • @EdoAkse Thanks i will take a look at that. – Mathias Albrechtsen Feb 23 '22 at 15:29
  • @EdoAkse That link you sent, is for Mboards and i suppose not for computer/servers maybe im wrong. – Mathias Albrechtsen Feb 23 '22 at 15:51
  • oops, my bad. PyPI has [an NTP lib](https://pypi.org/project/ntplib/) though – Edo Akse Feb 23 '22 at 16:22
  • @EdoAkse no problem:), however how would you interact with windows to change the time the NTP lib only querys time, but something that interacts with win32 needs to set it, and thats what i find very hard to find a solution to. – Mathias Albrechtsen Feb 23 '22 at 16:59
  • Or something in python needs to set it, however that must interact with w32 sys in some way i would believe – Mathias Albrechtsen Feb 23 '22 at 16:59
  • Indeed, specifically `win32api.SetSystemTime()`. There's some nice answers out there which explain how to do this, such as [this one](https://stackoverflow.com/a/12292874/9267296). You might run into permission issues though. It might be easier to just makke sure the windows machine itself has something to keep the time synced with an NTP server... – Edo Akse Feb 23 '22 at 17:09
  • Also, you state `time window offset` on the Bybit API server side, but how does your local time actually come into play here? – Edo Akse Feb 23 '22 at 17:12
  • @EdoAkse I will try and take a look at that setsystemtime() however i believe its the same problems where i have to type the password to be able to change it. With regards to the time window offset, it happens that latency from client to servers can differ and thereby offset time by some margin, and from their end, you cannot get to execute stuff if this window is too big, so when syncing up my time with some NTP like windows NTP then i catchup with this drift and get within the required boundry to be allowed post/request stuff from bybit. – Mathias Albrechtsen Feb 23 '22 at 18:47

1 Answers1

-1

Easier install NPT software o the machines and it runs a service. These are accurate. As suggested you let one machine in the network sync time from Meinberg and the rest of the network gets their time form the NTP Server.

https://www.meinbergglobal.com/english/sw/ntp.htm