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