Search in sources :

Example 1 with TradeHandler

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

the class TradeManagerTest method testTradeChannelHandler1.

/**
 * Test the trade channel handler
 * @throws APIException
 * @throws InterruptedException
 */
@Test(timeout = 10000)
public void testTradeChannelHandler1() throws APIException, InterruptedException {
    final String jsonString = "[0,\"te\",[106655593,\"tBTCUSD\",1512247319827,5691690918,-0.002,10894,null,null,-1]]";
    final JSONArray jsonArray = new JSONArray(jsonString);
    final TradeHandler tradeHandler = new TradeHandler();
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    final CountDownLatch latch = new CountDownLatch(1);
    bitfinexApiBroker.getTradeManager().registerCallback((t) -> {
        try {
            Assert.assertTrue(t.isExecuted());
            Assert.assertEquals(106655593, t.getId());
            Assert.assertEquals(BitfinexCurrencyPair.BTC_USD, t.getCurrency());
            Assert.assertEquals(1512247319827l, t.getMtsCreate());
            Assert.assertEquals(5691690918l, t.getOrderId());
            Assert.assertEquals(-0.002, t.getExecAmount().doubleValue(), DELTA);
            Assert.assertEquals(10894, t.getExecPrice().doubleValue(), DELTA);
            Assert.assertTrue(t.toString().length() > 0);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
        latch.countDown();
    });
    tradeHandler.handleChannelData(bitfinexApiBroker, jsonArray);
    latch.await();
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONArray(org.json.JSONArray) CountDownLatch(java.util.concurrent.CountDownLatch) TradeHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler) Test(org.junit.Test)

Example 2 with TradeHandler

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

the class TradeManagerTest method testTradeChannelHandler2.

/**
 * Test the trade channel handler
 * @throws APIException
 * @throws InterruptedException
 */
@Test(timeout = 10000)
public void testTradeChannelHandler2() throws APIException, InterruptedException {
    final String jsonString = "[0,\"tu\",[106655593,\"tBTCUSD\",1512247319827,5691690918,-0.002,10894,\"EXCHANGE MARKET\",10894,-1,-0.0392184,\"USD\"]]";
    final JSONArray jsonArray = new JSONArray(jsonString);
    final TradeHandler tradeHandler = new TradeHandler();
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    final CountDownLatch latch = new CountDownLatch(1);
    bitfinexApiBroker.getTradeManager().registerCallback((t) -> {
        try {
            Assert.assertFalse(t.isExecuted());
            Assert.assertEquals(106655593, t.getId());
            Assert.assertEquals(BitfinexCurrencyPair.BTC_USD, t.getCurrency());
            Assert.assertEquals(1512247319827l, t.getMtsCreate());
            Assert.assertEquals(5691690918l, t.getOrderId());
            Assert.assertEquals(-0.002, t.getExecAmount().doubleValue(), DELTA);
            Assert.assertEquals(10894, t.getExecPrice().doubleValue(), DELTA);
            Assert.assertEquals(BitfinexOrderType.EXCHANGE_MARKET, t.getOrderType());
            Assert.assertEquals(10894, t.getOrderPrice().doubleValue(), DELTA);
            Assert.assertFalse(t.isMaker());
            Assert.assertEquals(-0.0392184, t.getFee().doubleValue(), DELTA);
            Assert.assertEquals("USD", t.getFeeCurrency());
            Assert.assertTrue(t.toString().length() > 0);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
        latch.countDown();
    });
    tradeHandler.handleChannelData(bitfinexApiBroker, jsonArray);
    latch.await();
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONArray(org.json.JSONArray) CountDownLatch(java.util.concurrent.CountDownLatch) TradeHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler) Test(org.junit.Test)

Example 3 with TradeHandler

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

TradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler)3 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JSONArray (org.json.JSONArray)2 Test (org.junit.Test)2 DoNothingHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.DoNothingHandler)1 HeartbeatHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.HeartbeatHandler)1 NotificationHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler)1 OrderHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler)1 PositionHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.PositionHandler)1 WalletHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler)1 ExecutedTradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler)1