Search in sources :

Example 26 with MarketOrder

use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.

the class TradeServiceIntegration method marketSellTest.

/*
   * @Test public void marketBuyTest() throws Exception { Exchange exchange = ExchangeUtils.createExchangeFromJsonConfiguration(); if (exchange ==
   * null) { return; // forces pass if not configuration is available } assertNotNull(exchange); TradeService service = exchange.getTradeService();
   * assertNotNull(service); String id = service.placeMarketOrder(new MarketOrder(Order.OrderType.BID, new BigDecimal("0.1"), CurrencyPair.BTC_EUR));
   * System.out.println("Market buy order id = " + id); }
   */
@Test
public void marketSellTest() throws Exception {
    Exchange exchange = ExchangeUtils.createExchangeFromJsonConfiguration();
    if (exchange == null) {
        // forces pass if not configuration is available
        return;
    }
    assertNotNull(exchange);
    TradeService service = exchange.getTradeService();
    assertNotNull(service);
    service.placeMarketOrder(new MarketOrder(Order.OrderType.ASK, new BigDecimal("0.001"), CurrencyPair.BTC_EUR));
}
Also used : Exchange(org.knowm.xchange.Exchange) TradeService(org.knowm.xchange.service.trade.TradeService) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 27 with MarketOrder

use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.

the class DsxTradeServiceRawIntegration method testPlaceMarketOrderRaw.

@Test
public void testPlaceMarketOrderRaw() throws IOException {
    Date date = new Date();
    String id = date.toString().replace(" ", "");
    LOGGER.info("Placing order id : " + id);
    exception.expect(DsxException.class);
    exception.expectMessage("Insufficient funds");
    MarketOrder limitOrder = new MarketOrder(Order.OrderType.BID, new BigDecimal("0.01"), CurrencyPair.BTC_USD, id, new Date());
    service.placeMarketOrderRaw(limitOrder);
}
Also used : MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) BaseAuthenticatedServiceTest(org.knowm.xchange.dsx.BaseAuthenticatedServiceTest)

Example 28 with MarketOrder

use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.

the class BinanceAdaptersTest method testFilledMarketOrder.

@Test
public void testFilledMarketOrder() throws IOException {
    BinanceOrder binanceOrder = ObjectMapperHelper.readValue(BinanceAdaptersTest.class.getResource("/org/knowm/xchange/binance/filled-market-order.json"), BinanceOrder.class);
    Order order = BinanceAdapters.adaptOrder(binanceOrder);
    assertThat(order).isInstanceOf(MarketOrder.class);
    MarketOrder marketOrder = (MarketOrder) order;
    assertThat(marketOrder.getStatus()).isEqualByComparingTo(Order.OrderStatus.FILLED);
    assertThat(marketOrder.getOriginalAmount()).isEqualByComparingTo("0.10700000");
    assertThat(marketOrder.getCumulativeAmount()).isEqualByComparingTo("0.10700000");
    assertThat(marketOrder.getRemainingAmount()).isEqualByComparingTo(BigDecimal.ZERO);
    assertThat(marketOrder.getAveragePrice()).isEqualByComparingTo("0.01858383");
    assertThat(marketOrder.getOrderFlags()).contains(BinanceOrderFlags.withClientId("gzcLIkn86ag3FycOCEl6Vi"));
    MarketOrder copy = ObjectMapperHelper.viaJSON(marketOrder);
    assertThat(copy).isEqualToComparingFieldByField(marketOrder);
}
Also used : BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) Order(org.knowm.xchange.dto.Order) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Test(org.junit.Test)

Example 29 with MarketOrder

use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.

the class TradeServiceIntegration method testPlaceTestOrderMarketOrderShouldNotThrowAnyException.

@Test
public void testPlaceTestOrderMarketOrderShouldNotThrowAnyException() throws IOException {
    final MarketOrder marketOrder = sampleMarketOrder();
    tradeService.placeTestOrder(MARKET, marketOrder, null, null);
}
Also used : MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Test(org.junit.Test)

Example 30 with MarketOrder

use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.

the class BTCMarketsTradeServiceTest method shouldPlaceMarketOrder.

@Test
public void shouldPlaceMarketOrder() throws IOException {
    MarketOrder marketOrder = new MarketOrder.Builder(Order.OrderType.BID, CurrencyPair.BTC_AUD).originalAmount(new BigDecimal("10.00000000")).build();
    BTCMarketsPlaceOrderRequest btcMarketsOrder = new BTCMarketsPlaceOrderRequest("BTC-AUD", "0", "10.00000000", "Market", "Bid", null, null, "GTC", false, null, null);
    BTCMarketsPlaceOrderResponse orderResponse = new BTCMarketsPlaceOrderResponse("11111");
    when(btcMarketsAuthenticatedV3.placeOrder(Mockito.eq(SPECIFICATION_API_KEY), Mockito.any(SynchronizedValueFactory.class), Mockito.any(BTCMarketsDigestV3.class), Mockito.refEq(btcMarketsOrder))).thenReturn(orderResponse);
    // when
    String placed = btcMarketsTradeService.placeMarketOrder(marketOrder);
    // then
    assertThat(placed).isEqualTo("11111");
}
Also used : MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BTCMarketsPlaceOrderResponse(org.knowm.xchange.btcmarkets.dto.v3.trade.BTCMarketsPlaceOrderResponse) BTCMarketsPlaceOrderRequest(org.knowm.xchange.btcmarkets.dto.v3.trade.BTCMarketsPlaceOrderRequest) BigDecimal(java.math.BigDecimal) SynchronizedValueFactory(si.mazi.rescu.SynchronizedValueFactory) Test(org.junit.Test)

Aggregations

MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)45 BigDecimal (java.math.BigDecimal)37 Test (org.junit.Test)20 Date (java.util.Date)17 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)15 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)10 TradeService (org.knowm.xchange.service.trade.TradeService)9 UserTrades (org.knowm.xchange.dto.trade.UserTrades)8 Order (org.knowm.xchange.dto.Order)7 OrderType (org.knowm.xchange.dto.Order.OrderType)6 LgoProductsTest (org.knowm.xchange.lgo.dto.product.LgoProductsTest)6 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)5 IOException (java.io.IOException)4 ThrowingCallable (org.assertj.core.api.ThrowableAssert.ThrowingCallable)4 Exchange (org.knowm.xchange.Exchange)4 StopOrder (org.knowm.xchange.dto.trade.StopOrder)4 OrderStatus (org.knowm.xchange.dto.Order.OrderStatus)3 ArrayList (java.util.ArrayList)2 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)2 UserTrade (org.knowm.xchange.dto.trade.UserTrade)2