use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class CoinfloorUserTradesIntegration method fetchUserTradesTest.
@Test
public void fetchUserTradesTest() throws IOException {
final ExchangeSpecification specification = new ExchangeSpecification(CoinfloorExchange.class);
String username = System.getProperty("xchange.coinfloor.username");
String password = System.getProperty("xchange.coinfloor.password");
if (username == null || password == null) {
return;
}
specification.setUserName(username);
specification.setPassword(password);
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
TradeService service = exchange.getTradeService();
CoinfloorTradeHistoryParams params = (CoinfloorTradeHistoryParams) service.createTradeHistoryParams();
UserTrades trades = service.getTradeHistory(params);
logger.info("{}", trades);
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class CoinfloorCancelOrderIntegration method cancelOpenOrdersTest.
@Test
public void cancelOpenOrdersTest() throws IOException {
final ExchangeSpecification specification = new ExchangeSpecification(CoinfloorExchange.class);
String username = System.getProperty("xchange.coinfloor.username");
String password = System.getProperty("xchange.coinfloor.password");
if (username == null || password == null) {
return;
}
specification.setUserName(username);
specification.setPassword(password);
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
TradeService service = exchange.getTradeService();
// fetch open orders
CoinfloorOpenOrdersParams params = (CoinfloorOpenOrdersParams) service.createOpenOrdersParams();
OpenOrders openOrders = service.getOpenOrders(params);
// cancel one order
if (openOrders.getOpenOrders().size() > 0) {
LimitOrder order = openOrders.getOpenOrders().iterator().next();
boolean success = service.cancelOrder(order.getId());
logger.info("cancel of order={} success={}", order, success);
}
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class KucoinTradeHistoryDemo method main.
public static void main(String[] args) throws Exception {
Exchange exchange = KucoinExamplesUtils.getExchange();
TradeService tradeService = exchange.getTradeService();
getRecentTrades(tradeService);
// getHistoricalTrades(tradeService); // historical trades API endpoint not supported on
// Sandbox
getPagedTrades(tradeService);
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class KucoinTradeRawDemo method genericStopLimitOrder.
private static void genericStopLimitOrder(TradeService tradeService) throws Exception {
System.out.println("GENERIC STOP LIMIT ORDER...\n");
StopOrder stopOrder = new StopOrder.Builder(ORDER_TYPE, PAIR).limitPrice(STOP_LIMIT).stopPrice(STOP_PRICE).originalAmount(AMOUNT).build();
String uuid = tradeService.placeStopOrder(stopOrder);
System.out.println("Stop order successfully placed. ID=" + uuid);
// wait for order to propagate
Thread.sleep(3000);
OpenOrdersParamCurrencyPair orderParams = (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
orderParams.setCurrencyPair(PAIR);
OpenOrders openOrders = tradeService.getOpenOrders(orderParams);
Optional<? extends Order> found = openOrders.getHiddenOrders().stream().filter(o -> o.getId().equals(uuid)).findFirst();
if (!found.isPresent()) {
throw new AssertionError("Order not found on book");
}
if (!(found.get() instanceof StopOrder)) {
throw new AssertionError("Stop order not returned");
}
StopOrder returnedStopOrder = (StopOrder) found.get();
if (returnedStopOrder.getLimitPrice().compareTo(STOP_LIMIT) != 0) {
throw new AssertionError("Limit price mismatch: " + returnedStopOrder.getLimitPrice());
}
if (returnedStopOrder.getStopPrice().compareTo(STOP_PRICE) != 0) {
throw new AssertionError("Stop price mismatch: " + returnedStopOrder.getStopPrice());
}
System.out.println("Attempting to cancel order " + uuid);
boolean cancelled = tradeService.cancelOrder(uuid);
if (cancelled) {
System.out.println("Order successfully canceled.");
} else {
System.out.println("Order not successfully canceled.");
}
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class MercadoBitcoinTradeDemo method main.
public static void main(String[] args) throws IOException, InterruptedException {
Exchange mercadoBitcoin = InteractiveAuthenticatedExchange.createInstanceFromDefaultInput();
TradeService tradeService = mercadoBitcoin.getTradeService();
generic(tradeService);
raw((MercadoBitcoinTradeServiceRaw) tradeService);
}
Aggregations