use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class BleutradeAdaptersTest method shouldAdaptMarkets.
@Test
public void shouldAdaptMarkets() throws IOException {
// given
final BleutradeMarketsReturn response = parse(BleutradeMarketsReturn.class);
// when
Set<CurrencyPair> currencyPairs = BleutradeAdapters.adaptBleutradeCurrencyPairs(response);
// then
assertThat(currencyPairs).hasSize(2);
assertThat(currencyPairs).contains(CurrencyPair.DOGE_BTC, BLEU_BTC_CP);
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class DragonexMarketDataService method getOrderBook.
@Override
public OrderBook getOrderBook(CurrencyPair pair, Object... args) throws IOException {
long symbolId = exchange.symbolId(pair);
BiFunction<OrderType, Order, LimitOrder> f = (t, o) -> new LimitOrder(t, o.volume, pair, null, null, o.price);
// currently the max count of orders: 50
Depth d = super.marketDepth(symbolId, 50);
List<LimitOrder> bids = d.getBuys().stream().map(o -> f.apply(OrderType.BID, o)).collect(Collectors.toList());
List<LimitOrder> asks = d.getSells().stream().map(o -> f.apply(OrderType.ASK, o)).collect(Collectors.toList());
return new OrderBook(null, asks, bids);
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class DragonexTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
if (!(params instanceof TradeHistoryParamCurrencyPair)) {
throw new ExchangeException("You need to provide the currency pair.");
}
TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
CurrencyPair pair = pairParams.getCurrencyPair();
if (pair == null) {
throw new ExchangeException("You need to provide the currency pair.");
}
long symbolId = exchange.symbolId(pair);
Integer direction = null;
if (params instanceof TradeHistoryParamsSorted) {
TradeHistoryParamsSorted sort = (TradeHistoryParamsSorted) params;
direction = sort.getOrder() == Order.asc ? 1 : 2;
}
DealHistoryRequest req = new DealHistoryRequest(symbolId, direction, null, 1000);
DealHistory dealHistory = super.dealHistory(exchange.getOrCreateToken().token, req);
List<UserTrade> trades = dealHistory.getList().stream().map(d -> {
CurrencyPair currencyPair = exchange.pair(d.symbolId);
return new UserTrade.Builder().type(d.orderType == 1 ? OrderType.BID : OrderType.ASK).originalAmount(d.volume).currencyPair(currencyPair).price(d.price).timestamp(d.getTimestamp()).id(d.tradeId).orderId(d.orderId).feeAmount(d.charge).feeCurrency(currencyPair.counter).build();
}).collect(Collectors.toList());
return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class DVChainAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(List<DVChainTrade> trades) {
List<UserTrade> pastTrades = new ArrayList<>(trades.size());
for (DVChainTrade trade : trades) {
Order.OrderType orderType = trade.getSide().equalsIgnoreCase("buy") ? Order.OrderType.BID : Order.OrderType.ASK;
Date timestamp = Date.from(trade.getCreatedAt());
CurrencyPair currencyPair = new CurrencyPair(trade.getAsset(), "USD");
final BigDecimal fee = null;
pastTrades.add(new UserTrade.Builder().type(orderType).originalAmount(trade.getQuantity()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(timestamp).id(trade.getId()).orderId(trade.getId()).feeAmount(fee).feeCurrency(Currency.USD).build());
}
return new UserTrades(pastTrades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.currency.CurrencyPair in project XChange by knowm.
the class DVChainAdapters method adaptOpenOrders.
public static OpenOrders adaptOpenOrders(List<DVChainTrade> orders) {
List<LimitOrder> openOrders = new ArrayList<>(orders.size());
for (DVChainTrade order : orders) {
CurrencyPair currencyPair = new CurrencyPair(order.getAsset(), "USD");
Order.OrderType orderType = order.getSide().equals("buy") ? Order.OrderType.BID : Order.OrderType.ASK;
LimitOrder limitOrder = new LimitOrder(orderType, order.getQuantity(), order.getQuantity(), currencyPair, order.getId(), Date.from(order.getCreatedAt()), order.getLimitPrice());
openOrders.add(limitOrder);
}
return new OpenOrders(openOrders);
}
Aggregations