-1

I managed to create hitbtc api caller

Protected Overrides Function getJsonPrivate(method As String, otherParameters() As Tuple(Of String, String)) As String
    Dim content = "/api/1/trading/" + method + "?nonce=" + ExchangesClass.getNonce().ToString + "&apikey=" + _apiKey1
    Dim postar = otherParameters.ToList.ConvertAll(Function(x) x.Item1 + "=" + x.Item2)
    Dim post = String.Join("&", postar) ' "id=4987469178"
    Dim sighash = computeSig(content) '"https://api.hitbtc.com/api/1/trading/cancel_order?nonce=36411402&apikey=13a2492a3f0631d657ecd510ceacc509"
    Dim url = "https://api.hitbtc.com" + content
    Dim response = CookieAwareWebClient.downloadString1(url, post, {Tuple.Create("X-Signature", sighash)})
    'Dim response1 = CookieAwareWebClient.downloadString1("https://api.hitbtc.com" + content + "&" + post, "", {Tuple.Create("X-Signature", sighash)})

    Return response
End Function

It works for their get requests. I can get balances. I can get active orders. But to cancel orders, for example, I would need post requests.

For example, doing _jsonResult = getJsonPrivate("balance", {})

would work just fine and I would get:

"{""balance"":[{""currency_code"":""1ST"",""cash"":""0"",""reserved"":""0""},{""currency_code"":""8BT"",""cash"":""0"",""reserved"":""0""},{""currency_code"":""ADX"",""cash"":""0"",""reserved"":""0""},{""currency_code"":""AE"",""cash"":""0"",""reserved"":""0""},{""currency_code"":""AEON"",""cash"":""0"",""reserved"":""0""},{""currency_code"":""AIR"",""cash"":""0"",""reserved"":""0""},{""currency_code"":""AMB"",""cash"":""0"",""reserved"":""0""},{""currency_code"":""AMP"",""cash"":""0"",""reserved"":""0""},

response simply result in zero.

I tried to see PhP code sample here

https://github.com/hitbtc-com/hitbtc-api/blob/master/APIv1.md#examples

And the PHP sample here

https://gist.github.com/hitbtc-com/10885873

It's still strange.

Am I supposed to computeSig based on the post requests too added to URI? With no underlying &

Has anyone C# or vb.net sample? I think it'll require only one small change to the code so I can do cancel_order method instead of just get

The content of downloadstring1 is the following. So it basically do post or get based on whether post argument is empty string or not. I think that's pretty obvious.

Public Shared Function downloadString1(url As String, post As String, otherHeaders As Tuple(Of String, String)()) As String
        Dim wc = New CookieAwareWebClient()
        For Each oh In otherHeaders
            wc.Headers.Add(oh.Item1, oh.Item2)
        Next

        Dim response = String.Empty

        Try
            If post = "" Then
                response = wc.DownloadString(url)
            Else
                response = wc.UploadString(url, post)
            End If
        Catch ex As Exception
            Dim a = 1
        End Try

        Return response
    End Function
user4951
  • 32,206
  • 53
  • 172
  • 282
  • 1
    this is not c# related – BugFinder Nov 06 '17 at 09:04
  • https://stackoverflow.com/questions/5401501/how-to-post-data-to-specific-url-using-webclient-in-c-sharp shows how you can use webclient to post in C#. I'm assuming VB.net would be the same (i.e. use UploadString instead of DownloadString) – apokryfos Nov 06 '17 at 09:21
  • It's related to C# because I don't expect anyone to know vb.net. So I need a C# sample or vb.net sample. Vb.net is best but c# is not. I already use uploadstring. – user4951 Nov 06 '17 at 09:25
  • That is NOT the problem. I am asking someone familiar with hitbtc code to tell me what change of code I need to do. The function downloadstring1 already do uploadstring when post is not empty – user4951 Nov 06 '17 at 12:46

2 Answers2

0

The only change I would need is to include the post message when computing signature

I change this

 Dim sighash = computeSig(content) 

to

Dim sighash = computeSig(content + post) 

Now I got this message instead

"{""CancelReject"":{""rejectReasonCode"":""orderNotFound""}}"

Which is a problem (before I just got empty string.

That would be another question.

Update:

Ah I should use clientOrderId rather than id or order id. Some minimum documentation.

I got this instead

?response

"{""ExecutionReport"":{""orderId"":""4987469178"",""latestOrderId"":""4987469178"",""clientOrderId"":""2c90f00aee8e4d21b0cd83d421297c9a"",""orderStatus"":""canceled"",""userId"":""user_319564"",""symbol"":""UGTBTC"",""side"":""buy"",""price"":""0.000018"",""quantity"":111,""type"":""limit"",""timeInForce"":""GTC"",""lastQuantity"":0,""lastPrice"":"""",""leavesQuantity"":0,""cumQuantity"":0,""averagePrice"":""0"",""created"":1509439576948,""execReportType"":""canceled"",""timestamp"":1509962441283}}"

user4951
  • 32,206
  • 53
  • 172
  • 282
0

Once you have create an account on Hitbtc, and create API key, and add the Place/cancel orders Access Right, you may cancel order with a DELETE request (not a POST, not a GET, it is a DELETE):

DELETE /api/2/order/{clientOrderId}

Your request will look like this (with curl):

curl -X DELETE -u "ff20f250a7b3a414781d1abe11cd8cee:fb453577d11294359058a9ae13c94713" \
"https://api.hitbtc.com/api/2/order/d8574207d9e3b16a4a5511753eeef175"   

From your source code, I see that you use the API V1 endpoint (/api/1/trading), but please consider that API V1 is outdated, and it is better to switch to API V2.

You may finaly refer to the official Hitbtc API documentation.

You may also double-check that the order was not already canceled ?

Regards

A. STEFANI
  • 6,707
  • 1
  • 23
  • 48