Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
returnBalances
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub HashHmac(data As String, secret As String) As Byte()
Try
Dim m As Mac 'm As Message Authentication Code
Dim kg As KeyGenerator 'kg As KeyGenerator
kg.Initialize("HmacSHA512") 'initialize kg using HmacSHA512 algorithm
kg.KeyFromBytes(secret.GetBytes("UTF8")) 'encode string "secret" to an array of Bytes using UTF8
m.Initialise("HmacSHA512", kg.Key) 'initialize m using HmacSHA512 algorithm and the secret key
m.Update(data.GetBytes("UTF8")) 'encodes post data to an array of Bytes and loads it to be signed
Return m.Sign
Catch
Log(LastException)
End Try
'sign the loaded data using the secret key, return the calc signature data
End Sub
Private Sub returnBalances
Dim url As String = "https://poloniex.com/tradingApi"
Dim nonce As Long
nonce = DateTime.now
Dim pars As Map = CreateMap("nonce":nonce,"command":"returnBalances")
SendCommand("returnBalances", url, pars,True)
End Sub
private Sub SendCommand(work As String, uri As String, pars As Map, Signature As Boolean)
If Signature Then
Dim tosign As String = $"command=${pars.Get("command")}&nonce=${pars.Get("nonce")}"$
Dim Sign() As Byte
Sign = HashHmac( tosign, "5bdbcb41815a52a7e4427fe165ebb7718ab712ef69224b3ff42d0d0f7db8cae33c5100b14a44b4d74e26797892ea7df6d8bfaf1d947362027c726f5e6ea00bdf")
Dim API_Signed As String
Dim Byte_Conv As ByteConverter
API_Signed = Byte_Conv.HexFromBytes(Sign) 'convert to HEX
API_Signed = API_Signed.ToLowerCase
End If
Dim j As HttpJob
j.Initialize(work, Me)
j.PostBytes(uri,tosign.GetBytes("UTF8"))
If Signature Then
j.GetRequest.SetHeader("Key", "KE5G97MT-TH31A6TJ-IXQUK3NJ-69Q76GJG")
j.GetRequest.SetHeader("Sign", API_Signed)
End If
Wait For (j) jobDone(job As HttpJob)
If j.Success Then
Dim resultfromapi As String = job.GetString
Dim parser As JSONParser
parser.Initialize(resultfromapi)
Dim root As Map = parser.NextObject
For Each key As String In root.Keys
Log($"Key "${key}" = ${root.Get(key)}"$)
Next
Else
Log(job.ErrorMessage)
End If
job.Release
End Sub