Search in sources :

Example 26 with OpenOrders

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);
}
Also used : OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) Test(org.junit.Test)

Example 27 with OpenOrders

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);
}
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 28 with OpenOrders

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);
}
Also used : InputStream(java.io.InputStream) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) RippleLimitOrder(org.knowm.xchange.ripple.dto.trade.RippleLimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RippleAccountOrders(org.knowm.xchange.ripple.dto.trade.RippleAccountOrders) RippleLimitOrder(org.knowm.xchange.ripple.dto.trade.RippleLimitOrder) Test(org.junit.Test)

Example 29 with OpenOrders

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();
}
Also used : BitcoindeMyOrdersWrapper(org.knowm.xchange.bitcoinde.v4.dto.trade.BitcoindeMyOrdersWrapper) BitcoindeOrderFlagsOrderRequirements(org.knowm.xchange.bitcoinde.v4.dto.BitcoindeOrderFlagsOrderRequirements) InputStream(java.io.InputStream) BitcoindeOrderFlagsOrderQuantities(org.knowm.xchange.bitcoinde.v4.dto.BitcoindeOrderFlagsOrderQuantities) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 30 with OpenOrders

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));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) JacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory) CoinbaseProOrder(org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

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