use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class GeminiTradeServiceTest method openOrdersByCurrencyPairTest.
@Test
public void openOrdersByCurrencyPairTest() throws Exception {
stubFor(post(urlPathEqualTo("/v1/orders")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile(ORDERS_FILE_NAME)));
DefaultOpenOrdersParamCurrencyPair defaultOpenOrdersParamCurrencyPair = new DefaultOpenOrdersParamCurrencyPair(CurrencyPair.BTC_USD);
OpenOrders openOrders = classUnderTest.getOpenOrders(defaultOpenOrdersParamCurrencyPair);
assertThat(openOrders).isNotNull();
assertThat(openOrders.getOpenOrders().size()).isEqualTo(1);
LimitOrder firstOrder = openOrders.getOpenOrders().get(0);
assertThat(firstOrder).isNotNull();
assertThat(firstOrder.getOriginalAmount()).isNotNull().isPositive();
assertThat(firstOrder.getId()).isNotBlank();
assertThat(firstOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USD);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class GeminiTradeServiceTest method ordersTest.
@Test
public void ordersTest() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
JsonNode jsonRoot = mapper.readTree(this.getClass().getResource("/" + WIREMOCK_FILES_PATH + "/" + ORDERS_FILE_NAME));
stubFor(post(urlPathEqualTo("/v1/orders")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile(ORDERS_FILE_NAME)));
OpenOrders openOrders = classUnderTest.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();
assertThat(firstOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USD);
LimitOrder secondOrder = openOrders.getOpenOrders().get(1);
assertThat(secondOrder).isNotNull();
assertThat(secondOrder.getOriginalAmount()).isNotNull().isPositive();
assertThat(secondOrder.getId()).isNotBlank();
assertThat(secondOrder.getInstrument()).isEqualTo(CurrencyPair.LTC_BTC);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class RippleAdaptersTest method adaptOpenOrdersTest.
@Test
public void adaptOpenOrdersTest() throws JsonParseException, JsonMappingException, IOException {
final RippleExchange exchange = new RippleExchange();
final int roundingScale = exchange.getRoundingScale();
// Read in the JSON from the example resources
final InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/ripple/dto/trade/example-account-orders.json");
final ObjectMapper mapper = new ObjectMapper();
final RippleAccountOrders response = mapper.readValue(is, RippleAccountOrders.class);
// Convert to XChange orders
final OpenOrders orders = RippleAdapters.adaptOpenOrders(response, roundingScale);
assertThat(orders.getOpenOrders()).hasSize(12);
final LimitOrder firstOrder = orders.getOpenOrders().get(0);
assertThat(firstOrder).isInstanceOf(RippleLimitOrder.class);
assertThat(firstOrder.getCurrencyPair()).isEqualTo(CurrencyPair.XRP_BTC);
assertThat(((RippleLimitOrder) firstOrder).getCounterCounterparty()).isEqualTo("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B");
assertThat(firstOrder.getId()).isEqualTo("5");
assertThat(firstOrder.getLimitPrice()).isEqualTo("0.00003226");
assertThat(firstOrder.getTimestamp()).isNull();
assertThat(firstOrder.getOriginalAmount()).isEqualTo("1");
assertThat(firstOrder.getType()).isEqualTo(OrderType.BID);
final LimitOrder secondOrder = orders.getOpenOrders().get(1);
assertThat(secondOrder).isInstanceOf(RippleLimitOrder.class);
assertThat(secondOrder.getCurrencyPair()).isEqualTo(CurrencyPair.XRP_BTC);
assertThat(((RippleLimitOrder) secondOrder).getCounterCounterparty()).isEqualTo("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B");
assertThat(secondOrder.getId()).isEqualTo("7");
// Price = 15159.38551342023 / 123.123456
assertThat(secondOrder.getLimitPrice()).isEqualTo("123.12345677999998635515884154518859509596611713043533");
assertThat(secondOrder.getTimestamp()).isNull();
assertThat(secondOrder.getOriginalAmount()).isEqualTo("123.123456");
assertThat(secondOrder.getType()).isEqualTo(OrderType.ASK);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class BitcoindeAdaptersTest method testOpenOrdersAdapter.
@Test
public void testOpenOrdersAdapter() throws IOException {
final InputStream is = BitcoindeAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/bitcoinde/v4/dto/my_orders.json");
// Use Jackson to parse it
final ObjectMapper mapper = new ObjectMapper();
BitcoindeMyOrdersWrapper bitcoindeOpenOrdersWrapper = mapper.readValue(is, BitcoindeMyOrdersWrapper.class);
final OpenOrders openOrders = BitcoindeAdapters.adaptOpenOrders(bitcoindeOpenOrdersWrapper);
// Make sure trade values are correct
assertThat(openOrders.getOpenOrders()).isNotNull();
assertThat(openOrders.getOpenOrders().size()).isEqualTo(1);
LimitOrder order = openOrders.getOpenOrders().get(0);
assertThat(order.getId()).isEqualTo("VNSP86");
assertThat(order.getType()).isEqualTo(OrderType.BID);
assertThat(order.getInstrument()).isEqualTo(CurrencyPair.BTC_EUR);
assertThat(order.getTimestamp()).isEqualTo("2018-01-25T17:35:19+01:00");
assertThat(order.getOriginalAmount()).isEqualByComparingTo("0.01");
assertThat(order.getLimitPrice()).isEqualByComparingTo("6000");
assertThat(order.getStatus()).isEqualTo(OrderStatus.NEW);
assertThat(order.getOrderFlags()).containsOnly(new BitcoindeOrderFlagsOrderQuantities(new BigDecimal("0.01"), new BigDecimal("0.01"), new BigDecimal("60"), new BigDecimal("60")), new BitcoindeOrderFlagsOrderRequirements(BitcoindeTrustLevel.SILVER, false, new String[] { "AT", "BE", "BG", "CH", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GB", "GR", "HR", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MQ", "MT", "NL", "NO", "PL", "PT", "RO", "SE", "SI", "SK" }, BitcoindePaymentOption.EXPRESS_SEPA));
assertThat(order.getAveragePrice()).isNull();
assertThat(order.getCumulativeAmount()).isNull();
assertThat(order.getFee()).isNull();
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class CoinbaseProAdaptersTest method testOrders.
@Test
public void testOrders() throws JsonParseException, JsonMappingException, IOException {
final JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
final ObjectMapper mapper = factory.createObjectMapper();
InputStream is = new SequenceInputStream(new ByteArrayInputStream("[".getBytes(StandardCharsets.UTF_8)), new SequenceInputStream(getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/order/example-limit-order-pending.json"), new SequenceInputStream(new ByteArrayInputStream(", ".getBytes(StandardCharsets.UTF_8)), new SequenceInputStream(getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/order/example-stop-order-filled.json"), new ByteArrayInputStream("]".getBytes(StandardCharsets.UTF_8))))));
final CoinbaseProOrder[] coinbaseProOrders = mapper.readValue(is, CoinbaseProOrder[].class);
OpenOrders openOrders = CoinbaseProAdapters.adaptOpenOrders(coinbaseProOrders);
assertThat(openOrders.getOpenOrders()).hasSize(1);
assertThat(openOrders.getHiddenOrders()).hasSize(1);
assertStopOrderFilled(openOrders.getHiddenOrders().get(0));
assertLimitOrderPending(openOrders.getOpenOrders().get(0));
}
Aggregations