Search in sources :

Example 1 with KrakenOrderDescription

use of org.knowm.xchange.kraken.dto.trade.KrakenOrderDescription 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)

Example 2 with KrakenOrderDescription

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

the class KrakenAdapters method adaptOpenOrders.

public static OpenOrders adaptOpenOrders(Map<String, KrakenOrder> krakenOrders) {
    List<LimitOrder> limitOrders = new ArrayList<>();
    for (Entry<String, KrakenOrder> krakenOrderEntry : krakenOrders.entrySet()) {
        KrakenOrder krakenOrder = krakenOrderEntry.getValue();
        KrakenOrderDescription orderDescription = krakenOrder.getOrderDescription();
        if (!"limit".equals(orderDescription.getOrderType().toString())) {
            // ignore anything but a plain limit order for now
            continue;
        }
        limitOrders.add((LimitOrder) adaptOrder(krakenOrderEntry.getKey(), krakenOrder));
    }
    return new OpenOrders(limitOrders);
}
Also used : ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) KrakenOrderDescription(org.knowm.xchange.kraken.dto.trade.KrakenOrderDescription)

Example 3 with KrakenOrderDescription

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

the class KrakenUtils method filterOpenOrdersByCurrencyPair.

public static Map<String, KrakenOrder> filterOpenOrdersByCurrencyPair(Map<String, KrakenOrder> krakenOrders, CurrencyPair currencyPair) {
    Map<String, KrakenOrder> filteredKrakenOrders = new HashMap<>();
    for (Map.Entry<String, KrakenOrder> krakenOrderEntry : krakenOrders.entrySet()) {
        KrakenOrder krakenOrder = krakenOrderEntry.getValue();
        KrakenOrderDescription orderDescription = krakenOrder.getOrderDescription();
        if (currencyPair != null && currencyPair.equals(KrakenAdapters.adaptCurrencyPair(orderDescription.getAssetPair()))) {
            filteredKrakenOrders.put(krakenOrderEntry.getKey(), krakenOrder);
        }
    }
    return filteredKrakenOrders;
}
Also used : HashMap(java.util.HashMap) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) Map(java.util.Map) HashMap(java.util.HashMap) KrakenOrderDescription(org.knowm.xchange.kraken.dto.trade.KrakenOrderDescription)

Aggregations

KrakenOrder (org.knowm.xchange.kraken.dto.trade.KrakenOrder)3 KrakenOrderDescription (org.knowm.xchange.kraken.dto.trade.KrakenOrderDescription)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)1 KrakenOpenOrdersResult (org.knowm.xchange.kraken.dto.trade.results.KrakenOpenOrdersResult)1