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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations