gazbert / bxbot

A simple Bitcoin trading bot written in Java.
MIT License
775 stars 275 forks source link

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

Closed roywasse closed 3 years ago

roywasse commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Released.