Search in sources :

Example 1 with WalletHandler

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

the class WalletHandlerTest method testWalletSnapshot.

/**
 * Test the wallet parsing
 * @throws APIException
 * @throws InterruptedException
 */
@Test(timeout = 20000)
public void testWalletSnapshot() throws APIException, InterruptedException {
    final String callbackValue = "[0,\"ws\",[[\"exchange\",\"ETH\",9,0,null],[\"exchange\",\"USD\",1826.56468323,0,null],[\"margin\",\"USD\",0,0,null],[\"exchange\",\"XRP\",0,0,null],[\"exchange\",\"EOS\",0,0,null],[\"exchange\",\"NEO\",0,0,null],[\"exchange\",\"LTC\",0,0,null],[\"exchange\",\"IOT\",0,0,null],[\"exchange\",\"BTC\",0,0,null]]]";
    final JSONArray jsonArray = new JSONArray(callbackValue);
    final CountDownLatch walletLatch = new CountDownLatch(1);
    final Table<String, String, Wallet> walletTable = HashBasedTable.create();
    final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
    final WalletManager walletManager = Mockito.mock(WalletManager.class);
    Mockito.when(bitfinexApiBroker.getWalletManager()).thenReturn(walletManager);
    Mockito.when(walletManager.getWalletTable()).thenReturn(walletTable);
    Mockito.when(bitfinexApiBroker.getConnectionReadyLatch()).thenReturn(walletLatch);
    Assert.assertTrue(walletTable.isEmpty());
    final WalletHandler walletHandler = new WalletHandler();
    walletHandler.handleChannelData(bitfinexApiBroker, jsonArray);
    walletLatch.await();
    Assert.assertEquals(9, walletTable.size());
    Assert.assertEquals(9, walletTable.get("exchange", "ETH").getBalance().doubleValue(), DELTA);
    Assert.assertEquals(-1, walletTable.get("exchange", "ETH").getBalanceAvailable().doubleValue(), DELTA);
    Assert.assertEquals(0, walletTable.get("exchange", "ETH").getUnsettledInterest().doubleValue(), DELTA);
    Assert.assertEquals(1826.56468323, walletTable.get("exchange", "USD").getBalance().doubleValue(), DELTA);
    Assert.assertEquals(-1, walletTable.get("exchange", "ETH").getBalanceAvailable().doubleValue(), DELTA);
    Assert.assertEquals(0, walletTable.get("exchange", "ETH").getUnsettledInterest().doubleValue(), DELTA);
    Assert.assertEquals(0, walletTable.get("margin", "USD").getBalance().doubleValue(), DELTA);
    Assert.assertEquals(-1, walletTable.get("margin", "USD").getBalanceAvailable().doubleValue(), DELTA);
    Assert.assertEquals(0, walletTable.get("margin", "USD").getUnsettledInterest().doubleValue(), DELTA);
    Assert.assertTrue(walletTable.get("margin", "USD").toString().length() > 0);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) WalletManager(com.github.jnidzwetzki.bitfinex.v2.manager.WalletManager) Wallet(com.github.jnidzwetzki.bitfinex.v2.entity.Wallet) JSONArray(org.json.JSONArray) WalletHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with WalletHandler

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

the class WalletHandlerTest method testWalletUpdate.

/**
 * Test the wallet parsing
 * @throws APIException
 * @throws InterruptedException
 */
@Test(timeout = 20000)
public void testWalletUpdate() throws APIException, InterruptedException {
    final String callbackValue = "[0,\"ws\",[\"exchange\",\"ETH\",9,0,null]]";
    final JSONArray jsonArray = new JSONArray(callbackValue);
    final CountDownLatch walletLatch = new CountDownLatch(1);
    final Table<String, String, Wallet> walletTable = HashBasedTable.create();
    final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
    final WalletManager walletManager = Mockito.mock(WalletManager.class);
    Mockito.when(bitfinexApiBroker.getWalletManager()).thenReturn(walletManager);
    Mockito.when(walletManager.getWalletTable()).thenReturn(walletTable);
    Mockito.when(bitfinexApiBroker.getConnectionReadyLatch()).thenReturn(walletLatch);
    Assert.assertTrue(walletTable.isEmpty());
    final WalletHandler walletHandler = new WalletHandler();
    walletHandler.handleChannelData(bitfinexApiBroker, jsonArray);
    walletLatch.await();
    Assert.assertEquals(1, walletTable.size());
    Assert.assertEquals(9, walletTable.get("exchange", "ETH").getBalance().doubleValue(), DELTA);
    Assert.assertEquals(-1, walletTable.get("exchange", "ETH").getBalanceAvailable().doubleValue(), DELTA);
    Assert.assertEquals(0, walletTable.get("exchange", "ETH").getUnsettledInterest().doubleValue(), DELTA);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) WalletManager(com.github.jnidzwetzki.bitfinex.v2.manager.WalletManager) Wallet(com.github.jnidzwetzki.bitfinex.v2.entity.Wallet) JSONArray(org.json.JSONArray) WalletHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with WalletHandler

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

WalletHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler)3 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)2 Wallet (com.github.jnidzwetzki.bitfinex.v2.entity.Wallet)2 WalletManager (com.github.jnidzwetzki.bitfinex.v2.manager.WalletManager)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 TradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler)1 ExecutedTradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler)1