use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class HuobiPrivateApiIntegration method placePendingOrder.
private String placePendingOrder() throws IOException {
TradeService tradeService = exchange.getTradeService();
HuobiAccountService accountService = (HuobiAccountService) exchange.getAccountService();
HuobiAccount[] accounts = accountService.getAccounts();
LimitOrder limitOrder = new LimitOrder(OrderType.BID, new BigDecimal("0.001"), new CurrencyPair("BTC", "USDT"), String.valueOf(accounts[0].getId()), null, new BigDecimal("10000"));
return tradeService.placeLimitOrder(limitOrder);
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class TradeServiceIntegration method cancelOrder.
private static void cancelOrder() throws IOException {
Exchange exx = getExchange();
TradeService tradeService = exx.getTradeService();
try {
EXXCancelOrderByCurrencyPair exxCancelOrderByCurrencyPair = new EXXCancelOrderByCurrencyPair();
exxCancelOrderByCurrencyPair.setCurrencyPair(CurrencyPair.ETH_BTC);
exxCancelOrderByCurrencyPair.setId("634");
boolean result = tradeService.cancelOrder(exxCancelOrderByCurrencyPair);
System.out.println("cancelOrder result: " + result);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class TradeServiceIntegration method placeLimitOrder.
private static void placeLimitOrder() throws IOException {
Exchange exx = getExchange();
TradeService tradeService = exx.getTradeService();
try {
// place a limit order
LimitOrder limitOrder = new LimitOrder((OrderType.BID), new BigDecimal("1.0"), CurrencyPair.ETH_BTC, null, null, new BigDecimal("0.00050"));
String limitOrderReturnValue = tradeService.placeLimitOrder(limitOrder);
System.out.println("Order Id: " + limitOrderReturnValue);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class CobinhoodTradeDemo method generic.
public static void generic(Exchange exchange) throws IOException {
CurrencyPair pair = CurrencyPair.BTC_USDT;
TradeService tradeService = exchange.getTradeService();
// Get open orders
OpenOrders orders = tradeService.getOpenOrders(new CobinhoodOpenOrdersParams(pair));
LimitOrder order = orders.getOpenOrders().stream().collect(StreamUtils.singletonCollector());
if (order != null) {
System.out.println(order);
}
}
use of org.knowm.xchange.service.trade.TradeService in project XChange by knowm.
the class BTCMarketsTradeDemo method main.
public static void main(String[] args) throws Exception {
Exchange btcMarketsExchange = BTCMarketsExampleUtils.createTestExchange();
TradeService tradeService = btcMarketsExchange.getTradeService();
final OpenOrdersParamCurrencyPair openOrdersParams = (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
openOrdersParams.setCurrencyPair(CurrencyPair.BTC_AUD);
System.out.println("Open Orders: " + tradeService.getOpenOrders(openOrdersParams));
// Place a limit sell order at a high price
LimitOrder sellOrder = new LimitOrder((OrderType.ASK), new BigDecimal("0.003"), CurrencyPair.BTC_AUD, null, null, new BigDecimal("2000"));
String limitOrderReturnValue = tradeService.placeLimitOrder(sellOrder);
System.out.println("Limit Order return value: " + limitOrderReturnValue);
System.out.println("Waiting a while for the order to get registered...");
Thread.sleep(2000);
System.out.println("Open Orders: " + tradeService.getOpenOrders(openOrdersParams));
openOrdersParams.setCurrencyPair(CurrencyPair.LTC_BTC);
System.out.println("Open Orders for LTC/BTC: " + tradeService.getOpenOrders(openOrdersParams));
// Cancel the added order.
boolean cancelResult = tradeService.cancelOrder(limitOrderReturnValue);
System.out.println("Canceling returned " + cancelResult);
System.out.println("Open Orders: " + tradeService.getOpenOrders(openOrdersParams));
// An example of a sell market order
MarketOrder sellMarketOrder = new MarketOrder((OrderType.ASK), new BigDecimal("0.003"), CurrencyPair.BTC_AUD, null, null);
String marketSellOrderId = tradeService.placeMarketOrder(sellMarketOrder);
System.out.println("Market Order return value: " + marketSellOrderId);
// An example of a buy limit order.
LimitOrder buyOrder = new LimitOrder((OrderType.BID), new BigDecimal("0.002"), CurrencyPair.BTC_AUD, null, null, new BigDecimal("240"));
String buyLimiOrderId = tradeService.placeLimitOrder(buyOrder);
System.out.println("Limit Order return value: " + buyLimiOrderId);
// An example of a buy market order
MarketOrder buyMarketOrder = new MarketOrder((OrderType.BID), new BigDecimal("0.004"), CurrencyPair.BTC_AUD, null, null);
String buyMarketOrderId = tradeService.placeMarketOrder(buyMarketOrder);
System.out.println("Market Order return value: " + buyMarketOrderId);
// Get history of executed trades.
BTCMarketsTradeService.HistoryParams params = (BTCMarketsTradeService.HistoryParams) tradeService.createTradeHistoryParams();
params.setPageLength(10);
params.setCurrencyPair(CurrencyPair.BTC_AUD);
final UserTrades tradeHistory = tradeService.getTradeHistory(params);
System.out.println("Trade history: " + tradeHistory);
}
Aggregations