use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.
the class GateioAdapters method adaptTrade.
public static Trade adaptTrade(GateioTradeHistory.GateioPublicTrade trade, CurrencyPair currencyPair) {
OrderType orderType = adaptOrderType(trade.getType());
Date timestamp = DateUtils.fromMillisUtc(trade.getDate() * 1000);
return new Trade.Builder().type(orderType).originalAmount(trade.getAmount()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(timestamp).id(trade.getTradeId()).build();
}
use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.
the class GeminiAdapters method adaptOrders.
public static OpenOrders adaptOrders(GeminiOrderStatusResponse[] activeOrders, CurrencyPair currencyPair) {
List<LimitOrder> limitOrders = new ArrayList<>(activeOrders.length);
for (GeminiOrderStatusResponse order : activeOrders) {
CurrencyPair currentCurrencyPair = adaptCurrencyPair(order.getSymbol());
if (currencyPair != null && !currentCurrencyPair.equals(currencyPair)) {
continue;
}
OrderType orderType = order.getSide().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
Date timestamp = convertBigDecimalTimestampToDate(new BigDecimal(order.getTimestamp()));
OrderStatus status = OrderStatus.NEW;
if (order.isCancelled()) {
status = OrderStatus.CANCELED;
} else if (order.getExecutedAmount().signum() > 0 && order.getExecutedAmount().compareTo(order.getOriginalAmount()) < 0) {
status = OrderStatus.PARTIALLY_FILLED;
} else if (order.getExecutedAmount().compareTo(order.getOriginalAmount()) == 0) {
status = OrderStatus.FILLED;
}
LimitOrder limitOrder = new LimitOrder(orderType, order.getOriginalAmount(), currentCurrencyPair, String.valueOf(order.getId()), timestamp, order.getPrice(), order.getAvgExecutionPrice(), order.getExecutedAmount(), null, status);
limitOrders.add(limitOrder);
}
return new OpenOrders(limitOrders);
}
use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.
the class LivecoinAdapters method adaptTrades.
public static Trades adaptTrades(List<LivecoinTrade> tradesRaw, CurrencyPair currencyPair) {
if (tradesRaw.isEmpty()) {
return new Trades(Collections.emptyList());
}
List<Trade> trades = new ArrayList<>(tradesRaw.size());
for (LivecoinTrade trade : tradesRaw) {
OrderType type = trade.getType().equals("SELL") ? OrderType.BID : OrderType.ASK;
Trade t = new Trade.Builder().type(type).originalAmount(trade.getQuantity()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(parseDate(trade.getTime())).id(String.valueOf(trade.getId())).build();
trades.add(t);
}
return new Trades(trades, tradesRaw.get(0).getId(), TradeSortType.SortByID);
}
use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.
the class LivecoinAdapters method adaptUserOrder.
public static Order adaptUserOrder(LivecoinUserOrder order) {
OrderType type;
boolean limit;
switch(order.getType()) {
case "MARKET_SELL":
type = OrderType.ASK;
limit = false;
break;
case "LIMIT_SELL":
type = OrderType.ASK;
limit = true;
break;
case "LIMIT_BUY":
type = OrderType.BID;
limit = true;
break;
case "MARKET_BUY":
type = OrderType.BID;
limit = false;
break;
default:
throw new ExchangeException("Order id=" + order.getId() + " has unknown type " + order.getType());
}
CurrencyPair pair = new CurrencyPair(order.getCurrencyPair());
Order.OrderStatus status;
if (order.getRemainingQuantity().compareTo(BigDecimal.ZERO) == 0) {
status = Order.OrderStatus.FILLED;
} else {
status = order.getRemainingQuantity().compareTo(order.getQuantity()) < 0 ? Order.OrderStatus.PARTIALLY_FILLED : Order.OrderStatus.PENDING_NEW;
}
Order.Builder builder;
if (limit) {
builder = new LimitOrder.Builder(type, pair).limitPrice(order.getPrice()).remainingAmount(order.getRemainingQuantity());
} else {
builder = new MarketOrder.Builder(type, pair).averagePrice(order.getPrice());
}
return builder.originalAmount(order.getQuantity()).id(order.getId().toString()).timestamp(DateUtils.fromUnixTime(order.getIssueTime())).orderStatus(status).build();
}
use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.
the class UpbitAdapters method adaptOrderBook.
public static OrderBook adaptOrderBook(UpbitOrderBooks upbitOrderBooks) {
UpbitOrderBook upbitOrderBook = upbitOrderBooks.getUpbitOrderBooks()[0];
CurrencyPair currencyPair = UpbitUtils.toCurrencyPair(upbitOrderBook.getMarket());
Map<OrderType, List<LimitOrder>> orderbookMap = adaptMarketOrderToLimitOrder(upbitOrderBook.getOrderbookUnits(), currencyPair);
return new OrderBook(DateUtils.fromMillisUtc(upbitOrderBook.getTimestamp().longValue()), orderbookMap.get(OrderType.ASK), orderbookMap.get(OrderType.BID));
}
Aggregations