· 7 years ago · Dec 28, 2018, 12:14 AM
1Private Function PrivateApiAsync(ByVal requestEndPoint As String, ByVal RequestType As HttpMethod, ByVal Params As Dictionary(Of String, String), Optional ByVal IncludeST As Boolean = True) As CallResult
2 Dim ErrMSG As String = "Unknown Error"
3 Try
4 Dim xhttp As New HttpClient()
5 Dim request As New HttpRequestMessage
6 Dim sign As String = ""
7 Dim Parameters As String = ""
8 Dim tonce = Int(DateTime.Now.ToUniversalTime.Subtract(New DateTime(1970, 1, 1)).TotalMilliseconds)
9 Dim newparam As New Dictionary(Of String, String)
10 newparam.Add("access_id", _Credentials.APIKey)
11 For Each entry In Params
12 newparam.Add(entry.Key, entry.Value)
13 Next
14 newparam.Add("tonce", tonce)
15
16 Dim FormURLEncodedSTR = New FormUrlEncodedContent(newparam).ReadAsStringAsync.Result
17 sign = GetHash(FormURLEncodedSTR & "&" & "secret_key=" & _Credentials.APISecret)
18
19 With request
20 .Headers.Add("authorization", sign)
21 .Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36")
22 .Method = RequestType
23 If RequestType = HttpMethod.Post Then
24 .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint)
25 .Content = New StringContent(Json_.Serialize(newparam), Encoding.UTF8, "application/json")
26 Else
27 .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint & "?" & FormURLEncodedSTR)
28 End If
29 End With
30
31 Dim result = xhttp.SendAsync(request).Result
32 Dim xcontent = result.Content.ReadAsStringAsync.Result
33 Dim jData = Json_.DeserializeObject(xcontent)
34 Dim Success As Boolean = False
35 If jData("code") <> 0 Then
36 ErrMSG = jData("message")
37 Else
38 Success = True
39 Return New CallResult With {.Data = Json_.Serialize(jData("data")), .ErrorMSG = "", .Success = Success}
40 End If
41 Catch ex As Exception
42 Return New CallResult With {.Data = "", .ErrorMSG = ex.Message.ToString, .Success = False}
43 End Try
44 Return New CallResult With {.Data = "", .ErrorMSG = ErrMSG, .Success = False}
45 End Function