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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations