use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class LgoAdapters method adaptUserTrade.
private static UserTrade adaptUserTrade(LgoUserTrade lgoUserTrade) {
OrderType type = adaptUserTradeType(lgoUserTrade);
CurrencyPair currencyPair = adaptProductId(lgoUserTrade.getProductId());
Date creationDate = lgoUserTrade.getCreationDate();
return new UserTrade.Builder().type(type).originalAmount(lgoUserTrade.getQuantity()).currencyPair(currencyPair).price(lgoUserTrade.getPrice()).timestamp(creationDate).id(lgoUserTrade.getId()).orderId(lgoUserTrade.getOrderId()).feeAmount(lgoUserTrade.getFees()).feeCurrency(currencyPair.counter).build();
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class LgoAdapters method adaptMetadata.
public static ExchangeMetaData adaptMetadata(ExchangeMetaData metaData, LgoProducts products, LgoCurrencies currencies) {
Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = metaData.getCurrencyPairs();
Map<Currency, CurrencyMetaData> currency = metaData.getCurrencies();
for (LgoCurrency lgoCurrency : currencies.getCurrencies()) {
currency.put(Currency.getInstance(lgoCurrency.getCode()), new CurrencyMetaData(lgoCurrency.getDecimals(), null));
}
for (LgoProduct product : products.getProducts()) {
BigDecimal minAmount = product.getBase().getLimits().getMin();
BigDecimal maxAmount = product.getBase().getLimits().getMax();
Integer baseScale = currency.get(Currency.getInstance(product.getBase().getId())).getScale();
BigDecimal increment = product.getQuote().getIncrement().stripTrailingZeros();
currencyPairs.put(toPair(product), new CurrencyPairMetaData(null, minAmount, maxAmount, null, null, baseScale, increment.scale(), null, new FeeTier[0], increment, Currency.USD, true));
}
return metaData;
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class LatokenExchange method remoteInit.
@Override
public void remoteInit() {
try {
// Load the static meta-data and override with the dynamic one
Map<Currency, CurrencyMetaData> currenciesMetaData = exchangeMetaData.getCurrencies();
Map<CurrencyPair, CurrencyPairMetaData> pairsMetaData = exchangeMetaData.getCurrencyPairs();
List<LatokenPair> allPairs = latoken.getAllPairs();
List<LatokenCurrency> allCurrencies = latoken.getAllCurrencies();
// Save pairs map on the exchange
this.exchangeSpecification.setExchangeSpecificParametersItem("pairs", allPairs);
// Update Currency meta-data
for (LatokenCurrency latokenCurrency : allCurrencies) {
Currency currency = LatokenAdapters.adaptCurrency(latokenCurrency);
addCurrencyMetadata(currenciesMetaData, currency, PRECISION);
}
// Update CurrencyPair meta-data
for (LatokenPair latokenPair : allPairs) {
CurrencyPair pair = LatokenAdapters.adaptCurrencyPair(latokenPair);
CurrencyPairMetaData pairMetadata = LatokenAdapters.adaptPairMetaData(latokenPair);
addCurrencyPairMetadata(pairsMetaData, pair, pairMetadata);
}
} catch (Exception e) {
throw new ExchangeException("Failed to initialize: " + e.getMessage(), e);
}
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class LatokenTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
if (params instanceof TradeHistoryParamCurrencyPair == false) {
throw new ExchangeException("CurrencyPair must be provided to get user trades.");
}
TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
CurrencyPair pair = pairParams.getCurrencyPair();
if (pair == null) {
throw new ExchangeException("CurrencyPair must be provided to get user trades.");
}
// Limit is an optional parameter
Integer limit = null;
if (params instanceof TradeHistoryParamLimit) {
TradeHistoryParamLimit limitParams = (TradeHistoryParamLimit) params;
limit = limitParams.getLimit();
}
try {
LatokenUserTrades latokenTrades = getLatokenUserTrades(pair, limit);
return LatokenAdapters.adaptUserTrades(this.exchange, latokenTrades);
} catch (LatokenException e) {
throw LatokenErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class dydxStreamingAdapters method dydxOrderBookChanges.
public static List<LimitOrder> dydxOrderBookChanges(org.knowm.xchange.dto.Order.OrderType orderType, CurrencyPair currencyPair, String[][] changes, SortedMap<BigDecimal, BigDecimal> sideEntries, int maxDepth, boolean isV1) {
if (sideEntries == null) {
return Collections.emptyList();
}
if (changes != null) {
for (String[] level : changes) {
BigDecimal price;
BigDecimal volume;
if (isV1) {
price = new BigDecimal(level[level.length - 2]).movePointRight(amounts.get(currencyPair.base) - amounts.get(currencyPair.counter));
volume = new BigDecimal(level[level.length - 1]).movePointLeft(amounts.get(currencyPair.base));
} else {
price = new BigDecimal(level[level.length - 2]);
volume = new BigDecimal(level[level.length - 1]);
}
sideEntries.put(price, volume);
}
}
Stream<Map.Entry<BigDecimal, BigDecimal>> stream = sideEntries.entrySet().stream().filter(level -> level.getValue().compareTo(BigDecimal.ZERO) != 0);
if (maxDepth != 0) {
stream = stream.limit(maxDepth);
}
return stream.map(level -> new LimitOrder(orderType, level.getValue(), currencyPair, "0", null, level.getKey())).collect(Collectors.toList());
}
Aggregations