Search in sources :

Example 11 with CurrencyPair

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();
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 12 with CurrencyPair

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;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) LgoCurrency(org.knowm.xchange.lgo.dto.currency.LgoCurrency) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) LgoProduct(org.knowm.xchange.lgo.dto.product.LgoProduct) Currency(org.knowm.xchange.currency.Currency) LgoCurrency(org.knowm.xchange.lgo.dto.currency.LgoCurrency) FeeTier(org.knowm.xchange.dto.meta.FeeTier) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 13 with CurrencyPair

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);
    }
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) LatokenCurrency(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenCurrency) Currency(org.knowm.xchange.currency.Currency) LatokenCurrency(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenCurrency) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LatokenPair(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenPair) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 14 with CurrencyPair

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);
    }
}
Also used : LatokenException(org.knowm.xchange.latoken.dto.LatokenException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) LatokenUserTrades(org.knowm.xchange.latoken.dto.trade.LatokenUserTrades) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 15 with CurrencyPair

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());
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) PLINK(org.knowm.xchange.currency.Currency.PLINK) HashMap(java.util.HashMap) USD(org.knowm.xchange.currency.Currency.USD) Collectors(java.util.stream.Collectors) DAI(org.knowm.xchange.currency.Currency.DAI) BigDecimal(java.math.BigDecimal) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) USDC(org.knowm.xchange.currency.Currency.USDC) Stream(java.util.stream.Stream) PBTC(org.knowm.xchange.currency.Currency.PBTC) WETH(org.knowm.xchange.currency.Currency.WETH) Map(java.util.Map) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) SortedMap(java.util.SortedMap) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal)

Aggregations

CurrencyPair (org.knowm.xchange.currency.CurrencyPair)518 BigDecimal (java.math.BigDecimal)157 Test (org.junit.Test)125 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)121 Date (java.util.Date)108 ArrayList (java.util.ArrayList)107 Ticker (org.knowm.xchange.dto.marketdata.Ticker)91 Currency (org.knowm.xchange.currency.Currency)88 OrderType (org.knowm.xchange.dto.Order.OrderType)81 Exchange (org.knowm.xchange.Exchange)76 Order (org.knowm.xchange.dto.Order)70 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)60 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)58 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)57 UserTrade (org.knowm.xchange.dto.trade.UserTrade)57 List (java.util.List)54 HashMap (java.util.HashMap)53 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)53 UserTrades (org.knowm.xchange.dto.trade.UserTrades)51 IOException (java.io.IOException)43