Search in sources :

Example 1 with KrakenOrderResponse

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

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

the class KrakenLimitOrderDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    OrderType orderType = (OrderType.ASK);
    BigDecimal tradeableAmount = new BigDecimal("0.01");
    BigDecimal price = new BigDecimal("65.25");
    LimitOrder limitOrder = new LimitOrder(orderType, tradeableAmount, CurrencyPair.BTC_LTC, "", null, price);
    KrakenOrderResponse orderResponse = tradeService.placeKrakenLimitOrder(limitOrder);
    System.out.println("Limit Order response: " + orderResponse);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) BigDecimal(java.math.BigDecimal)

Example 3 with KrakenOrderResponse

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

the class KrakenTradeJsonTest method testAddOrderResponseUnmarshal.

@Test
public void testAddOrderResponseUnmarshal() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = KrakenTradeJsonTest.class.getResourceAsStream("/org/knowm/xchange/kraken/dto/trading/example-addorder-response-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    KrakenOrderResult krakenResult = mapper.readValue(is, KrakenOrderResult.class);
    KrakenOrderResponse orderResponse = krakenResult.getResult();
    assertThat(orderResponse.getDescription().getOrderDescription()).isEqualTo("sell 0.01000000 XBTLTC @ limit 45.25000");
    assertThat(orderResponse.getTransactionIds().get(0)).isEqualTo("OWQJ5O-ZWYC7-5R7POQ");
}
Also used : InputStream(java.io.InputStream) KrakenOrderResult(org.knowm.xchange.kraken.dto.trade.results.KrakenOrderResult) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with KrakenOrderResponse

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

the class KrakenTradeRawSpecificDemo method main.

public static void main(String[] args) throws IOException {
    Exchange krakenExchange = KrakenExampleUtils.createTestExchange();
    // Interested in the private trading functionality (authentication)
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    // stop at -5% loss, take profit at +$10 price increase.
    KrakenStandardOrder order = KrakenStandardOrder.getLimitOrderBuilder(CurrencyPair.BTC_USD, KrakenType.BUY, "100.00", new BigDecimal("2.12345678")).withCloseOrder(KrakenOrderType.STOP_LOSS_PROFIT, "#5%", "#10").withValidateOnly(// validate only for demo purposes
    true).buildOrder();
    KrakenOrderResponse orderResponse = tradeService.placeKrakenOrder(order);
    System.out.println(orderResponse);
    Map<String, KrakenOrder> openOrders = tradeService.getKrakenOpenOrders();
    System.out.println(openOrders);
    limitRate();
    Map<String, KrakenOrder> closedOrders = tradeService.getKrakenClosedOrders();
    System.out.println(closedOrders);
    Set<String> closedOrderIds = closedOrders.keySet();
    System.out.println(tradeService.queryKrakenOrders(closedOrderIds.toArray(new String[closedOrderIds.size()])));
    Map<String, KrakenTrade> trades = tradeService.getKrakenTradeHistory().getTrades();
    System.out.println(trades);
    Set<String> tradeIds = trades.keySet();
    System.out.println(tradeService.queryKrakenTrades(tradeIds.toArray(new String[tradeIds.size()])));
    Map<String, KrakenOpenPosition> openPositions = tradeService.getKrakenOpenPositions();
    System.out.println(openPositions);
}
Also used : KrakenTrade(org.knowm.xchange.kraken.dto.trade.KrakenTrade) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) KrakenOrder(org.knowm.xchange.kraken.dto.trade.KrakenOrder) BigDecimal(java.math.BigDecimal) Exchange(org.knowm.xchange.Exchange) KrakenOpenPosition(org.knowm.xchange.kraken.dto.trade.KrakenOpenPosition) KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw)

Example 5 with KrakenOrderResponse

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

the class KrakenMarketOrderDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    // Interested in the private trading functionality (authentication)
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    // place a marketOrder with volume 0.01
    OrderType orderType = (OrderType.BID);
    BigDecimal tradeableAmount = new BigDecimal("0.01");
    MarketOrder marketOrder = new MarketOrder(orderType, tradeableAmount, CurrencyPair.BTC_EUR);
    KrakenOrderResponse orderID = tradeService.placeKrakenMarketOrder(marketOrder);
    System.out.println("Market Order ID: " + orderID);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) BigDecimal(java.math.BigDecimal)

Aggregations

KrakenOrderResponse (org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse)6 BigDecimal (java.math.BigDecimal)5 KrakenTradeServiceRaw (org.knowm.xchange.kraken.service.KrakenTradeServiceRaw)4 OrderType (org.knowm.xchange.dto.Order.OrderType)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 KrakenOrder (org.knowm.xchange.kraken.dto.trade.KrakenOrder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 RoundingMode (java.math.RoundingMode)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Monetary (javax.money.Monetary)1 SneakyThrows (lombok.SneakyThrows)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Test (org.junit.Test)1 Exchange (org.knowm.xchange.Exchange)1 Currency (org.knowm.xchange.currency.Currency)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1