Search in sources :

Example 1 with TradeService

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);
}
Also used : CoinfloorExchange(org.knowm.xchange.coinfloor.CoinfloorExchange) Exchange(org.knowm.xchange.Exchange) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeService(org.knowm.xchange.service.trade.TradeService) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) Test(org.junit.Test)

Example 2 with TradeService

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);
    }
}
Also used : CoinfloorExchange(org.knowm.xchange.coinfloor.CoinfloorExchange) Exchange(org.knowm.xchange.Exchange) TradeService(org.knowm.xchange.service.trade.TradeService) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Test(org.junit.Test)

Example 3 with TradeService

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);
}
Also used : Exchange(org.knowm.xchange.Exchange) TradeService(org.knowm.xchange.service.trade.TradeService)

Example 4 with 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.");
    }
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KucoinExamplesUtils(org.knowm.xchange.examples.kucoin.KucoinExamplesUtils) OrderCancelResponse(org.knowm.xchange.kucoin.dto.response.OrderCancelResponse) OrderType(org.knowm.xchange.dto.Order.OrderType) UUID(java.util.UUID) Exchange(org.knowm.xchange.Exchange) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BigDecimal(java.math.BigDecimal) Order(org.knowm.xchange.dto.Order) TradeService(org.knowm.xchange.service.trade.TradeService) Optional(java.util.Optional) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) KucoinTradeServiceRaw(org.knowm.xchange.kucoin.KucoinTradeServiceRaw) OrderCreateApiRequest(org.knowm.xchange.kucoin.dto.request.OrderCreateApiRequest) OrderCreateResponse(org.knowm.xchange.kucoin.dto.response.OrderCreateResponse) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) StopOrder(org.knowm.xchange.dto.trade.StopOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)

Example 5 with TradeService

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);
}
Also used : Exchange(org.knowm.xchange.Exchange) InteractiveAuthenticatedExchange(org.knowm.xchange.examples.mercadobitcoin.InteractiveAuthenticatedExchange) TradeService(org.knowm.xchange.service.trade.TradeService)

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