knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.81k stars 1.93k forks source link

KrakenOrderResponse include the error code and error message. #1957

Open azlax opened 6 years ago

azlax commented 6 years ago

protected R checkResult(KrakenResult krakenResult) in public KrakenOrderResponse placeKrakenOrder(KrakenStandardOrder krakenStandardOrder) throws IOException

should return the krakenResult and not krakenResult.getResult();

So that we can programatically act upon different error codes are error messages from the Kraken API, instead of just a null krakenResult.

for example: API status 200 {"error":["EService:Unavailable"]} -> retry.

jcuypers commented 6 years ago

Maybe I dont see your point but can't you catch the error and do something with it?

Eservice: unavailable is caught by ExchangeException.

The only exceptions that are difficult to handle on Kraken are the real HTTP errors 502/504/520 etc. which leaves you in an "unknown" state and you have to perform checks for consistency (is my order actually performed or not.

    try {
        <whatever you need to do with the order>
    } catch (SocketException e) {
        System.out.println("Socket exception...");
        System.out.println(e.getMessage());
    } catch (NonceException e) {
        System.out.println("Nonce exception...");
        System.out.println(e.getMessage());
    } catch (ExchangeException e) {
        System.out.println("Exchange exception...");
        System.out.println(e.getMessage());
    } catch (IOException e) {
        System.out.println("ok we have an issue...");
        System.out.println(e.getMessage());
    } catch (Exception e) {
        System.out.println("oh oh...");
        System.out.println(e.getMessage());
    }
timmolter commented 6 years ago

See the GDAX implementation for correct handling or exchange exceptions. This may need to be implemented for Kraken (and a lot of other exchanges in the project).