Search in sources :

Example 1 with CexIOOrder

use of org.knowm.xchange.cexio.dto.trade.CexIOOrder in project XChange by knowm.

the class CexIOAdapters method adaptOpenOrders.

public static OpenOrders adaptOpenOrders(List<CexIOOrder> cexIOOrderList) {
    List<LimitOrder> limitOrders = new ArrayList<>();
    for (CexIOOrder cexIOOrder : cexIOOrderList) {
        OrderType orderType = cexIOOrder.getType() == CexIOOrder.Type.buy ? OrderType.BID : OrderType.ASK;
        String id = Long.toString(cexIOOrder.getId());
        limitOrders.add(new LimitOrder(orderType, cexIOOrder.getAmount(), cexIOOrder.getAmount().subtract(cexIOOrder.getPending()), new CurrencyPair(cexIOOrder.getSymbol1(), cexIOOrder.getSymbol2()), id, DateUtils.fromMillisUtc(cexIOOrder.getTime()), cexIOOrder.getPrice()));
    }
    return new OpenOrders(limitOrders);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) CexIOOrder(org.knowm.xchange.cexio.dto.trade.CexIOOrder) DateUtils.fromISODateString(org.knowm.xchange.utils.DateUtils.fromISODateString) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with CexIOOrder

use of org.knowm.xchange.cexio.dto.trade.CexIOOrder in project XChange by knowm.

the class CexIOAdapters method adaptOrder.

