Search in sources :

Example 1 with BithumbOrder

use of org.knowm.xchange.bithumb.dto.account.BithumbOrder in project XChange by knowm.

the class BithumbAdapters method adaptOrder.

public static LimitOrder adaptOrder(BithumbOrder order) {
    final CurrencyPair currencyPair = adaptCurrencyPair(order.getOrderCurrency(), order.getPaymentCurrency());
    final Order.OrderType orderType = adaptOrderType(order.getType());
    Order.OrderStatus status = Order.OrderStatus.UNKNOWN;
    if (order.getUnitsRemaining().compareTo(order.getUnits()) == 0) {
        status = Order.OrderStatus.NEW;
    } else if (order.getUnitsRemaining().compareTo(BigDecimal.ZERO) == 0) {
        status = Order.OrderStatus.FILLED;
    } else {
        status = Order.OrderStatus.PARTIALLY_FILLED;
    }
    return new LimitOrder.Builder(orderType, currencyPair).id(String.valueOf(order.getOrderId())).limitPrice(order.getPrice()).originalAmount(order.getUnits()).remainingAmount(order.getUnitsRemaining()).orderStatus(status).timestamp(new Date(order.getOrderDate() / 1000L)).build();
}
Also used : BithumbOrder(org.knowm.xchange.bithumb.dto.account.BithumbOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with BithumbOrder

use of org.knowm.xchange.bithumb.dto.account.BithumbOrder in project XChange by knowm.

the class BithumbAdaptersTest method testAdaptOpenOrder.

@Test
public void testAdaptOpenOrder() throws IOException {
    // given
    InputStream is = BithumbAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/bithumb/dto/account/example-order.json");
    final BithumbResponse<List<BithumbOrder>> bithumbOrderResponse = mapper.readValue(is, new TypeReference<BithumbResponse<List<BithumbOrder>>>() {
    });
    // when
    final LimitOrder limitOrder = BithumbAdapters.adaptOrder(bithumbOrderResponse.getData().stream().findFirst().get());
    // then
    assertThat(limitOrder.getLimitPrice()).isEqualTo(BigDecimal.valueOf(501000));
    assertThat(limitOrder.getType()).isEqualTo(Order.OrderType.BID);
    assertThat(limitOrder.getOriginalAmount()).isEqualTo(BigDecimal.valueOf(5.0));
    assertThat(limitOrder.getCumulativeAmount()).isEqualTo(BigDecimal.valueOf(0.0));
    assertThat(limitOrder.getAveragePrice()).isNull();
    assertThat(limitOrder.getCurrencyPair()).isEqualTo(new CurrencyPair(Currency.BTC, Currency.KRW));
    assertThat(limitOrder.getId()).isEqualTo("C0101000007408440032");
    assertThat(limitOrder.getTimestamp()).isNotNull();
    assertThat(limitOrder.getStatus()).isEqualTo(Order.OrderStatus.NEW);
}
Also used : BithumbResponse(org.knowm.xchange.bithumb.dto.BithumbResponse) InputStream(java.io.InputStream) BithumbOrder(org.knowm.xchange.bithumb.dto.account.BithumbOrder) List(java.util.List) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Aggregations

BithumbOrder (org.knowm.xchange.bithumb.dto.account.BithumbOrder)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 InputStream (java.io.InputStream)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1 BithumbResponse (org.knowm.xchange.bithumb.dto.BithumbResponse)1 Order (org.knowm.xchange.dto.Order)1 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)1