Search in sources :

Example 26 with TradeService

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);
}
Also used : TradeService(org.knowm.xchange.service.trade.TradeService) HuobiAccountService(org.knowm.xchange.huobi.service.HuobiAccountService) HuobiAccount(org.knowm.xchange.huobi.dto.account.HuobiAccount) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 27 with TradeService

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();
    }
}
Also used : Exchange(org.knowm.xchange.Exchange) EXXExchange(org.knowm.xchange.exx.EXXExchange) EXXCancelOrderByCurrencyPair(org.knowm.xchange.exx.dto.params.EXXCancelOrderByCurrencyPair) TradeService(org.knowm.xchange.service.trade.TradeService) IOException(java.io.IOException)

Example 28 with TradeService

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();
    }
}
Also used : Exchange(org.knowm.xchange.Exchange) EXXExchange(org.knowm.xchange.exx.EXXExchange) TradeService(org.knowm.xchange.service.trade.TradeService) IOException(java.io.IOException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal)

Example 29 with TradeService

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);
    }
}
Also used : CobinhoodTradeService(org.knowm.xchange.cobinhood.service.CobinhoodTradeService) TradeService(org.knowm.xchange.service.trade.TradeService) CobinhoodOpenOrdersParams(org.knowm.xchange.cobinhood.dto.trading.CobinhoodOpenOrdersParams) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 30 with TradeService

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);
}
Also used : Exchange(org.knowm.xchange.Exchange) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeService(org.knowm.xchange.service.trade.TradeService) BTCMarketsTradeService(org.knowm.xchange.btcmarkets.service.BTCMarketsTradeService) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) BTCMarketsTradeService(org.knowm.xchange.btcmarkets.service.BTCMarketsTradeService)

Aggregations

TradeService (org.knowm.xchange.service.trade.TradeService)98 Exchange (org.knowm.xchange.Exchange)65 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)29 BigDecimal (java.math.BigDecimal)28 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)22 Test (org.junit.Test)19 IOException (java.io.IOException)16 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)14 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)14 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)11 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)9 UserTrades (org.knowm.xchange.dto.trade.UserTrades)8 CoinsuperExchange (org.knowm.xchange.coinsuper.CoinsuperExchange)7 Order (org.knowm.xchange.dto.Order)7 Date (java.util.Date)6 OrderType (org.knowm.xchange.dto.Order.OrderType)5 Trades (org.knowm.xchange.dto.marketdata.Trades)5 DVChainExchange (org.knowm.xchange.dvchain.DVChainExchange)5 OpenOrdersParams (org.knowm.xchange.service.trade.params.orders.OpenOrdersParams)5 UserTrade (org.knowm.xchange.dto.trade.UserTrade)4