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);
}
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;
}
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);
}
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();
}
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;
}
Aggregations