Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the GetValidValue() #101

Closed
zbigniew-klasik opened this issue Sep 23, 2018 · 3 comments
Closed

Problem with the GetValidValue() #101

zbigniew-klasik opened this issue Sep 23, 2018 · 3 comments
Assignees
Labels

Comments

@zbigniew-klasik
Copy link

On symbol ETHBTC.
For initial quantity 0.0466234368291005145420025865
GetValidValue() returns 0.0470000000000000000000000000
But it should return 0.047 (without following zeros)

Later Validate() does not throw an exception,
but PlaceAsync() throws: Binance.BinanceHttpException: [BadRequest]: 'Bad Request' - Illegal characters found in parameter 'quantity'; legal range is '^([0-9]{1,20})(.[0-9]{1,20})?$'.

For me, it looks like the following zeros are serialized and send to Binance as strings and do not pass the regex validation.
The regex looks like constant, it allows 20 decimal places so the easiest fix for this problem is something like that:
quantity = decimal.Round(quantity, 20);
and now the quantity is 0.04700000000000000000

and the PlaceAsync() works well without throwing the exception.

@sonvister sonvister added the bug label Sep 25, 2018
@sonvister sonvister self-assigned this Sep 25, 2018
sonvister added a commit that referenced this issue Sep 25, 2018
Add decimal normalization extension and use to remove trailing zeros before serializing and adding a decimal parameter to HTTP request (for #101).
@sonvister
Copy link
Owner

@zbigniew-klasik, thanks for mentioning the issue and providing useful information.

I added a public decimal extension, Normalize(), to remove any trailing zeros from decimal values and applied it before the parameters are serialized and added to the HTTP request. This should resolve the error.

I chose not to modify GetValidValue(), GetUpperValidValue(), and GetLowerValidValue() since these are just one possible source of decimal values that may be passed to PlaceOrderAsync(). However, I am currently considering updating these methods to truncate the precision of the returned value to the increment precision (which would also resolve the error).

@sonvister
Copy link
Owner

@zbigniew-klasik, 0.2.0-beta6 is released. Please let me know if the error is resolved (and feel free to close this issue). I chose not to modify GetValidValue(), GetUpperValidValue(), or GetLowerValidValue() at this time.

@zbigniew-klasik
Copy link
Author

@sonvister Now it works well. Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants