0
I am trying to load my crypto portfolio into Excel so I can use its easy analysis functionality on my trades. However, I'm having trouble connecting to the API using VBA's WinHttpRequest.
I use the following code to try to GET account info (balances) /api/v3/account:
Sub GetBalances()
Dim tNow As String
tNow = CStr(Date2Long(Now()))
Dim sUrl As String
sUrl = "https://api.binance.com/api/v3/account?timestamp=" & tNow & "&signature=[signature here]"
Dim oRequest As WinHttp.WinHttpRequest
Dim sResult As String
On Error GoTo Err_DoSomeJob
Set oRequest = New WinHttp.WinHttpRequest
With oRequest
.Open "GET", sUrl, True
.SetRequestHeader "Content-Type", "application/json; charset=UTF-8"
.SetRequestHeader "X-MBX-APIKEY", "[API key here]"
.Send "{}"
.WaitForResponse
sResult = .ResponseText
Debug.Print sResult
sResult = oRequest.Status
Debug.Print sResult
End With
Exit_DoSomeJob:
On Error Resume Next
Set oRequest = Nothing
Exit Sub
Err_DoSomeJob:
MsgBox Err.Description, vbExclamation, Err.Number
Resume Exit_DoSomeJob
End Sub
Private Function Date2Long(dtmDate As Date) As Long
Date2Long = (dtmDate - #1/1/1970#) * 86400
Exit Function
End Function
However it gives the following error message:
{"code":-1100,"msg":"Illegal characters found in parameter 'signature'; legal range is '^[A-Fa-f0-9]{64}$'."}
Which seems strange as the secret key's character range is only A-F, while the secret provided seems to contain A-Z. Anyone else know how to solve this problem? Might it be a problem caused by VBA? Or might the problem lie somewhere else?
Are you signing the signature? for example in PHP: $signature = hash_hmac('sha256', $query, $this->api_secret); – Marc Alexander – 2018-01-03T22:22:29.237
No I don't, so that will probably be the problem. What is $query in your example? – Sjors Hijgenaar – 2018-01-04T09:00:13.337
@MarcAlexander I presume that $query is your request string, do you have an example in code that you could share? I'm struggling what to include... – Sjors Hijgenaar – 2018-01-05T09:25:59.907