Search in sources :

Example 1 with DefaultOpenOrdersParamCurrencyPair

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

the class CoinbeneTradeDemo 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 DefaultOpenOrdersParamCurrencyPair(pair));
    LimitOrder order = orders.getOpenOrders().stream().collect(StreamUtils.singletonCollector());
    if (order != null) {
        System.out.println(order);
    }
}
Also used : CoinbeneTradeService(org.knowm.xchange.coinbene.service.CoinbeneTradeService) TradeService(org.knowm.xchange.service.trade.TradeService) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)

Example 2 with DefaultOpenOrdersParamCurrencyPair

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

the class TradeServiceIntegration method testCgetOpenOrdersByMarketTest.

@Test
public void testCgetOpenOrdersByMarketTest() throws Exception {
    DefaultOpenOrdersParamCurrencyPair currencyPair = new DefaultOpenOrdersParamCurrencyPair();
    currencyPair.setCurrencyPair(CurrencyPair.ETH_BTC);
    OpenOrders openOrders = tradeService.getOpenOrders(currencyPair);
    logger.info("Response: {}", openOrders);
}
Also used : OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) Test(org.junit.Test)

Example 3 with DefaultOpenOrdersParamCurrencyPair

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

the class GeminiTradeServiceTest method openOrdersByCurrencyPairTest.

@Test
public void openOrdersByCurrencyPairTest() throws Exception {
    stubFor(post(urlPathEqualTo("/v1/orders")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile(ORDERS_FILE_NAME)));
    DefaultOpenOrdersParamCurrencyPair defaultOpenOrdersParamCurrencyPair = new DefaultOpenOrdersParamCurrencyPair(CurrencyPair.BTC_USD);
    OpenOrders openOrders = classUnderTest.getOpenOrders(defaultOpenOrdersParamCurrencyPair);
    assertThat(openOrders).isNotNull();
    assertThat(openOrders.getOpenOrders().size()).isEqualTo(1);
    LimitOrder firstOrder = openOrders.getOpenOrders().get(0);
    assertThat(firstOrder).isNotNull();
    assertThat(firstOrder.getOriginalAmount()).isNotNull().isPositive();
    assertThat(firstOrder.getId()).isNotBlank();
    assertThat(firstOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USD);
}
Also used : OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) Test(org.junit.Test)

Example 4 with DefaultOpenOrdersParamCurrencyPair

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

the class CoinbaseProTradeServiceTest method openOrdersByProductTest.

@Test
public void openOrdersByProductTest() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonRoot = mapper.readTree(this.getClass().getResource("/" + WIREMOCK_FILES_PATH + "/" + OPENORDERS_FILE_NAME));
    stubFor(get(urlPathEqualTo("/orders")).withQueryParam("status", equalTo("open")).withQueryParam("product_id", equalTo("BTC-USD")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("openOrders.json")));
    DefaultOpenOrdersParamCurrencyPair defaultOpenOrdersParamCurrencyPair = new DefaultOpenOrdersParamCurrencyPair(CurrencyPair.BTC_USD);
    OpenOrders openOrders = classUnderTest.getOpenOrders(defaultOpenOrdersParamCurrencyPair);
    assertThat(openOrders).isNotNull();
    assertThat(openOrders.getOpenOrders()).hasSize(jsonRoot.size());
    LimitOrder firstOrder = openOrders.getOpenOrders().get(0);
    assertThat(firstOrder).isNotNull();
    assertThat(firstOrder.getOriginalAmount()).isNotNull().isPositive();
    assertThat(firstOrder.getId()).isNotBlank();
    assertThat(firstOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USD);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) Test(org.junit.Test)

Example 5 with DefaultOpenOrdersParamCurrencyPair

use of org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair 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)

Aggregations

DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)11 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)9 Test (org.junit.Test)6 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)6 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)4 TradeService (org.knowm.xchange.service.trade.TradeService)3 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 BithumbException (org.knowm.xchange.bithumb.BithumbException)2 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)2 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)2 OpenOrdersParams (org.knowm.xchange.service.trade.params.orders.OpenOrdersParams)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Date (java.util.Date)1 Exchange (org.knowm.xchange.Exchange)1 BinanceTradeService (org.knowm.xchange.binance.service.BinanceTradeService)1 BithumbOrder (org.knowm.xchange.bithumb.dto.account.BithumbOrder)1 BithumbTradeServiceRaw (org.knowm.xchange.bithumb.service.BithumbTradeServiceRaw)1 CoinbeneTradeService (org.knowm.xchange.coinbene.service.CoinbeneTradeService)1