BTCMarkets / API

API
119 stars 30 forks source link

Account API - No decimal places #43

Open wallism opened 6 years ago

wallism commented 6 years ago

Hi, Maybe I'm missing something but all balance values returned do not have decimal places. This is the format: {"balance":1000000000,"pendingFunds":0,"currency":"AUD"} My current balance in AU that is returned is: 245745420414. This amount is actually $2457.45, as displayed when I login to the site. But what if the amount was $245745.42, how do I programatically determine the correct balance when there are no decimal places?

Same with all currencies, e.g. BTC, I get back 45038674 as balance, which is 0.45038674 but how do I know it is not 45.038674? Is this a bug and balances should be returned with decimal places, or is there some formula I need to apply to accurately determine my balances via the API?

Thanks! Mark

StuAngel commented 6 years ago

/100000000 45038674 / 100000000 = 0.45038674 245745420414 / 100000000 = 2457.45420414

dylanhand commented 6 years ago

I'm having this problem with the websocket. The API is returning float values such as 23456.78, but the websocket is inconsistent - it returns 2345678000000.

Any reason for this or best practice for handling?

StuAngel commented 6 years ago

as mentioned in the previous post - divide all the values by 100000000 or multiply them by 0.00000001

ghost commented 6 years ago

I'd love to see this changed, it's definitely something easy to work around, just annoying when getting started and reading returned values with human eyes

StuAngel commented 6 years ago

Hi guys, try to think of it this way,

1 bitcoin (BTC) is made of 100,000,000 Satoshis, so the numbers (eg. 245745420414 or 2345678000000) you see that are being returned are how many Satoshi you have (not bitcoin), in the same way you can say you have 100 cents or 1 dollar

Stu

fyi - https://en.bitcoin.it/wiki/Units

wallism commented 6 years ago

I'm used to it now and it all works fine. The problem is this approach is it is different to every other exchange api, so requires so custom logic to handle it. This is fine but I was VERY worried that I'd missed or added a zero and my program was going to start selling or buying at a different order of magnitude. I've now done hundreds of thousands of dollars of orders without a hitch, so if anyone is worried, don't be, just check and double check how many zero's you have when converting :) Keep up the great work guys and Happy New Year!

ghost commented 6 years ago

Stu, while I'm sure that is correct, has that actually helped anyone conceptualise numbers that big? having the API return doubles instead of ints would just remove the same code from every application that uses this specific API and by the sounds of things, allow apps to integrate better with multiple sites easier. As I'm planning to expend to othe exchanges, it's good to know that others may be easier to work with.

StuAngel commented 6 years ago

Hi Budgetcats,

there are sort of 3 parts to this answer, but they all somewhat run into each other - I think the idea is that one day in the future we will be using 'satoshi' more than we use 'bitcoin', so I might say, "Hey Budgetcat, I just sent you (0000000<< these would naturally get knocked off an int)50 satoshi" instead of "0.000000005 of a bitcoin" - I am already seeing people talk about something worth x amount of satoshi rather than x fraction of a bitcoin - I guess the json responses are somewhat Englishy, but they are meant to be decoded by an application and not so much by the human eye so I do understand both sides to this comment, lastly, I dont actually work for BTC Markets, my initial response was really just a quick response to an easy question to save the support the time to go into it (as I had just submitted my own query and was reading a couple out of interest), but I would be more than happy for any of the official staff to step in and pick up from here,

best regards

Stu ;)

Wil-Storch commented 6 years ago

If the API is going to continue to use values*100000000 then this should at least be clearly documented. I was going nuts thinking my REST client was dropping decimal places and could see no mention of it in the application guide.

Hopefully in v2 a transition could be made to using doubles like most other APIs to aid code re-usability ;)

Regards, Wil

StuAngel commented 6 years ago

not sure if anyone has had a look, but there is a reference on

https://github.com/BTCMarkets/API/wiki/Trading-API that says

Volume of 1 BTC = 100000000 (i.e x 100000000)

Stu

Wil-Storch commented 6 years ago

On the flip side, the order book returns prices and volume WITH the decimal point. It would be good to have consistency throughout an API, as as it is without debugging each path individually it is hard to determine the behavior to expect.

dylanhand commented 6 years ago

+1 for consistency