Search in sources :

Example 16 with OrderType

use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.

the class UserTradeTest method returnsEqualsCorrectlyWithUnequalUserTradesOfTradeAttributes.

@Test
public void returnsEqualsCorrectlyWithUnequalUserTradesOfTradeAttributes() {
    final OrderType type = OrderType.ASK;
    final BigDecimal originalAmount = new BigDecimal("100.501");
    final CurrencyPair currencyPair = CurrencyPair.BTC_USD;
    final BigDecimal price = new BigDecimal("250.34");
    final Date timestamp = new Date();
    final UserTrade original = new UserTrade.Builder().type(type).originalAmount(originalAmount).currencyPair(currencyPair).price(price).timestamp(timestamp).id("FooTradeId").orderId("OrderId").feeAmount(new BigDecimal("0")).feeCurrency(Currency.BTC).build();
    final UserTrade copy = new UserTrade.Builder().type(type).originalAmount(originalAmount).currencyPair(currencyPair).price(price).timestamp(timestamp).id("BarTradeId").orderId("OrderId").feeAmount(new BigDecimal("0")).feeCurrency(Currency.BTC).build();
    assertNotEquals(original, copy);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 17 with OrderType

use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.

the class UserTradeTest method testBuilder.

@Test
public void testBuilder() {
    final OrderType type = OrderType.BID;
    final BigDecimal originalAmount = new BigDecimal("99.401");
    final CurrencyPair currencyPair = CurrencyPair.LTC_BTC;
    final BigDecimal price = new BigDecimal("251.64");
    final Date timestamp = new Date();
    final String id = "id";
    final String orderId = "OrderId";
    final BigDecimal feeAmount = new BigDecimal("0.0006");
    final Currency feeCurrency = Currency.BTC;
    final String orderUserReference = "orderUserReference";
    final UserTrade copy = new UserTrade.Builder().type(type).originalAmount(originalAmount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(id).orderId(orderId).feeAmount(feeAmount).feeCurrency(feeCurrency).orderUserReference(orderUserReference).build();
    assertThat(copy.getType()).isEqualTo(type);
    assertThat(copy.getOriginalAmount()).isEqualTo(originalAmount);
    assertThat(copy.getCurrencyPair()).isEqualTo(currencyPair);
    assertThat(copy.getPrice()).isEqualTo(price);
    assertThat(copy.getTimestamp()).isEqualTo(timestamp);
    assertThat(copy.getId()).isEqualTo(id);
    assertThat(copy.getOrderId()).isEqualTo(orderId);
    assertThat(copy.getFeeAmount()).isEqualTo(feeAmount);
    assertThat(copy.getFeeCurrency()).isEqualTo(feeCurrency);
    assertThat(copy.getOrderUserReference()).isEqualTo(orderUserReference);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) Currency(org.knowm.xchange.currency.Currency) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 18 with OrderType

use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.

the class CoinsuperAdapters method adaptTradeHistory.

/**
 * Adapt the user's trades
 *
 * @param CoinsuperUserTransaction
 * @return
 */
public static UserTrades adaptTradeHistory(CoinsuperResponse<List<OrderDetail>> OrderDetails) {
    List<UserTrade> trades = new ArrayList<>();
    long lastTradeId = 0;
    for (OrderDetail orderDetail : OrderDetails.getData().getResult()) {
        OrderType orderType = OrderType.BID;
        if (orderDetail.getAction().equals("SELL")) {
            orderType = OrderType.ASK;
        }
        UserTrade trade = new UserTrade.Builder().type(orderType).originalAmount(orderDetail.getAmount().abs()).currencyPair(new CurrencyPair(orderDetail.getSymbol())).price(orderDetail.getPriceLimit().abs()).timestamp(new Date()).id(Long.toString(orderDetail.getOrderNo())).orderId(Long.toString(orderDetail.getOrderNo())).feeAmount(BigDecimal.valueOf(orderDetail.getFee())).feeCurrency(Currency.getInstance(orderDetail.getSymbol().toUpperCase())).build();
        lastTradeId = orderDetail.getOrderNo();
        trades.add(trade);
    }
    return new UserTrades(trades, lastTradeId, TradeSortType.SortByID);
}
Also used : OrderDetail(org.knowm.xchange.coinsuper.dto.trade.OrderDetail) UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 19 with OrderType

use of org.knowm.xchange.dto.Order.OrderType 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 20 with OrderType

use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.

the class DsxAdapters method adaptTrades.

public static Trades adaptTrades(List<? extends DsxTrade> allDsxTrades, CurrencyPair currencyPair, DsxTradesSortBy sortBy) {
    List<Trade> trades = new ArrayList<>(allDsxTrades.size());
    long lastTradeId = 0;
    for (int i = 0; i < allDsxTrades.size(); i++) {
        DsxTrade dsxTrade = allDsxTrades.get(i);
        Date timestamp = dsxTrade.getTimestamp();
        BigDecimal price = dsxTrade.getPrice();
        BigDecimal amount = dsxTrade.getQuantity();
        String tid = dsxTrade.getId();
        long longTradeId = tid == null ? 0 : Long.parseLong(tid);
        if (longTradeId > lastTradeId) {
            lastTradeId = longTradeId;
        }
        OrderType orderType = adaptSide(dsxTrade.getSide());
        Trade trade = new Trade.Builder().type(orderType).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(tid).build();
        trades.add(trade);
    }
    return new Trades(trades, lastTradeId, sortBy.sortType);
}
Also used : DsxUserTrade(org.knowm.xchange.dsx.dto.DsxUserTrade) DsxOwnTrade(org.knowm.xchange.dsx.dto.DsxOwnTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) DsxTrade(org.knowm.xchange.dsx.dto.DsxTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) DsxTrade(org.knowm.xchange.dsx.dto.DsxTrade) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Aggregations

OrderType (org.knowm.xchange.dto.Order.OrderType)104 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)68 Date (java.util.Date)65 BigDecimal (java.math.BigDecimal)64 UserTrade (org.knowm.xchange.dto.trade.UserTrade)38 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)36 ArrayList (java.util.ArrayList)35 Trade (org.knowm.xchange.dto.marketdata.Trade)25 UserTrades (org.knowm.xchange.dto.trade.UserTrades)19 Order (org.knowm.xchange.dto.Order)15 Currency (org.knowm.xchange.currency.Currency)12 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)12 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)11 Test (org.junit.Test)10 Trades (org.knowm.xchange.dto.marketdata.Trades)10 OrderStatus (org.knowm.xchange.dto.Order.OrderStatus)9 List (java.util.List)6 BitfinexOrderType (org.knowm.xchange.bitfinex.v1.BitfinexOrderType)5 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)5 StopOrder (org.knowm.xchange.dto.trade.StopOrder)5