Android Question Placing an order using Binance API

Mattiaf

Active Member
Licensed User
Hello, I might need to create a fast utility for my phone in order to place orders using Binance API..
I already did the project on vb.net and im trying to convert it for b4a and I ended up with

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Dim job As HttpJob
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub PlaceOrder
    
    job.Initialize("PlaceOrder", Me)
    job.PostString("https://api.binance.com/api/v3/order", "symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=10&recvWindow=5000&timestamp=" & DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") & "Z&signature=" & GetSignature("symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=10&recvWindow=5000&timestamp=" & DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") & "Z"))
    job.GetRequest.SetHeader("X-MBX-APIKEY", "YOUR_API_KEY")
End Sub

Private Sub JobDone(job As HttpJob)
    If job.Success Then
        Log("Response: " & job.GetString)
    Else
        Log("Error: " & job.ErrorMessage)
    End If
End Sub

Sub GetSignature(query As String) As String
    Dim hash As String
    Dim message As String
    message = query & "&secret=" & "YOUR_SECRET_KEY"
    Return hash.HMAC_SHA256_HEX(message, "YOUR_SECRET_KEY")
End Sub

but it seems it doesn't like how I wrote the post string cause it is showing a "Object expected" error..
also the hmac_sha256 seems that is missing someting to generate it but frankly, I don't know how to proceed..
Any help?
thanks!!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top