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

KrakenExchangeAdapter not checking allowed no. of decimals for a coin before creating rest api call for a trade #126

Closed
roywasse opened this issue Jan 6, 2021 · 2 comments · Fixed by #131
Assignees
Projects

Comments

@roywasse
Copy link

roywasse commented Jan 6, 2021

The Kraken API doesn't allow the same number of decimals for each coin. See https://support.kraken.com/hc/en-us/articles/360001389366-Price-and-volume-decimal-precision

Currently the decimal format for price of a coin is denominated in the file KrakenExchangeAdapter.java as:
DecimalFormat("#.########", getDecimalFormatSymbols()).format(price));

When trading XBT (Bitcoin) this formatting would for instance an error from the KrakenAPI and causing the trade to fail.

To solve the KrakenAPI should be queried to retrieve the allowed decimal precision for a specific coin this is traded or the allowed number of decimals should be configurable in the a Kraken specific YAML file.

Hard coded fix I applied myself for trading XBTEUR is this change in KrakenExchangeAdapter.Java:
if (orderType == OrderType.SELL) {
params.put(PRICE, new DecimalFormat("#.#", getDecimalFormatSymbols()).format(price));

  } else {
    params.put(PRICE, new DecimalFormat("#.########", getDecimalFormatSymbols()).format(price));
  }

Note: you also need to change the unittests.

@gazbert
Copy link
Owner

gazbert commented Jan 11, 2021

Thanks for spotting this Roy. If you fancy having a go at a fix and PR, you're more than welcome. I've got a lot on at the moment, but I plan on releasing a maintenance/dependency update release of the bot in the Spring.

  • gazbert

@gazbert gazbert added the bug label Jan 11, 2021
@gazbert gazbert added this to TODO in BX-bot Jan 11, 2021
@gazbert gazbert moved this from TODO to In Progress in BX-bot Jan 17, 2021
@gazbert gazbert pinned this issue Jan 19, 2021
gazbert added a commit that referenced this issue Jan 26, 2021
Fetch decimal price precision from kraken api use it for volume and
  price when placing orders.

Fixes #126

Co-authored-by: gazbert <gazbert@users.noreply.github.com>
@gazbert gazbert reopened this Jan 26, 2021
@gazbert gazbert self-assigned this Jan 26, 2021
gazbert added a commit that referenced this issue Jan 26, 2021
gazbert added a commit that referenced this issue Jan 26, 2021
@gazbert
Copy link
Owner

gazbert commented Jan 28, 2021

Released.

@gazbert gazbert closed this as completed Jan 28, 2021
@gazbert gazbert moved this from In Progress to Done in BX-bot Jan 28, 2021
@gazbert gazbert unpinned this issue Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants