Search in sources :

Example 21 with CurrencyPairMetaData

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

the class FtxAdapters method adaptExchangeMetaData.

public static ExchangeMetaData adaptExchangeMetaData(FtxMarketsDto marketsDto) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = new HashMap<>();
    Map<Currency, CurrencyMetaData> currency = new HashMap<>();
    marketsDto.getMarketList().forEach(ftxMarketDto -> {
        CurrencyPairMetaData currencyPairMetaData = new CurrencyPairMetaData.Builder().amountStepSize(ftxMarketDto.getPriceIncrement()).minimumAmount(ftxMarketDto.getSizeIncrement()).priceScale(ftxMarketDto.getPriceIncrement().scale()).baseScale(ftxMarketDto.getSizeIncrement().scale()).build();
        if ("spot".equals(ftxMarketDto.getType())) {
            CurrencyPair currencyPair = new CurrencyPair(ftxMarketDto.getBaseCurrency(), ftxMarketDto.getQuoteCurrency());
            currencyPairs.put(currencyPair, currencyPairMetaData);
            if (!currency.containsKey(currencyPair.base)) {
                currency.put(currencyPair.base, new CurrencyMetaData(ftxMarketDto.getSizeIncrement().scale(), BigDecimal.ZERO));
            }
            if (!currency.containsKey(currencyPair.counter)) {
                currency.put(currencyPair.counter, new CurrencyMetaData(ftxMarketDto.getPriceIncrement().scale(), BigDecimal.ZERO));
            }
        } else if ("future".equals(ftxMarketDto.getType()) && ftxMarketDto.getName().contains("-")) {
            CurrencyPair futuresContract = new CurrencyPair(ftxMarketDto.getName());
            currencyPairs.put(futuresContract, currencyPairMetaData);
        }
    });
    RateLimit[] rateLimits = { new RateLimit(30, 1, TimeUnit.SECONDS) };
    return new ExchangeMetaData(currencyPairs, currency, rateLimits, rateLimits, true);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) RateLimit(org.knowm.xchange.dto.meta.RateLimit) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) HashMap(java.util.HashMap) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 22 with CurrencyPairMetaData

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

the class GeminiAdapters method adaptMetaData.

public static ExchangeMetaData adaptMetaData(List<CurrencyPair> currencyPairs, ExchangeMetaData metaData) {
    Map<CurrencyPair, CurrencyPairMetaData> pairsMap = metaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currenciesMap = metaData.getCurrencies();
    for (CurrencyPair c : currencyPairs) {
        if (!pairsMap.containsKey(c)) {
            pairsMap.put(c, null);
        }
        if (!currenciesMap.containsKey(c.base)) {
            currenciesMap.put(c.base, null);
        }
        if (!currenciesMap.containsKey(c.counter)) {
            currenciesMap.put(c.counter, null);
        }
    }
    return metaData;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 23 with CurrencyPairMetaData

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

the class LivecoinAdapters method adaptToExchangeMetaData.

public static ExchangeMetaData adaptToExchangeMetaData(ExchangeMetaData exchangeMetaData, List<LivecoinRestriction> products) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currencies = exchangeMetaData.getCurrencies();
    for (LivecoinRestriction product : products) {
        CurrencyPair pair = adaptCurrencyPair(product);
        CurrencyPairMetaData staticMetaData = exchangeMetaData.getCurrencyPairs().get(pair);
        CurrencyPairMetaData.Builder builder;
        if (staticMetaData == null) {
            builder = new CurrencyPairMetaData.Builder();
        } else {
            builder = CurrencyPairMetaData.Builder.from(staticMetaData);
        }
        if (product.getPriceScale() != null) {
            builder.priceScale(product.getPriceScale());
        } else if (staticMetaData != null && staticMetaData.getPriceScale() == null) {
            builder.priceScale(FALLBACK_PRICE_SCALE);
        }
        if (!(staticMetaData != null && staticMetaData.getBaseScale() != null)) {
            builder.baseScale(LIVECOIN_BASE_SCALE);
        }
        if (product.getMinLimitQuantity() != null) {
            builder.minimumAmount(product.getMinLimitQuantity());
        }
        currencyPairs.put(pair, builder.build());
        if (!currencies.containsKey(pair.base))
            currencies.put(pair.base, null);
        if (!currencies.containsKey(pair.counter))
            currencies.put(pair.counter, null);
    }
    return new ExchangeMetaData(currencyPairs, currencies, null, null, true);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) LivecoinRestriction(org.knowm.xchange.livecoin.dto.marketdata.LivecoinRestriction) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 24 with CurrencyPairMetaData

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

