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

Cannot resolve "XXBTXLTC" currency pair for Kraken #1812

Open vladmelnyk opened 6 years ago

vladmelnyk commented 6 years ago

@timmolter When I try to get my trading history using tradeService.getTradeHistory() I receive NPE which lead me to KrakenUtils.translateKrakenCurrencyPair() returning null on "XXBTXLTC" currency pair, which I had back on 2015. Looks like it has 8 symbols and doesn't enter any of the ifs provided. Moreover, on Kraken endpoint (https://api.kraken.com/0/public/AssetPairs) it seems to have "XLTCXXBT" now. Hence, do you feel like another if for 8 symbol currencyPair length should be added or there could be another way around? Thanks

Achterhoeker commented 6 years ago

@vladmelnyk The adapter isn't capable of handling pairs that aren't signalled anymore as a valid market. For this particularly case an extra if is possible. But then we start again introducing more strange handlers for all edge cases.

Example not tested code that could solve your problem: else if (currencyPairIn.length() == 8) { Currency base = assetsMap.get(currencyPairIn.substring(0, 4)); if (base == null) { base = new Currency(currencyPairIn.substring(0,4));
} if (base.getCommonlyUsedCurrency() != null) { base = base.getCommonlyUsedCurrency(); } Currency counter = assetsMap.get(currencyPairIn.substring(0, 4)); if (counter == null) { counter = new Currency(currencyPairIn.substring(4,8));
} if (counter.getCommonlyUsedCurrency() != null) { counter = counter.getCommonlyUsedCurrency(); } pair = new CurrencyPair(base, counter); }

This code tries to get a translation from kraken code to an xchange currency. If it fails, it will create a new one with the name from Kraken. In your case it should work. (XXBT and XLTC are still present. With an older coin not present anymore on Kraken you could expect a strange coin name like XLTC (if kraken dropped ltc completely)

vladmelnyk commented 6 years ago

@Achterhoeker I am suggesting including support for 8 symbol pairs anyway - because there are pairs like USDTZUSD XETCXETH XETCXXBT that are size of 8.

Achterhoeker commented 6 years ago

@vladmelnyk The other current pairs are supported by the currencypair map. That map is build with all symbols retrieved from the Kraken exchange. All pairs currently signalled by Kraken are working correctly as far as i know. (my bot is using Kraken with all pairs)

jcuypers commented 6 years ago

Isn't there a way we could create some form/notion of active currency pairs that are currently tradable on an exchange and ones that have been available before at some point in time? As there are frequent changes to these tables you can't reliably used them as a ground-truth for a project, causing duplicate work and data.

archenroot commented 6 years ago

@jcuypers - so you say, these structures will be established once you connect to exchange on the user end?

Maybe we can establish some kind of continuous feeder which iterates trough all exchanges and populate all tables by keeping them active and marks those invalid. This script can run all the day and generate these currency pairs structures in source code form. Once difference found, it will generate new change and commit into some specific branch. What do you think about this? So we can have some branch which has still latest currency pairs accross all exchanges.