#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private TextAreaOut As TextArea
Private ButtonGet As Button
Private BinanceApiUrl As String
Private ApiSecret As String
Private ApiKey As String
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
BinanceApiUrl = "https://api.binance.com/api/"
ApiKey = "VmcKfcJ127jpeGUPAKXnHXJBTSF9iMfHUqptwEb1TCvSLwgNnCJ2BuWsdVwyhsbD"
ApiSecret = "xTFh2bqOydbMumZmWcV13ecPYFTHmZa5pg0Xp3rlay5Tyog2VBoEAJQToMURhU1E"
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
'Function in charge of making requests to the Binance API
private Sub SendCommand(work As String, uri As String, Signature As Boolean)
Try
'Si se debe firmar
If (Signature == True)Then
Dim timestamp As Long
timestamp = DateTime.now 'Creamos el timestamp
Dim queryString As String
queryString = "timestamp=" & timestamp 'Creamos el Query string
Dim Sign() As Byte
Sign = HashHmac(queryString, ApiSecret) 'Firmamos el Query string
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)
Dim Url As String
Url = BinanceApiUrl & uri & "?" & queryString & "&signature=" & API_Signed 'Creamos la Url
j.Download(Url)
Log(Url)
'Si se debe firmar
If (Signature == True)Then
Try
'Defino el SetHeader basado función "signedRequest()" que encontrará en este post.
j.GetRequest.SetHeader("User-Agent", "Mozilla/4.0 (compatible; PHP Binance API)")
j.GetRequest.SetHeader("X-MBX-ApiKey", ApiKey)
j.GetRequest.SetHeader("Content-Type", "application/x-www-form-urlencoded")
Catch
Log(LastException)
End Try
End If
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
TextAreaOut.Text = j.JobName & CRLF
TextAreaOut.Text = TextAreaOut.Text & j.GetString
Log(j.GetString)
Else
TextAreaOut.Text = j.ErrorMessage
End If
j.Release
Catch
MessageBox(LastException, "Error")
End Try
End Sub
Sub ButtonGet_Click
SendCommand("GetBalances", "v3/account", True)
End Sub
'Function in charge of Signing the QueryString
Public 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 'sign the loaded data using the secret key, return the calc signature data
Catch
MessageBox(LastException, "Error")
End Try
End Sub
Public Sub MessageBox(Message As String, Title As String )
Private jxui As XUI
jxui.MsgboxAsync(Message, Title)
End Sub