Search in sources :

Example 26 with OrderType

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();
}
Also used : GateioTrade(org.knowm.xchange.gateio.dto.trade.GateioTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) GateioOrderType(org.knowm.xchange.gateio.dto.GateioOrderType) Date(java.util.Date)

Example 27 with OrderType

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);
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 28 with OrderType

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);
}
Also used : LivecoinTrade(org.knowm.xchange.livecoin.dto.marketdata.LivecoinTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) LivecoinTrade(org.knowm.xchange.livecoin.dto.marketdata.LivecoinTrade)

Example 29 with OrderType

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();
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) LivecoinUserOrder(org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder) LivecoinOrder(org.knowm.xchange.livecoin.dto.marketdata.LivecoinOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) OrderType(org.knowm.xchange.dto.Order.OrderType) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 30 with OrderType

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));
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) UpbitOrderBook(org.knowm.xchange.upbit.dto.marketdata.UpbitOrderBook) UpbitOrderBook(org.knowm.xchange.upbit.dto.marketdata.UpbitOrderBook) ArrayList(java.util.ArrayList) List(java.util.List) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

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