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

Kraken OHLC call provides a null string regardless of pair provided #3559

Open nickmitchko opened 4 years ago

nickmitchko commented 4 years ago

The Kraken OHLC api does not seem to be properly implementing the KrakenCurrencyPair array.

I am running this code and the exchange works for all other purposes:

// Boot up our exchange
// Credentials is my internal app service that provides an exchange spec. 
KrakenExchange          exchange    = (KrakenExchange) ExchangeFactory.INSTANCE.createExchange(Credentials.getInstance().getNewExchangeSpec());
// Get market data service to query OHLC backfill data
KrakenMarketDataService dataService = (KrakenMarketDataService) exchange.getMarketDataService();
// Get the actualy OHLCs
KrakenOHLCs krakenOHLC = dataService.getKrakenOHLC(CurrencyPair.BTC_USD);
// Won't reach
krakenOHLC.getOHLCs();

When I debug, it seems that the OHLC call is providing a null CurrencyPair string to the actual API call.

See here for the bugger when I use both CurrencyPair.BTC_USD and CurrencyPair.XBT_USD

Screenshot from 2020-06-13 17-03-02

Screenshot from 2020-06-13 17-09-05

It seems the call to KrakenUtils.createKrakenCurrencyPair() returns an error always due to a bug in KrakenUtils

nickmitchko commented 4 years ago

I found a workaround which required populating the KrakenUtils pair map prior to calling the OHLC function:

KrakenExchange exchange    = (KrakenExchange) ExchangeFactory.INSTANCE.createExchange(Credentials.getInstance().getNewExchangeSpec());
KrakenMarketDataService dataService = (KrakenMarketDataService) exchange.getMarketDataService();
// Required below to call OHLC
try {
    KrakenAssets assets = dataService.getKrakenAssets();
    KrakenUtils.setKrakenAssets(assets.getAssetPairMap());
    KrakenAssetPairs krakenAssetPairs = dataService.getKrakenAssetPairs();
    KrakenUtils.setKrakenAssetPairs(krakenAssetPairs.getAssetPairMap());
    System.out.println("");
} catch (IOException ioException) {
    ioException.printStackTrace();
}
// Call OHLC below this works.

// ...
KrakenOHLCs krakenOHLC = dataService.getKrakenOHLC(CurrencyPair.BTC_USD, 1, (Long)null);
krakenOHLC.getOHLCs();
nickmitchko commented 4 years ago

Maybe this sort of pair initialization should go into the kraken lib, who is the maintainer of that?