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