Search in sources :

Example 1 with NotificationHandler

use of com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler 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 2 with NotificationHandler

use of com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class BitfinexApiBroker method setupChannelHandler.

/**
 * Setup the channel handler
 */
private void setupChannelHandler() {
    // Heartbeat
    channelHandler.put("hb", new HeartbeatHandler());
    // Position snapshot
    channelHandler.put("ps", new PositionHandler());
    // Position new
    channelHandler.put("pn", new PositionHandler());
    // Position updated
    channelHandler.put("pu", new PositionHandler());
    // Position caneled
    channelHandler.put("pc", new PositionHandler());
    // Founding offers
    channelHandler.put("fos", new DoNothingHandler());
    // Founding credits
    channelHandler.put("fcs", new DoNothingHandler());
    // Founding loans
    channelHandler.put("fls", new DoNothingHandler());
    // Ats - Unkown
    channelHandler.put("ats", new DoNothingHandler());
    // Wallet snapshot
    channelHandler.put("ws", new WalletHandler());
    // Wallet update
    channelHandler.put("wu", new WalletHandler());
    // Order snapshot
    channelHandler.put("os", new OrderHandler());
    // Order notification
    channelHandler.put("on", new OrderHandler());
    // Order update
    channelHandler.put("ou", new OrderHandler());
    // Order cancelation
    channelHandler.put("oc", new OrderHandler());
    // Trade executed
    channelHandler.put("te", new TradeHandler());
    // Trade update
    channelHandler.put("tu", new TradeHandler());
    // General notification
    channelHandler.put("n", new NotificationHandler());
}
Also used : HeartbeatHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.HeartbeatHandler) PositionHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.PositionHandler) NotificationHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler) DoNothingHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.DoNothingHandler) WalletHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler) TradeHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler) ExecutedTradeHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler) OrderHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler)

Aggregations

NotificationHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler)2 OrderHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler)2 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 BitfinexOrderBuilder (com.github.jnidzwetzki.bitfinex.v2.BitfinexOrderBuilder)1 DoNothingHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.DoNothingHandler)1 HeartbeatHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.HeartbeatHandler)1 PositionHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.PositionHandler)1 TradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler)1 WalletHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler)1 ExecutedTradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler)1 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)1 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)1 BitfinexOrder (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder)1 BitfinexOrderType (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrderType)1 ConnectionCapabilities (com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities)1 ExchangeOrder (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder)1 ExchangeOrderState (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrderState)1 OrderManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1