public static Order adaptOrder(CexIOOpenOrder cexIOOrder) {
    OrderType orderType = cexIOOrder.type.equals("sell") ? OrderType.ASK : OrderType.BID;
    BigDecimal originalAmount = new BigDecimal(cexIOOrder.amount);
    CurrencyPair currencyPair = new CurrencyPair(cexIOOrder.symbol1, cexIOOrder.symbol2);
    Date timestamp = new Date(cexIOOrder.time);
    BigDecimal limitPrice = new BigDecimal(cexIOOrder.price);
    Order.OrderStatus status = adaptOrderStatus(cexIOOrder);
    BigDecimal cumulativeAmount = null;
    try {
        BigDecimal remains = new BigDecimal(cexIOOrder.remains);
        cumulativeAmount = originalAmount.subtract(remains);
    } catch (Exception e) {
    }
    return new LimitOrder(orderType, originalAmount, currencyPair, cexIOOrder.orderId, timestamp, limitPrice, null, cumulativeAmount, null, status);
}
Also used : CexIOArchivedOrder(org.knowm.xchange.cexio.dto.trade.CexIOArchivedOrder) Order(org.knowm.xchange.dto.Order) CexIOFullOrder(org.knowm.xchange.cexio.dto.trade.CexIOFullOrder) CexIOOpenOrder(org.knowm.xchange.cexio.dto.trade.CexIOOpenOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CexIOOrder(org.knowm.xchange.cexio.dto.trade.CexIOOrder) OrderType(org.knowm.xchange.dto.Order.OrderType) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) InvalidFormatException(com.fasterxml.jackson.databind.exc.InvalidFormatException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with CexIOOrder

use of org.knowm.xchange.cexio.dto.trade.CexIOOrder in project XChange by knowm.

the class CexIOTradeService method getOrder.

@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
    List<Order> orders = new ArrayList<>();
    for (String orderId : orderIds) {
        CexIOOpenOrder cexIOOrder = getOrderDetail(orderId);
        orders.add(CexIOAdapters.adaptOrder(cexIOOrder));
    }
    return orders;
}
Also used : CexIOArchivedOrder(org.knowm.xchange.cexio.dto.trade.CexIOArchivedOrder) Order(org.knowm.xchange.dto.Order) CexIOOpenOrder(org.knowm.xchange.cexio.dto.trade.CexIOOpenOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CexIOOrder(org.knowm.xchange.cexio.dto.trade.CexIOOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) CexIOOpenOrder(org.knowm.xchange.cexio.dto.trade.CexIOOpenOrder) ArrayList(java.util.ArrayList)

Example 4 with CexIOOrder

use of org.knowm.xchange.cexio.dto.trade.CexIOOrder in project XChange by knowm.

the class CexIOAdapters method adaptOrder.

public static LimitOrder adaptOrder(CexIOFullOrder cexIOOrder) {
    OrderType orderType = cexIOOrder.type.equals("sell") ? OrderType.ASK : OrderType.BID;
    BigDecimal originalAmount = new BigDecimal(cexIOOrder.amount);
    CurrencyPair currencyPair = new CurrencyPair(cexIOOrder.symbol1, cexIOOrder.symbol2);
    Date timestamp = new Date(cexIOOrder.time);
    BigDecimal limitPrice = new BigDecimal(cexIOOrder.price);
    Order.OrderStatus status = adaptOrderStatus(cexIOOrder);
    BigDecimal cumulativeAmount = null;
    if (cexIOOrder.remains != null) {
        BigDecimal remains = new BigDecimal(cexIOOrder.remains);
        cumulativeAmount = originalAmount.subtract(remains);
    }
    BigDecimal totalAmountMaker = cexIOOrder.totalAmountMaker != null ? new BigDecimal(cexIOOrder.totalAmountMaker) : BigDecimal.ZERO;
    BigDecimal totalAmountTaker = cexIOOrder.totalAmountTaker != null ? new BigDecimal(cexIOOrder.totalAmountTaker) : BigDecimal.ZERO;
    BigDecimal tradedAmount = totalAmountMaker.add(totalAmountTaker);
    BigDecimal averagePrice = null;
    if (cumulativeAmount != null && tradedAmount.compareTo(BigDecimal.ZERO) > 0) {
        averagePrice = tradedAmount.divide(cumulativeAmount, 2, RoundingMode.HALF_UP);
    }
    BigDecimal feeMaker = cexIOOrder.feeMaker != null ? new BigDecimal(cexIOOrder.feeMaker) : BigDecimal.ZERO;
    BigDecimal feeTaker = cexIOOrder.feeTaker != null ? new BigDecimal(cexIOOrder.feeTaker) : BigDecimal.ZERO;
    BigDecimal fee = feeMaker.add(feeTaker);
    return new LimitOrder(orderType, originalAmount, currencyPair, cexIOOrder.orderId, timestamp, limitPrice, averagePrice, cumulativeAmount, fee.compareTo(BigDecimal.ZERO) > 0 ? fee : null, status);
}
Also used : CexIOArchivedOrder(org.knowm.xchange.cexio.dto.trade.CexIOArchivedOrder) Order(org.knowm.xchange.dto.Order) CexIOFullOrder(org.knowm.xchange.cexio.dto.trade.CexIOFullOrder) CexIOOpenOrder(org.knowm.xchange.cexio.dto.trade.CexIOOpenOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CexIOOrder(org.knowm.xchange.cexio.dto.trade.CexIOOrder) OrderType(org.knowm.xchange.dto.Order.OrderType) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 5 with CexIOOrder

use of org.knowm.xchange.cexio.dto.trade.CexIOOrder in project XChange by knowm.

the class TradeDemo method raw.

private static void raw(CexIOTradeServiceRaw tradeService) throws IOException {
    List<CexIOOrder> openOrders = tradeService.getCexIOOpenOrders(new CurrencyPair("NMC", "BTC"));
    System.out.println(openOrders);
}
Also used : CexIOOrder(org.knowm.xchange.cexio.dto.trade.CexIOOrder) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

CexIOOrder (org.knowm.xchange.cexio.dto.trade.CexIOOrder)5 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)4 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)4 CexIOArchivedOrder (org.knowm.xchange.cexio.dto.trade.CexIOArchivedOrder)3 CexIOOpenOrder (org.knowm.xchange.cexio.dto.trade.CexIOOpenOrder)3 Order (org.knowm.xchange.dto.Order)3 OrderType (org.knowm.xchange.dto.Order.OrderType)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CexIOFullOrder (org.knowm.xchange.cexio.dto.trade.CexIOFullOrder)2 InvalidFormatException (com.fasterxml.jackson.databind.exc.InvalidFormatException)1 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)1 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)1 DateUtils.fromISODateString (org.knowm.xchange.utils.DateUtils.fromISODateString)1