krijnsent / crypto_vba

An Excel/VBA project to communicate with various cryptocurrency exchanges APIs
MIT License
155 stars 54 forks source link

HitBTC order "Quantity is not valid number" #32

Closed mtmy2 closed 6 years ago

mtmy2 commented 6 years ago

Good day. Thank you for great work for vba users! I have one problem with post order on btsusd pair. I set quantity = 0.01, type = market and get response with error "Quantity is not valid number". If i try to change quantity = 1, i have response "Insufficient funds". and if I post order wiht DOGEBTC for examply where quantity =1000 i have success order. It seems like HitBTC don't alLow me trade with quantity less than 1 BTC. But quantityIncrement ia 0.01 for BTCUSD. I have general verification account. Can anybody explain me how solve this problem?

`Sub placeorderHitBTC() Dim httpObject As Object Dim nonce As Double Dim verb, symbol, url, postdata, replytext, nonceStr As String 'âðåìåííî Set thiswb = ActiveWorkbook qty = 0.01 side = "sell"

' Set api key and secret apiKey = ".." apiSecret = ".."

nonce = CreateNonce(10) nonceStr = nonce symbol = "BTCUSD" url = "/api/2/order" postdata = "symbol=" & symbol & "&quantity=" & qty & "&type=market" & "&side=" & side

Set httpObject = CreateObject("msxml2.xmlhttp") ' httpObject.Open "POST", "https://api.hitbtc.com" & url, False httpObject.setRequestHeader "accept", "application/json" httpObject.setRequestHeader "Authorization", "Basic " & Base64Encode(apiKey & ":" & apiSecret) httpObject.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" httpObject.Send postdata

' Catch response replytext = httpObject.ResponseText thiswb.Worksheets("Òåðìèíàë").Cells(1, "Q") = replytext

Set httpObject = Nothing `

krijnsent commented 6 years ago

Hi @mtmy2 , I haven't seen this problem before, but can try to replicate it somewhere in the coming week. Cheers

krijnsent commented 6 years ago

Hi @mtmy2 could you do a debug.print of your postdata string?

Like so: postdata = "symbol=" & sym... etc... debug.print postdata

My guess is that your value has a comma in it, so you'd need to replace that by a dot.

mtmy2 commented 6 years ago

Debug gave: symbol=BTCUSD&quantity=0,01&type=market&side=buy

mtmy2 commented 6 years ago

this error with qty=0,01: {"error":{"code":2010,"message":"Quantity not a valid number","description":"Quantity not a valid number or not set"}} And this error with qty=1: {"error":{"code":20001,"message":"Insufficient funds","description":"Check that the funds are sufficient, given commissions"}}

krijnsent commented 6 years ago

Hi @mtmy2 , do you see the "qty=0,01" -> that is a comma, and HitBTC only accepts a . (dot) as a decimal symbol So you could add a line after that postdata line to do that: postdata = Replace(postdata , ",", ".", 1)

That should solve the first error. For the second error, you need enough funds in your account.

mtmy2 commented 6 years ago

It's work! Thak you so much!