Search in sources :

Example 11 with OrderType

use of org.knowm.xchange.dto.Order.OrderType 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 12 with OrderType

use of org.knowm.xchange.dto.Order.OrderType 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 13 with OrderType

use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.

the class CexIOAdapters method adaptTrade.

/**
 * Adapts a CexIOTrade to a Trade Object
 *
 * @param trade CexIO trade object
 * @param currencyPair trade currencies
 * @return The XChange Trade
 */
public static Trade adaptTrade(CexIOTrade trade, CurrencyPair currencyPair) {
    BigDecimal amount = trade.getAmount();
    BigDecimal price = trade.getPrice();
    Date date = DateUtils.fromMillisUtc(trade.getDate() * 1000L);
    OrderType type = trade.getType().equals(ORDER_TYPE_BUY) ? OrderType.BID : OrderType.ASK;
    return new Trade.Builder().type(type).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(date).id(String.valueOf(trade.getTid())).build();
}
Also used : CexIOTrade(org.knowm.xchange.cexio.dto.marketdata.CexIOTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 14 with OrderType

use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.

the class LimitOrderTest method testSerializeDeserialize.

@Test
public void testSerializeDeserialize() throws IOException {
    final OrderType type = OrderType.ASK;
    final BigDecimal originalAmount = new BigDecimal("100.501");
    final BigDecimal averagePrice = new BigDecimal("255.00");
    final BigDecimal cumulativeAmount = new BigDecimal("0.00");
    final CurrencyPair currencyPair = CurrencyPair.BTC_USD;
    final BigDecimal limitPrice = new BigDecimal("250.34");
    final BigDecimal fee = new BigDecimal("22.2");
    final Date timestamp = new Date();
    final String id = "id";
    final Order.OrderStatus status = Order.OrderStatus.FILLED;
    final LimitOrder original = new LimitOrder(type, originalAmount, currencyPair, id, timestamp, limitPrice, averagePrice, cumulativeAmount, fee, status);
    original.addOrderFlag(TestFlags.TEST1);
    original.addOrderFlag(TestFlags.TEST3);
    LimitOrder jsonCopy = ObjectMapperHelper.viaJSON(original);
    assertThat(jsonCopy).isEqualToIgnoringGivenFields(original, "cumulativeAmount");
    assertTrue(jsonCopy.getCumulativeAmount().compareTo(original.getCumulativeAmount()) == 0);
}
Also used : Order(org.knowm.xchange.dto.Order) OrderType(org.knowm.xchange.dto.Order.OrderType) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 15 with OrderType

use of org.knowm.xchange.dto.Order.OrderType in project XChange by knowm.

the class LimitOrderTest method testBuilder.

@Test
public void testBuilder() {
    final OrderType type = OrderType.BID;
    final BigDecimal originalAmount = new BigDecimal("99.401");
    final BigDecimal averagePrice = new BigDecimal("255.00");
    final BigDecimal cumulativeAmount = new BigDecimal("0.00");
    final CurrencyPair currencyPair = CurrencyPair.LTC_BTC;
    final BigDecimal limitPrice = new BigDecimal("251.64");
    final BigDecimal fee = new BigDecimal("22.2");
    final String userReference = "123";
    final Date timestamp = new Date();
    final String id = "id";
    final Order.OrderStatus status = Order.OrderStatus.FILLED;
    final LimitOrder copy = new LimitOrder.Builder(type, currencyPair).originalAmount(originalAmount).averagePrice(averagePrice).cumulativeAmount(cumulativeAmount).limitPrice(limitPrice).orderStatus(status).timestamp(timestamp).id(id).flag(TestFlags.TEST1).fee(fee).userReference(userReference).build();
    assertThat(copy.getType()).isEqualTo(type);
    assertThat(copy.getOriginalAmount()).isEqualTo(originalAmount);
    assertThat(copy.getAveragePrice()).isEqualTo(averagePrice);
    assertThat(copy.getCumulativeAmount()).isEqualTo(cumulativeAmount);
    assertThat(copy.getCurrencyPair()).isEqualTo(currencyPair);
    assertThat(copy.getLimitPrice()).isEqualTo(limitPrice);
    assertThat(copy.getTimestamp()).isEqualTo(timestamp);
    assertThat(copy.getId()).isEqualTo(id);
    assertThat(copy.getOrderFlags()).hasSize(1);
    assertThat(copy.getOrderFlags()).containsExactly(TestFlags.TEST1);
    assertThat(copy.hasFlag(TestFlags.TEST1));
    assertThat(copy.getStatus()).isEqualTo(status);
    assertThat(copy.getFee()).isEqualTo(fee);
    assertThat(copy.getUserReference()).isEqualTo(userReference);
}
Also used : Order(org.knowm.xchange.dto.Order) OrderType(org.knowm.xchange.dto.Order.OrderType) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

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