Search in sources :

Example 1 with KrakenOrder

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

the class KrakenCancelOrderDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    System.out.println("Open Orders: " + tradeService.getKrakenOpenOrders());
    // place a limit buy order
    LimitOrder limitOrder = new LimitOrder((OrderType.ASK), new BigDecimal(".01"), CurrencyPair.BTC_LTC, "", null, new BigDecimal("51.25"));
    KrakenOrderResponse limitOrderReturnValue = tradeService.placeKrakenLimitOrder(limitOrder);
    System.out.println("Limit Order return value: " + limitOrderReturnValue);
    Map<String, KrakenOrder> openOrders = tradeService.getKrakenOpenOrders();
    System.out.println("Open Orders: " + openOrders);
    // Cancel the added order
    List<String> transactionIds = limitOrderReturnValue.getTransactionIds();
    if (transactionIds != null && !transactionIds.isEmpty()) {
        KrakenCancelOrderResponse cancelResult = tradeService.cancelKrakenOrder(transactionIds.get(0));
        System.out.println("Canceling returned " + cancelResult);
        System.out.println("Open Orders: " + tradeService.getKrakenOpenOrders());
    }
}
Also used : KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) KrakenCancelOrderResponse(org.knowm.xchange.kraken.dto.trade.results.KrakenCancelOrderResult.KrakenCancelOrderResponse) BigDecimal(java.math.BigDecimal)

Example 2 with KrakenOrder

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

the class KrakenOpenOrdersDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    // Interested in the private trading functionality (authentication)
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    // Get the open orders
    Map<String, KrakenOrder> openOrders = tradeService.getKrakenOpenOrders();
    System.out.println(openOrders);
}
Also used : KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder)

Example 3 with KrakenOrder

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

the class KrakenTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
    Map<String, KrakenOrder> krakenOrders = super.getKrakenOpenOrders();
    if (params != null && params instanceof OpenOrdersParamCurrencyPair) {
        OpenOrdersParamCurrencyPair openOrdersParamCurrencyPair = (OpenOrdersParamCurrencyPair) params;
        Map<String, KrakenOrder> filteredKrakenOrders = KrakenUtils.filterOpenOrdersByCurrencyPair(krakenOrders, openOrdersParamCurrencyPair.getCurrencyPair());
        return KrakenAdapters.adaptOpenOrders(filteredKrakenOrders);
    }
    return KrakenAdapters.adaptOpenOrders(krakenOrders);
}
Also used : KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)

Example 4 with KrakenOrder

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

the class KrakenUtilsTest method testFilterOpenOrdersByCurrencyPair.

@Test
public void testFilterOpenOrdersByCurrencyPair() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = KrakenAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/kraken/dto/trading/example-openorders-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    KrakenOpenOrdersResult krakenResult = mapper.readValue(is, KrakenOpenOrdersResult.class);
    Map<String, KrakenOrder> krakenOrders = KrakenUtils.filterOpenOrdersByCurrencyPair(krakenResult.getResult().getOrders(), CurrencyPair.BTC_EUR);
    OpenOrders orders = KrakenAdapters.adaptOpenOrders(krakenOrders);
    // Verify that the example data was unmarshalled correctly
    assertThat(orders.getOpenOrders()).hasSize(1);
    assertThat(orders.getOpenOrders().get(0).getId()).isEqualTo("OU5JPQ-OIDTK-QIGIGI");
    assertThat(orders.getOpenOrders().get(0).getLimitPrice()).isEqualTo("1000.000");
    assertThat(orders.getOpenOrders().get(0).getOriginalAmount()).isEqualTo("0.01000000");
    assertThat(orders.getOpenOrders().get(0).getCurrencyPair().base).isEqualTo(Currency.XBT);
    assertThat(orders.getOpenOrders().get(0).getCurrencyPair().counter).isEqualTo(Currency.EUR);
    assertThat(orders.getOpenOrders().get(0).getType()).isEqualTo(Order.OrderType.BID);
}
Also used : InputStream(java.io.InputStream) KrakenOpenOrdersResult(org.knowm.xchange.kraken.dto.trade.results.KrakenOpenOrdersResult) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with KrakenOrder

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

the class KrakenTradeJsonTest method testOrderUnmarshall.

@Test
public void testOrderUnmarshall() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = KrakenTradeJsonTest.class.getResourceAsStream("/org/knowm/xchange/kraken/dto/trading/example-openorders-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    KrakenOpenOrdersResult krakenResult = mapper.readValue(is, KrakenOpenOrdersResult.class);
    Entry<String, KrakenOrder> openOrderEntry = krakenResult.getResult().getOrders().entrySet().iterator().next();
    KrakenOrder order = openOrderEntry.getValue();
    // Verify that the example data was unmarshalled correctly
    assertThat(openOrderEntry.getKey()).isEqualTo("O767CW-TXHCL-FWZ5R2");
    assertThat(order.getOpenTimestamp()).isEqualTo(1499872460.2572);
    assertThat(order.getPrice()).isEqualTo("0.000000000");
    assertThat(order.getVolume()).isEqualTo("1000.00000000");
    assertThat(order.getVolumeExecuted()).isEqualTo("0.00000000");
    assertThat(order.getStatus()).isEqualTo(KrakenOrderStatus.OPEN);
    KrakenOrderDescription orderDescription = order.getOrderDescription();
    assertThat(orderDescription.getAssetPair()).isEqualTo("XRPXBT");
    assertThat(orderDescription.getLeverage()).isEqualTo("none");
    assertThat(orderDescription.getOrderDescription()).isEqualTo("buy 1000.00000000 XRPXBT @ limit 0.00001000");
    assertThat(orderDescription.getOrderType()).isEqualTo(KrakenOrderType.LIMIT);
    assertThat(orderDescription.getType()).isEqualTo(KrakenType.BUY);
    assertThat(orderDescription.getPrice()).isEqualTo("0.00001000");
    assertThat(orderDescription.getSecondaryPrice()).isEqualTo("0");
}
Also used : InputStream(java.io.InputStream) KrakenOpenOrdersResult(org.knowm.xchange.kraken.dto.trade.results.KrakenOpenOrdersResult) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KrakenOrderDescription(org.knowm.xchange.kraken.dto.trade.KrakenOrderDescription) Test(org.junit.Test)

Aggregations

KrakenOrder (org.knowm.xchange.kraken.dto.trade.KrakenOrder)9 KrakenOrderDescription (org.knowm.xchange.kraken.dto.trade.KrakenOrderDescription)3 KrakenTradeServiceRaw (org.knowm.xchange.kraken.service.KrakenTradeServiceRaw)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InputStream (java.io.InputStream)2 BigDecimal (java.math.BigDecimal)2 Test (org.junit.Test)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)2 KrakenOrderResponse (org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse)2 KrakenOpenOrdersResult (org.knowm.xchange.kraken.dto.trade.results.KrakenOpenOrdersResult)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SneakyThrows (lombok.SneakyThrows)1 Exchange (org.knowm.xchange.Exchange)1 KrakenOpenPosition (org.knowm.xchange.kraken.dto.trade.KrakenOpenPosition)1 KrakenTrade (org.knowm.xchange.kraken.dto.trade.KrakenTrade)1 KrakenCancelOrderResponse (org.knowm.xchange.kraken.dto.trade.results.KrakenCancelOrderResult.KrakenCancelOrderResponse)1 KrakenTradeService (org.knowm.xchange.kraken.service.KrakenTradeService)1