the class BitcointoyouExchangeTest method testExchangeMetaData.

@Test
public void testExchangeMetaData() throws Exception {
    final SoftAssertions softly = new SoftAssertions();
    ExchangeMetaData exchangeMetaData = sut.getExchangeMetaData();
    softly.assertThat(exchangeMetaData).isNotNull();
    softly.assertThat(exchangeMetaData.isShareRateLimits()).isTrue();
    softly.assertThat(exchangeMetaData.getCurrencies()).size().isEqualTo(1);
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs();
    softly.assertThat(currencyPairs).size().isEqualTo(1);
    softly.assertThat(currencyPairs).size().isEqualTo(1);
    softly.assertThat(exchangeMetaData.isShareRateLimits()).isTrue();
    RateLimit rateLimit = exchangeMetaData.getPrivateRateLimits()[0];
    softly.assertThat(rateLimit.getPollDelayMillis()).isEqualTo(10000);
    softly.assertAll();
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) RateLimit(org.knowm.xchange.dto.meta.RateLimit) SoftAssertions(org.assertj.core.api.SoftAssertions) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 25 with CurrencyPairMetaData

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

the class BitfinexAdapters method adaptMetaData.

/**
 * Flipped order of arguments to avoid type-erasure clash with {@link #adaptMetaData(List,
 * ExchangeMetaData)}
 *
 * @param exchangeMetaData The exchange metadata provided from bitfinex.json.
 * @param symbolDetails The symbol data fetced from Bitfinex.
 * @return The combined result.
 */
public static ExchangeMetaData adaptMetaData(ExchangeMetaData exchangeMetaData, List<BitfinexSymbolDetail> symbolDetails, Map<CurrencyPair, BigDecimal> lastPrices) {
    final Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs();
    symbolDetails.parallelStream().forEach(bitfinexSymbolDetail -> {
        final CurrencyPair currencyPair = adaptCurrencyPair(bitfinexSymbolDetail.getPair());
        // Infer price-scale from last and price-precision
        BigDecimal last = lastPrices.get(currencyPair);
        if (last != null) {
            int pricePercision = bitfinexSymbolDetail.getPrice_precision();
            int priceScale = last.scale() + (pricePercision - last.precision());
            CurrencyPairMetaData newMetaData = new CurrencyPairMetaData(currencyPairs.get(currencyPair) == null ? null : currencyPairs.get(currencyPair).getTradingFee(), bitfinexSymbolDetail.getMinimum_order_size(), bitfinexSymbolDetail.getMaximum_order_size(), priceScale, null);
            currencyPairs.put(currencyPair, newMetaData);
        }
    });
    return exchangeMetaData;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)52 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)45 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)33 Currency (org.knowm.xchange.currency.Currency)32 BigDecimal (java.math.BigDecimal)22 ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)22 HashMap (java.util.HashMap)16 Test (org.junit.Test)10 FeeTier (org.knowm.xchange.dto.meta.FeeTier)10 IOException (java.io.IOException)7 Map (java.util.Map)7 Fee (org.knowm.xchange.dto.account.Fee)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 RateLimit (org.knowm.xchange.dto.meta.RateLimit)4 WalletHealth (org.knowm.xchange.dto.meta.WalletHealth)4 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2