com.xeiam.xchange.examples.kraken.trade.KrakenTradeRawSpecificDemo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xchange-examples Show documentation
Show all versions of xchange-examples Show documentation
Provides a set of examples that demonstrate how to use XChange in client applications
The newest version!
package com.xeiam.xchange.examples.kraken.trade;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Set;
import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.examples.kraken.KrakenExampleUtils;
import com.xeiam.xchange.kraken.dto.trade.KrakenOpenPosition;
import com.xeiam.xchange.kraken.dto.trade.KrakenOrder;
import com.xeiam.xchange.kraken.dto.trade.KrakenOrderResponse;
import com.xeiam.xchange.kraken.dto.trade.KrakenOrderType;
import com.xeiam.xchange.kraken.dto.trade.KrakenStandardOrder;
import com.xeiam.xchange.kraken.dto.trade.KrakenTrade;
import com.xeiam.xchange.kraken.dto.trade.KrakenType;
import com.xeiam.xchange.kraken.service.polling.KrakenTradeServiceRaw;
public class KrakenTradeRawSpecificDemo {
public static void main(String[] args) throws IOException {
Exchange krakenExchange = KrakenExampleUtils.createTestExchange();
// Interested in the private trading functionality (authentication)
KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getPollingTradeService();
KrakenStandardOrder order = // stop at -5% loss, take profit at +$10 price increase.
KrakenStandardOrder.getLimitOrderBuilder(CurrencyPair.BTC_USD, KrakenType.BUY, "100.00", new BigDecimal("2.12345678"))
.withCloseOrder(KrakenOrderType.STOP_LOSS_PROFIT, "#5%", "#10").withValidateOnly(true) // validate only for demo purposes
.buildOrder();
KrakenOrderResponse orderResponse = tradeService.placeKrakenOrder(order);
System.out.println(orderResponse);
Map openOrders = tradeService.getKrakenOpenOrders();
System.out.println(openOrders);
limitRate();
Map closedOrders = tradeService.getKrakenClosedOrders();
System.out.println(closedOrders);
Set closedOrderIds = closedOrders.keySet();
System.out.println(tradeService.queryKrakenOrders(closedOrderIds.toArray(new String[closedOrderIds.size()])));
Map trades = tradeService.getKrakenTradeHistory();
System.out.println(trades);
Set tradeIds = trades.keySet();
System.out.println(tradeService.queryKrakenTrades(tradeIds.toArray(new String[tradeIds.size()])));
Map openPositions = tradeService.getOpenPositions();
System.out.println(openPositions);
}
private static void limitRate() {
try { // respect API rate limit
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy