Search in sources :

Example 96 with CurrencyPair

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);
}
Also used : BleutradeMarketsReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarketsReturn) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 97 with CurrencyPair

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);
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dragonex.dto.marketdata.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Ticker(org.knowm.xchange.dto.marketdata.Ticker) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date) BiFunction(java.util.function.BiFunction) IOException(java.io.IOException) Exchange(org.knowm.xchange.Exchange) Collectors(java.util.stream.Collectors) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Order(org.knowm.xchange.dragonex.dto.marketdata.Order) List(java.util.List) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) Depth(org.knowm.xchange.dragonex.dto.marketdata.Depth) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) OrderType(org.knowm.xchange.dto.Order.OrderType) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Depth(org.knowm.xchange.dragonex.dto.marketdata.Depth)

Example 98 with CurrencyPair

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);
}
Also used : TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) OrderType(org.knowm.xchange.dto.Order.OrderType) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) Exchange(org.knowm.xchange.Exchange) OrderHistory(org.knowm.xchange.dragonex.dto.trade.OrderHistory) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) DealHistoryRequest(org.knowm.xchange.dragonex.dto.trade.DealHistoryRequest) OrderHistoryRequest(org.knowm.xchange.dragonex.dto.trade.OrderHistoryRequest) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DealHistory(org.knowm.xchange.dragonex.dto.trade.DealHistory) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) IOException(java.io.IOException) UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderReference(org.knowm.xchange.dragonex.dto.trade.OrderReference) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Collectors(java.util.stream.Collectors) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) UserOrder(org.knowm.xchange.dragonex.dto.trade.UserOrder) OrderPlacement(org.knowm.xchange.dragonex.dto.trade.OrderPlacement) List(java.util.List) Order(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted.Order) TradeService(org.knowm.xchange.service.trade.TradeService) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) DealHistoryRequest(org.knowm.xchange.dragonex.dto.trade.DealHistoryRequest) UserTrade(org.knowm.xchange.dto.trade.UserTrade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) DealHistory(org.knowm.xchange.dragonex.dto.trade.DealHistory) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 99 with CurrencyPair

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);
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) DVChainTrade(org.knowm.xchange.dvchain.dto.trade.DVChainTrade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 100 with CurrencyPair

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);
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) DVChainTrade(org.knowm.xchange.dvchain.dto.trade.DVChainTrade) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) 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