如何知道kucoin时间服务器?

时间:2019-01-16 20:34:09

标签: vb.net

Binance和kucoin要求提供时间戳。

我想知道他们服务器的时间戳

对于币安来说,URL是 https://api.binance.com/api/v1/time

kucoin的URL是什么?

为什么我想知道?说我自己计算时间戳。

我使用了这段代码

Public Shared Function unixEpoch() As DateTime
    Return New DateTime(1970, 1, 1, 0, 0, 0)
End Function
Public Shared Function currentTimeStamp() As Int64
    Dim utime = (DateTime.UtcNow - unixEpoch()).TotalMilliseconds
    Return CLng(utime)
End Function

但是,我的代码在时间和时间之间总是有些差别。

大约相差2万毫秒。

在币安上,我得到了一个可以计算出差异的代码

所以我做到了

Private timeDifference As Long = -34343445344 ' Every object have a copy of this. So it's private and it's no longer static
Protected Function getTimeDifference() As Long
    If timeDifference = -34343445344 Then
        Dim jobdata = getServerTimeStamp()
        Dim timestamp = jsonHelper.currentTimeStamp()
        timeDifference = jobdata - timestamp
        Dim a = 1
    End If
    Return timeDifference
End Function

Protected Overrides Function getServerTimeStamp() As Long
    Return typicalGetServerTimeStamp("https://api.binance.com/api/v1/time", "serverTime")
End Function

然后是

Protected Function typicalGetServerTimeStamp(url As String, timestamp As String) As Long
    Dim response = CookieAwareWebClient.downloadString1(url)
    Dim jtok = JToken.Parse(response)
    Dim jobdata = CLng(jsonHelper.getParameterFromJtokenToJtoken(jtok, timestamp).ToString)
    Return jobdata
End Function

所以我寻找

https://api.binance.com/api/v1/time

获取时间戳,然后计算该时间戳与我当前的时间戳之间的差。并使用该差异来“纠正”我的时间戳。

0 个答案:

没有答案