B4J Question okhttputils and timeouts

kostefar

Active Member
Licensed User
Longtime User
Dear All,

I have the following code (just showing the important parts):

B4X:
Sub Sell_Order (instrument As String, vol As Double,rate As Double)As ResumableSub

    
    Dim params As String = $"{"Market":""$ & instrument.ToUpperCase & $"/BTC","Type":"Sell","Rate":"$ & Main.sci(rate) &   $","Amount":"$ & Main.sci(vol) & $"}"$
    Log (params)
    CoinFinder.writeerrlog(params)
    'SendtoCryptopia("sell-" & instrument,"SubmitTrade",params)
    wait for (SendtoCryptopia("sell-" & instrument,"SubmitTrade",params))  complete

End Sub

B4X:
Sub SendtoCryptopia (jobname As String,method As String, params As String)As ResumableSub
Sleep (100)
Dim j As HttpJob

j.PostString(uri, jsonstr)
j.GetRequest.Timeout = 120000
Wait For (j) jobdone (j As HttpJob)
If j.Success = True Then
If j.JobName.StartsWith ("sell-") Then
            Log (j.GetString)
                CoinFinder.writeerrlog(j.GetString & " " & j.JobName)
Else
        Log ("err " & j.ErrorMessage)
CoinFinder.writeerrlog ("errormessage;" & j.ErrorMessage)
        
        CoinFinder.writeerrlog ("errormessage2;" & jobname & ";"& originalmethod & ";" & originalparams)
j.Release
SendtoCryptopia(jobname,originalmethod,originalparams)
End If
End Sub

writeerrlog logs to a file for me to find out later what´s going on, and it´s not always errors that are being logged. Above, it logs whenever there´s a jobdone success = false or true, to find out why I sometimes place a sell_order without the exchange doing anything with it.
What happens is that once every minute, about 50 buy and sell orders are updated by first cancelling and then placing a new order (with the sleep 100 to not make the exchange feel like it´s under DDOS attack) and the log shows that the events are being confirmed by the exchange - usually within the second.
But as mentioned, sometimes - it be can after an hour of the app running, sometimes longer - it doesn´t confirm it (for an order or two out of 50), although the log shows the request being sent, and in these cases the exchange also doesn´t do anything with it - the request is lost.
I assume that it´s subject to a timeout, but when jobdone.success = false, I don´t see anything in the errlog file indicating such. Is it possible that the exchange in rare cases would just returns nothing and and a timeout is not fired? I´m really puzzled by how to capture these events, cause when it happens, there´s no way I can make my code react to it, and the sell order will just disappear untill next time I restart the app.

I hope someone can figure out what´s going on.

Thanks in advance!
 

KMatle

Expert
Licensed User
Longtime User
First of all you need to release every job so move the line out of the If clause. The server responds in j.getstring, too. A real error only happens when the job really fails. Other messages are seen in j.getstring so check the content and log it (e.g. your db throws a message -> valid job response)
 
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
First of all you need to release every job so move the line out of the If clause. The server responds in j.getstring, too. A real error only happens when the job really fails. Other messages are seen in j.getstring so check the content and log it (e.g. your db throws a message -> valid job response)

Thanks, I´ll be logging all getstrings to see what happens!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top