Search in sources :

Example 1 with CurrencyPair

use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.

the class BitstampAdapters method adaptMetaData.

public static ExchangeMetaData adaptMetaData(List<BitstampPairInfo> rawSymbols, ExchangeMetaData metaData) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = adaptCurrencyPairs(rawSymbols);
    Map<CurrencyPair, CurrencyPairMetaData> pairsMap = metaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currenciesMap = metaData.getCurrencies();
    for (Map.Entry<CurrencyPair, CurrencyPairMetaData> entry : currencyPairs.entrySet()) {
        CurrencyPair c = entry.getKey();
        CurrencyPairMetaData cmeta = entry.getValue();
        if (!pairsMap.containsKey(c)) {
            pairsMap.put(c, cmeta);
        } else {
            pairsMap.replace(c, cmeta);
        }
        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) HashMap(java.util.HashMap) Map(java.util.Map) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with CurrencyPair

use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.

the class CoingiAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(CoingiOrdersList ordersList) {
    List<UserTrade> trades = new ArrayList<>();
    for (CoingiOrder o : ordersList.getList()) {
        final OrderType orderType = o.getType() == 0 ? OrderType.BID : OrderType.ASK;
        final CurrencyPair pair = new CurrencyPair(o.getCurrencyPair().get("base").toUpperCase(), o.getCurrencyPair().get("counter").toUpperCase());
        UserTrade trade = new UserTrade.Builder().type(orderType).originalAmount(o.getOriginalBaseAmount()).currencyPair(pair).price(o.getPrice()).timestamp(new Date(o.getTimestamp())).id(o.getId()).orderId(o.getId()).feeAmount(BigDecimal.ZERO).build();
        trades.add(trade);
    }
    return new UserTrades(trades, TradeSortType.SortByID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with CurrencyPair

use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.

the class CoingiTradeService method getOrder.

@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
    try {
        Collection<Order> orders = new ArrayList<>();
        for (String orderId : orderIds) {
            CoingiGetOrderRequest request = new CoingiGetOrderRequest().setOrderId(orderId);
            CoingiOrder coingiOrder;
            coingiOrder = getCoingiOrder(request);
            CurrencyPair currencyPair = CoingiAdapters.adaptCurrency(coingiOrder.getCurrencyPair());
            Date date = new Date(coingiOrder.getTimestamp() * 1000);
            Order order = new LimitOrder(coingiOrder.getType() == 0 ? Order.OrderType.BID : Order.OrderType.ASK, coingiOrder.getOriginalBaseAmount(), currencyPair, coingiOrder.getId(), date, coingiOrder.getPrice());
            order.setOrderStatus(CoingiAdapters.adaptOrderStatus(coingiOrder.getStatus()));
            orders.add(order);
        }
        return orders;
    } catch (CoingiException e) {
        throw CoingiErrorAdapter.adapt(e);
    }
}
Also used : CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) CoingiException(org.knowm.xchange.coingi.dto.CoingiException) CoingiGetOrderRequest(org.knowm.xchange.coingi.dto.trade.CoingiGetOrderRequest) ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 4 with CurrencyPair

use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.

the class CmcAdapter method adaptTickerList.

public static List<Ticker> adaptTickerList(List<CmcTicker> cmcTickerList) {
    List<Ticker> tickerList = new ArrayList<>();
    cmcTickerList.forEach(cmcTicker -> {
        cmcTicker.getQuote().forEach((currencySymbol, quote) -> {
            CurrencyPair pair = new CurrencyPair(cmcTicker.getSymbol(), currencySymbol);
            tickerList.add(adaptTicker(cmcTicker, pair));
        });
    });
    return tickerList;
}
Also used : CmcTicker(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) ArrayList(java.util.ArrayList) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 5 with CurrencyPair

use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.

the class CoinMarketCapExchange method getExchangeSymbols.

@Override
public List<CurrencyPair> getExchangeSymbols() {
    List<Currency> currencies = marketDataService.getCurrencies();
    List<CurrencyPair> pairs = new ArrayList<>();
    for (Currency currency : currencies) {
        pairs.add(new CurrencyPair(currency, Currency.USD));
        pairs.add(new CurrencyPair(currency, Currency.BTC));
    }
    return pairs;
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

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