Search in sources :

Example 21 with OpenOrders

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

the class HuobiAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(HuobiOrder[] openOrders) {
    OpenOrders orders = adaptOpenOrders(openOrders);
    List<UserTrade> trades = new ArrayList<>();
    for (LimitOrder order : orders.getOpenOrders()) {
        trades.add(adaptTrade(order));
    }
    return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Example 22 with OpenOrders

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

the class BitfinexStreamingAdapters method adaptOrder.

static Order adaptOrder(BitfinexWebSocketAuthOrder authOrder) {
    BitfinexOrderStatusResponse[] orderStatus = { adaptOrderToRestResponse(authOrder) };
    OpenOrders orders = BitfinexAdapters.adaptOrders(orderStatus);
    if (orders.getOpenOrders().isEmpty()) {
        if (orders.getHiddenOrders().isEmpty()) {
            throw new IllegalStateException("No order in message");
        }
        return orders.getHiddenOrders().get(0);
    }
    return orders.getOpenOrders().get(0);
}
Also used : OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse)

Example 23 with OpenOrders

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

the class TradeServiceTest method openOrdersTest.

@Test
public void openOrdersTest() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonRoot = mapper.readTree(this.getClass().getResource("/" + WIREMOCK_FILES_PATH + "/" + OPENORDERS_FILE_NAME));
    stubFor(get(urlPathEqualTo("/v3/orders/open")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("openOrders.json")));
    OpenOrders openOrders = tradeService.getOpenOrders();
    assertThat(openOrders).isNotNull();
    assertThat(openOrders.getOpenOrders()).hasSize(jsonRoot.size());
    LimitOrder firstOrder = openOrders.getOpenOrders().get(0);
    assertThat(firstOrder).isNotNull();
    assertThat(firstOrder.getOriginalAmount()).isNotNull().isPositive();
    assertThat(firstOrder.getId()).isNotBlank();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 24 with OpenOrders

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

the class Bl3pAdapters method adaptOpenOrders.

public static OpenOrders adaptOpenOrders(CurrencyPair currencyPair, Bl3pOpenOrders.Bl3pOpenOrder[] bl3pOrders) {
    List<LimitOrder> result = new ArrayList<>(bl3pOrders.length);
    for (Bl3pOpenOrders.Bl3pOpenOrder bl3pOrder : bl3pOrders) {
        Order.OrderType orderType = Bl3pUtils.fromBl3pOrderType(bl3pOrder.getStatus());
        BigDecimal limitPrice = bl3pOrder.getPrice().value;
        BigDecimal originalAmount = bl3pOrder.getAmountFunds().value;
        BigDecimal executedAmount = bl3pOrder.getAmountExecuted().value;
        BigDecimal remainingAmount = originalAmount.subtract(executedAmount);
        result.add(new LimitOrder.Builder(orderType, currencyPair).cumulativeAmount(executedAmount).id("" + bl3pOrder.getOrderId()).limitPrice(limitPrice).originalAmount(originalAmount).remainingAmount(remainingAmount).timestamp(bl3pOrder.getTimestamp()).build());
    }
    return new OpenOrders(result);
}
Also used : Bl3pGetOrder(org.knowm.xchange.bl3p.dto.trade.Bl3pGetOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Bl3pOpenOrders(org.knowm.xchange.bl3p.dto.trade.Bl3pOpenOrders) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BigDecimal(java.math.BigDecimal) Bl3pOpenOrders(org.knowm.xchange.bl3p.dto.trade.Bl3pOpenOrders)

Example 25 with OpenOrders

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

the class GeminiAdaptersTest method testAdaptOrdersToOpenOrdersFiltersByCurrencyPair.

@Test
public void testAdaptOrdersToOpenOrdersFiltersByCurrencyPair() {
    GeminiOrderStatusResponse[] responsesToRetain = ArrayUtils.addAll(initOrderStatusResponses(SYMBOL), initOrderStatusResponses(SYMBOL));
    GeminiOrderStatusResponse[] responses = ArrayUtils.addAll(initOrderStatusResponses("ETHBTC"), responsesToRetain);
    OpenOrders orders = GeminiAdapters.adaptOrders(responses, CurrencyPair.BTC_USD);
    assertEquals(orders.getOpenOrders().size(), responsesToRetain.length);
    for (int i = 0; i < responsesToRetain.length; i++) {
        LimitOrder order = orders.getOpenOrders().get(i);
        long expectedTimestampMillis = new BigDecimal(responsesToRetain[i].getTimestamp()).multiply(new BigDecimal(1000L)).longValue();
        Order.OrderType expectedOrderType = responsesToRetain[i].getSide().equalsIgnoreCase("buy") ? Order.OrderType.BID : Order.OrderType.ASK;
        assertEquals(String.valueOf(responsesToRetain[i].getId()), order.getId());
        assertEquals(responsesToRetain[i].getOriginalAmount(), order.getOriginalAmount());
        assertEquals(responsesToRetain[i].getRemainingAmount(), order.getRemainingAmount());
        assertEquals(responsesToRetain[i].getExecutedAmount(), order.getOriginalAmount().subtract(order.getRemainingAmount()));
        assertEquals(GeminiAdapters.adaptCurrencyPair(SYMBOL), order.getInstrument());
        assertEquals(expectedOrderType, order.getType());
        assertEquals(expectedTimestampMillis, order.getTimestamp().getTime());
        assertEquals(responsesToRetain[i].getPrice(), order.getLimitPrice());
    }
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) OrderType(org.knowm.xchange.dto.Order.OrderType) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Aggregations

OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)117 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)79 Test (org.junit.Test)40 BigDecimal (java.math.BigDecimal)36 ArrayList (java.util.ArrayList)33 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)31 TradeService (org.knowm.xchange.service.trade.TradeService)26 Date (java.util.Date)23 Order (org.knowm.xchange.dto.Order)21 OrderType (org.knowm.xchange.dto.Order.OrderType)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)15 UserTrades (org.knowm.xchange.dto.trade.UserTrades)14 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)14 Exchange (org.knowm.xchange.Exchange)13 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)12 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)10 InputStream (java.io.InputStream)9 List (java.util.List)9 StopOrder (org.knowm.xchange.dto.trade.StopOrder)8