Search in sources :

Example 21 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class CoinbaseProExchangeIntegration method testExchangeMetaData.

@Test
public void testExchangeMetaData() {
    final Exchange exchange = ExchangeFactory.INSTANCE.createExchange(CoinbaseProExchange.class);
    ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData();
    Assert.assertNotNull(exchangeMetaData);
    Assert.assertNotNull(exchangeMetaData.getCurrencies());
    Assert.assertNotNull("USDC is not defined", exchangeMetaData.getCurrencies().get(new Currency("USDC")));
}
Also used : Exchange(org.knowm.xchange.Exchange) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) Test(org.junit.Test)

Example 22 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class DsxAdapters method adaptToExchangeMetaData.

public static ExchangeMetaData adaptToExchangeMetaData(List<DsxSymbol> symbols, Map<Currency, CurrencyMetaData> currencies, Map<CurrencyPair, CurrencyPairMetaData> currencyPairs) {
    if (symbols != null) {
        for (DsxSymbol symbol : symbols) {
            CurrencyPair pair = adaptSymbol(symbol);
            BigDecimal tickSize = symbol.getTickSize();
            // not 100% sure this is correct
            int priceScale = tickSize.scale();
            BigDecimal tradingFee = symbol.getTakeLiquidityRate();
            BigDecimal minimumAmount = symbol.getQuantityIncrement();
            BigDecimal maximumAmount = null;
            FeeTier[] feeTiers = null;
            if (currencyPairs.containsKey(pair)) {
                CurrencyPairMetaData existing = currencyPairs.get(pair);
                minimumAmount = existing.getMinimumAmount();
                maximumAmount = existing.getMaximumAmount();
                feeTiers = existing.getFeeTiers();
            }
            CurrencyPairMetaData meta = new CurrencyPairMetaData(tradingFee, minimumAmount, maximumAmount, priceScale, feeTiers);
            currencyPairs.put(pair, meta);
        }
    }
    return new ExchangeMetaData(currencyPairs, currencies, null, null, null);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) FeeTier(org.knowm.xchange.dto.meta.FeeTier) BigDecimal(java.math.BigDecimal) DsxSymbol(org.knowm.xchange.dsx.dto.DsxSymbol) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 23 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class CryptopiaAdaptersTest method testExchangeMetaDataAdapter.

@Test
public void testExchangeMetaDataAdapter() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = CryptopiaAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/cryptopia/dto/marketdata/example-currencies.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    CryptopiaBaseResponse<List<CryptopiaCurrency>> cryptopiaCurrencies = mapper.readValue(is, CryptopiaBaseResponseCryptopiaCurrency.class);
    is.close();
    assertThat(cryptopiaCurrencies).isNotNull();
    is = CryptopiaAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/cryptopia/dto/marketdata/example-trade-pairs.json");
    CryptopiaBaseResponse<List<CryptopiaTradePair>> cryptopiaTradePairs = mapper.readValue(is, CryptopiaBaseResponseCryptopiaTradePair.class);
    is.close();
    assertThat(cryptopiaTradePairs).isNotNull();
    ExchangeMetaData exchangeMetaData = CryptopiaAdapters.adaptToExchangeMetaData(cryptopiaCurrencies.getData(), cryptopiaTradePairs.getData());
    assertThat(exchangeMetaData).isNotNull();
    assertThat(exchangeMetaData.getCurrencies()).containsKey(Currency.ETH);
    assertThat(exchangeMetaData.getCurrencies().get(Currency.ETH).getScale()).isEqualTo(8);
    assertThat(exchangeMetaData.getCurrencyPairs()).containsKey(CurrencyPair.ETH_BTC);
    assertThat(exchangeMetaData.getCurrencyPairs().get(CurrencyPair.ETH_BTC).getTradingFee().toString()).isEqualTo("0.20000000");
}
Also used : InputStream(java.io.InputStream) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 24 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class BitcoinChartsAdapters method adaptMetaData.

public static ExchangeMetaData adaptMetaData(ExchangeMetaData exchangeMetaData, BitcoinChartsTicker[] tickers) {
    Map<CurrencyPair, CurrencyPairMetaData> pairs = new HashMap<>();
    for (BitcoinChartsTicker ticker : tickers) {
        BigDecimal anyPrice = firstNonNull(ticker.getAsk(), ticker.getBid(), ticker.getClose(), ticker.getHigh(), ticker.getHigh());
        int scale = anyPrice != null ? anyPrice.scale() : 0;
        pairs.put(new CurrencyPair(Currency.BTC, Currency.getInstance(ticker.getSymbol())), new CurrencyPairMetaData(null, null, null, scale, null));
    }
    return new ExchangeMetaData(pairs, exchangeMetaData.getCurrencies(), exchangeMetaData.getPublicRateLimits(), exchangeMetaData.getPrivateRateLimits(), exchangeMetaData.isShareRateLimits());
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) HashMap(java.util.HashMap) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) BitcoinChartsTicker(org.knowm.xchange.bitcoincharts.dto.marketdata.BitcoinChartsTicker)

Example 25 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class BleutradeAdaptersTest method shouldAdaptExchangeMetaData.

@Test
public void shouldAdaptExchangeMetaData() throws IOException {
    // given
    final BleutradeCurrenciesReturn currenciesResponse = parse(BleutradeCurrenciesReturn.class);
    final BleutradeMarketsReturn marketsResponse = parse(BleutradeMarketsReturn.class);
    final CurrencyPairMetaData[] expectedMetaDataList = expectedMetaDataList();
    final String[] expectedMetaDataStr = expectedMetaDataStr();
    // when
    ExchangeMetaData exchangeMetaData = BleutradeAdapters.adaptToExchangeMetaData(currenciesResponse.getResult(), marketsResponse.getResult());
    // then
    Map<Currency, CurrencyMetaData> currencyMetaDataMap = exchangeMetaData.getCurrencies();
    assertThat(currencyMetaDataMap).hasSize(2);
    assertThat(currencyMetaDataMap.get(Currency.BTC).getScale()).isEqualTo(8);
    assertThat(currencyMetaDataMap.get(Currency.LTC).getScale()).isEqualTo(8);
    Map<CurrencyPair, CurrencyPairMetaData> marketMetaDataMap = exchangeMetaData.getCurrencyPairs();
    assertThat(marketMetaDataMap).hasSize(2);
    // there is no reliable information about valid tradingFee calculation formula
    BleutradeAssert.assertEquals(marketMetaDataMap.get(CurrencyPair.DOGE_BTC), expectedMetaDataList[0]);
    assertThat(marketMetaDataMap.get(CurrencyPair.DOGE_BTC).toString()).isEqualTo(expectedMetaDataStr[0]);
    BleutradeAssert.assertEquals(marketMetaDataMap.get(BLEU_BTC_CP), expectedMetaDataList[1]);
    assertThat(marketMetaDataMap.get(BLEU_BTC_CP).toString()).isEqualTo(expectedMetaDataStr[1]);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BleutradeMarketsReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarketsReturn) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) BleutradeCurrenciesReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeCurrenciesReturn) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Aggregations

ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)33 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)23 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)22 Currency (org.knowm.xchange.currency.Currency)18 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)18 HashMap (java.util.HashMap)12 BigDecimal (java.math.BigDecimal)11 Test (org.junit.Test)9 Exchange (org.knowm.xchange.Exchange)5 FeeTier (org.knowm.xchange.dto.meta.FeeTier)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 RateLimit (org.knowm.xchange.dto.meta.RateLimit)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Fee (org.knowm.xchange.dto.account.Fee)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 InputStream (java.io.InputStream)2 MathContext (java.math.MathContext)2