Search in sources :

Example 11 with ExchangeOrder

use of com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class OrderManagerTest method testOrderSubmissionFailed.

/**
 * Test order submit failed
 * @throws APIException
 * @throws InterruptedException
 */
@Test(timeout = 10000)
public void testOrderSubmissionFailed() throws APIException, InterruptedException {
    final String jsonString = "[0,\"n\",[null,\"on-req\",null,null,[null,null,1513970684865000,\"tBTCUSD\",null,null,0.001,0.001,\"EXCHANGE MARKET\",null,null,null,null,null,null,null,12940,null,null,null,null,null,null,0,null,null],null,\"ERROR\",\"Invalid order: minimum size for BTC/USD is 0.002\"]]";
    final JSONArray jsonArray = new JSONArray(jsonString);
    final CountDownLatch latch = new CountDownLatch(1);
    final Consumer<ExchangeOrder> orderCallback = (e) -> {
        Assert.assertEquals(ExchangeOrderState.STATE_ERROR, e.getState());
        Assert.assertEquals(API_KEY, e.getApikey());
        Assert.assertEquals(1513970684865000l, e.getCid());
        Assert.assertEquals(BitfinexCurrencyPair.BTC_USD.toBitfinexString(), e.getSymbol());
        latch.countDown();
    };
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    bitfinexApiBroker.getOrderManager().registerCallback(orderCallback);
    final NotificationHandler notificationHandler = new NotificationHandler();
    notificationHandler.handleChannelData(bitfinexApiBroker, jsonArray);
    latch.await();
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) NotificationHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler) ConnectionCapabilities(com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities) Test(org.junit.Test) BitfinexOrderBuilder(com.github.jnidzwetzki.bitfinex.v2.BitfinexOrderBuilder) ExchangeOrderState(com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrderState) Executors(java.util.concurrent.Executors) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) Consumer(java.util.function.Consumer) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) BitfinexOrderType(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrderType) ExchangeOrder(com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder) BitfinexOrder(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder) OrderManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager) Assert(org.junit.Assert) ExecutorService(java.util.concurrent.ExecutorService) JSONArray(org.json.JSONArray) OrderHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) NotificationHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler) JSONArray(org.json.JSONArray) CountDownLatch(java.util.concurrent.CountDownLatch) ExchangeOrder(com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder) Test(org.junit.Test)

Example 12 with ExchangeOrder

use of com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class OrderManagerTest method testCancelOrder.

/**
 * Test the cancelation of an order
 * @throws InterruptedException
 * @throws APIException
 */
@Test(timeout = 60000)
public void testCancelOrder() throws APIException, InterruptedException {
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
    final Runnable r = () -> {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            return;
        }
        final ExchangeOrder exchangeOrder = new ExchangeOrder();
        exchangeOrder.setOrderId(12);
        exchangeOrder.setState(ExchangeOrderState.STATE_CANCELED);
        orderManager.updateOrder(exchangeOrder);
    };
    // Cancel event
    (new Thread(r)).start();
    orderManager.cancelOrderAndWaitForCompletion(12);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) ExchangeOrder(com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder) OrderManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager) Test(org.junit.Test)

Aggregations

ExchangeOrder (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder)12 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)6 BitfinexOrder (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder)6 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)5 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)4 ExchangeOrderState (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrderState)4 ConnectionCapabilities (com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities)3 OrderManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Consumer (java.util.function.Consumer)3 Test (org.junit.Test)3 CancelOrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand)2 CancelOrderGroupCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand)2 OrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand)2 Callable (java.util.concurrent.Callable)2 TimeUnit (java.util.concurrent.TimeUnit)2 Retryer (org.bboxdb.commons.Retryer)2 Logger (org.slf4j.Logger)2