Search in sources :

Example 1 with DefaultTradeHistoryParamCurrencyPair

use of org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair in project XChange by knowm.

the class GateioTradeDemo method generic.

private static void generic(TradeService tradeService) throws IOException, InterruptedException {
    LimitOrder limitOrder = new LimitOrder(OrderType.ASK, new BigDecimal("0.384"), CurrencyPair.LTC_BTC, "", null, new BigDecimal("0.0265"));
    String orderId = tradeService.placeLimitOrder(limitOrder);
    System.out.println(// Returned order id is currently broken for Gateio, rely on open orders instead//
    orderId);
    // for demo :(
    // wait for Gateio's back-end to propagate the order
    Thread.sleep(2000);
    OpenOrders openOrders = tradeService.getOpenOrders();
    System.out.println(openOrders);
    List<LimitOrder> openOrdersList = openOrders.getOpenOrders();
    if (!openOrdersList.isEmpty()) {
        String existingOrderId = openOrdersList.get(0).getId();
        boolean isCancelled = tradeService.cancelOrder(existingOrderId);
        System.out.println(isCancelled);
    }
    // wait for Gateio's back-end to propagate the cancelled order
    Thread.sleep(2000);
    openOrders = tradeService.getOpenOrders();
    System.out.println(openOrders);
    Thread.sleep(2000);
    Trades tradeHistory = tradeService.getTradeHistory(new DefaultTradeHistoryParamCurrencyPair(CurrencyPair.LTC_BTC));
    System.out.println(tradeHistory);
}
Also used : Trades(org.knowm.xchange.dto.marketdata.Trades) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) GateioOpenOrders(org.knowm.xchange.gateio.dto.trade.GateioOpenOrders) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BigDecimal(java.math.BigDecimal)

Example 2 with DefaultTradeHistoryParamCurrencyPair

use of org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair in project XChange by knowm.

the class BithumbTradeDemo method generic.

private static void generic(TradeService tradeService) throws IOException, InterruptedException {
    log.debug("{}", "----------GENERIC----------");
    final OpenOrdersParams openOrders = new DefaultOpenOrdersParamCurrencyPair(CURRENCY_PAIR);
    try {
        log.debug("{}", tradeService.getOpenOrders(openOrders));
    } catch (ExchangeException e) {
        log.debug("", e);
    }
    final TradeHistoryParams tradeHistoryParams = new DefaultTradeHistoryParamCurrencyPair(CURRENCY_PAIR);
    log.debug("{}", tradeService.getTradeHistory(tradeHistoryParams));
    final LimitOrder limitOrderBuy = new LimitOrder.Builder(Order.OrderType.BID, CURRENCY_PAIR).originalAmount(BigDecimal.valueOf(10)).limitPrice(BigDecimal.valueOf(100)).build();
    log.debug("{}", tradeService.placeLimitOrder(limitOrderBuy));
    // wait for order to propagate
    Thread.sleep(3000);
    final LimitOrder limitOrderSell = new LimitOrder.Builder(Order.OrderType.ASK, CURRENCY_PAIR).originalAmount(BigDecimal.valueOf(10)).limitPrice(BigDecimal.valueOf(600)).build();
    log.debug("{}", tradeService.placeLimitOrder(limitOrderSell));
    // wait for order to propagate
    Thread.sleep(3000);
    tradeService.getOpenOrders(openOrders).getOpenOrders().stream().map(Order::getId).map(orderId -> new CancelOrderByPairAndIdParams() {

        @Override
        public String getOrderId() {
            return orderId;
        }

        @Override
        public CurrencyPair getCurrencyPair() {
            return CURRENCY_PAIR;
        }
    }).forEach(param -> {
        try {
            log.debug("{}", tradeService.cancelOrder(param));
        } catch (IOException ignored) {
        }
    });
// log.debug("{}",tradeService.placeMarketOrder(new MarketOrder(Order.OrderType.ASK,
// BigDecimal.valueOf(10), CURRENCY_PAIR)));
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BithumbOrder(org.knowm.xchange.bithumb.dto.account.BithumbOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) Logger(org.slf4j.Logger) BithumbTradeServiceRaw(org.knowm.xchange.bithumb.service.BithumbTradeServiceRaw) BithumbOrder(org.knowm.xchange.bithumb.dto.account.BithumbOrder) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Exchange(org.knowm.xchange.Exchange) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BigDecimal(java.math.BigDecimal) Order(org.knowm.xchange.dto.Order) Currency(org.knowm.xchange.currency.Currency) TradeService(org.knowm.xchange.service.trade.TradeService) BithumbDemoUtils(org.knowm.xchange.examples.bithumb.BithumbDemoUtils) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) BithumbException(org.knowm.xchange.bithumb.BithumbException) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) IOException(java.io.IOException) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)

Example 3 with DefaultTradeHistoryParamCurrencyPair

use of org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair in project XChange by knowm.

the class TradeServiceIntegration method testHgetUserTrades.

@Test
public void testHgetUserTrades() throws Exception {
    DefaultTradeHistoryParamCurrencyPair currencyPair = new DefaultTradeHistoryParamCurrencyPair();
    currencyPair.setCurrencyPair(CurrencyPair.ETH_BTC);
    UserTrades trades = tradeService.getTradeHistory(currencyPair);
    logger.info("Response: {}", trades.getUserTrades());
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) Test(org.junit.Test)

Aggregations

DefaultTradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair)3 BigDecimal (java.math.BigDecimal)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 Exchange (org.knowm.xchange.Exchange)1 BithumbException (org.knowm.xchange.bithumb.BithumbException)1 BithumbOrder (org.knowm.xchange.bithumb.dto.account.BithumbOrder)1 BithumbTradeServiceRaw (org.knowm.xchange.bithumb.service.BithumbTradeServiceRaw)1 Currency (org.knowm.xchange.currency.Currency)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 Order (org.knowm.xchange.dto.Order)1 Trades (org.knowm.xchange.dto.marketdata.Trades)1 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1 BithumbDemoUtils (org.knowm.xchange.examples.bithumb.BithumbDemoUtils)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 GateioOpenOrders (org.knowm.xchange.gateio.dto.trade.GateioOpenOrders)1 TradeService (org.knowm.xchange.service.trade.TradeService)1 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)1