Search in sources :

Example 26 with LimitOrder

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

the class TradeServiceIntegration method testPlaceTestOrderLimitOrderShouldNotThrowAnyException.

@Test
public void testPlaceTestOrderLimitOrderShouldNotThrowAnyException() throws IOException {
    final LimitOrder limitOrder = sampleLimitOrder();
    tradeService.placeTestOrder(LIMIT, limitOrder, limitOrder.getLimitPrice(), null);
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Test(org.junit.Test)

Example 27 with LimitOrder

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

the class CCEXAdapters method adaptOpenOrder.

public static LimitOrder adaptOpenOrder(CCEXOpenorder cCEXOpenOrder) {
    OrderType type = cCEXOpenOrder.getOrderType().equalsIgnoreCase("LIMIT_SELL") ? OrderType.ASK : OrderType.BID;
    String[] currencies = cCEXOpenOrder.getExchange().split("-");
    CurrencyPair pair = new CurrencyPair(currencies[1], currencies[0]);
    return new LimitOrder(type, cCEXOpenOrder.getQuantityRemaining(), pair, cCEXOpenOrder.getOrderUuid(), null, cCEXOpenOrder.getLimit());
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 28 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder 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 29 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder 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 30 with LimitOrder

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

the class CryptopiaAdapters method adaptOrderBook.

/**
 * Adapts a CryptopiaOrderBook to an OrderBook Object
 *
 * @param cryptopiaOrderBook The exchange specific order book
 * @param currencyPair (e.g. BTC/USD)
 * @return The XChange OrderBook
 */
public static OrderBook adaptOrderBook(CryptopiaOrderBook cryptopiaOrderBook, CurrencyPair currencyPair) {
    List<LimitOrder> asks = createOrders(currencyPair, Order.OrderType.ASK, cryptopiaOrderBook.getAsks());
    List<LimitOrder> bids = createOrders(currencyPair, Order.OrderType.BID, cryptopiaOrderBook.getBids());
    return new OrderBook(new Date(), asks, bids);
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) CryptopiaOrderBook(org.knowm.xchange.cryptopia.dto.marketdata.CryptopiaOrderBook) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date)

Aggregations

LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)337 BigDecimal (java.math.BigDecimal)188 Test (org.junit.Test)122 Date (java.util.Date)110 ArrayList (java.util.ArrayList)95 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)90 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)89 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)77 Order (org.knowm.xchange.dto.Order)50 OrderType (org.knowm.xchange.dto.Order.OrderType)39 Exchange (org.knowm.xchange.Exchange)31 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)29 List (java.util.List)28 TradeService (org.knowm.xchange.service.trade.TradeService)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 IOException (java.io.IOException)20 Collectors (java.util.stream.Collectors)20 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)17 InputStream (java.io.InputStream)15 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)15