BTCMarkets / API

API
119 stars 30 forks source link

Can't get withdraw working #135

Closed splundge closed 6 years ago

splundge commented 6 years ago

Hi I can create orders and get my account balance, but I can't seem to withdraw? This indicates that my authentication is correct. But something's wrong with the withdrawal.

POST https://api.btcmarkets.net/fundtransfer/withdrawCrypto HTTP/1.1
User-Agent: Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0
Accept-Charset: UTF-8
Accept: application/json
apikey: (MY API KEY)
timestamp: 1526171453388
signature: (MY SIG)
Content-Type: application/json; charset=utf-8
Host: api.btcmarkets.net
Content-Length: 83
Expect: 100-continue
Connection: Keep-Alive

{"amount":10000000,"address":"(TARGET ADDRESS)","currency":"BTC"}

I've replace the sensitive information here. What's wrong with the structure of this request?

justin-ngin commented 6 years ago

Hi @splundge ,

What is the response you get from the API?

Thanks, Justin

splundge commented 6 years ago

the response i get is {"success":false,"errorCode":1,"errorMessage":"Authentication failed."}

justin-ngin commented 6 years ago

@splundge ,

What language are you using? I'll try to replicate. Are you turning the body into a JSON string before using it to create the signature?

Thanks, Justin

splundge commented 6 years ago

I'm using C#. Give this a whirl. (make sure to put your pub/priv key in there) you also need to reference newtonsoft json. Or you can just remove the json convertion and read the response manually

splundge commented 6 years ago

@justin-ngin hey justin did you end up getting this to work?

justin-ngin commented 6 years ago

@splundge ,

Sorry for the delay. I'm still working on this and hope to have something for you by today.

Regards, Justin

splundge commented 6 years ago

Sorry for the double post! I wasn't sure if this thread got buried :)

justin-ngin commented 6 years ago

@splundge ,

I think I've almost got it. The signature it is creating is incorrect. If your other endpoints are working, it must be something inside the Withdraw method, but I can't see what it might be as the logged requestBody looks exactly like it's supposed to.

justin-ngin commented 6 years ago

@splundge,

solved it. WithdrawalPath was not being passed into GetAuthenticationHeaders, and therefore wasn't being included in the string to generate the signature. Please let me know if that gets you up and running.

public void Withdraw(Currency currency, decimal quantity, string depositAddress)
        {
            var adjustedQuantity = (int)(quantity * 100000000m);
            var requestBody = String.Format("{{\"amount\":{0},\"address\":\"{1}\",\"currency\":\"{2}\"}}",
                adjustedQuantity,
                depositAddress,
                currency.ToString().ToUpper());

            var result = Post<WithdrawResponse>(WithdrawalPath, requestBody, GetAuthenticationHeaders(**WithdrawalPath**, requestBody));

            if (!result.success)
                throw new Exception(String.Format("{0} {1}", result.errorCode, result.errorMessage));
        }

Cheers, Justin

splundge commented 6 years ago

holy crap. what a stupid mistake. I fixed it up and it works. what a waste of time! Sorry Justin. Really appreciate your help with this issue!!