Search in sources :

Example 6 with Position

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

the class PositionTest method testPositionHandlerUpdate.

/**
 * Test the position handler
 * @throws APIException
 */
@Test
public void testPositionHandlerUpdate() throws APIException {
    final String jsonString = "[0,\"pu\",[\"tETHUSD\",\"ACTIVE\",0.14,713.78,-0.00330012,0,null,null,null,null]]";
    final JSONArray jsonArray = new JSONArray(jsonString);
    final PositionHandler positionHandler = new PositionHandler();
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    Assert.assertTrue(bitfinexApiBroker.getPositionManager().getPositions().isEmpty());
    positionHandler.handleChannelData(bitfinexApiBroker, jsonArray);
    Assert.assertEquals(1, bitfinexApiBroker.getPositionManager().getPositions().size());
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) PositionHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.PositionHandler) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 7 with Position

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

the class PositionTest method testPositionHandlerSnapshot.

/**
 * Test the position handler
 * @throws APIException
 */
@Test
public void testPositionHandlerSnapshot() throws APIException {
    final String jsonString = "[0,\"ps\",[[\"tETHUSD\",\"ACTIVE\",0.14,713.78,-0.00330012,0,null,null,null,null], [\"tBTCUSD\",\"ACTIVE\",0.14,713.78,-0.00330012,0,null,null,null,null]]]";
    final JSONArray jsonArray = new JSONArray(jsonString);
    final PositionHandler positionHandler = new PositionHandler();
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    Assert.assertTrue(bitfinexApiBroker.getPositionManager().getPositions().isEmpty());
    positionHandler.handleChannelData(bitfinexApiBroker, jsonArray);
    Assert.assertEquals(2, bitfinexApiBroker.getPositionManager().getPositions().size());
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) PositionHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.PositionHandler) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 8 with Position

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

the class PositionHandler method handlePositionCallback.

/**
 * Handle a position update
 * @param bitfinexApiBroker
 * @param positions
 */
private void handlePositionCallback(final BitfinexApiBroker bitfinexApiBroker, final JSONArray positions) {
    final String currencyString = positions.getString(0);
    BitfinexCurrencyPair currency = BitfinexCurrencyPair.fromSymbolString(currencyString);
    final Position position = new Position(currency);
    position.setStatus(positions.getString(1));
    position.setAmount(positions.getBigDecimal(2));
    position.setBasePrice(positions.getBigDecimal(3));
    position.setMarginFunding(positions.getBigDecimal(4));
    position.setMarginFundingType(positions.getBigDecimal(5));
    position.setPl(positions.optBigDecimal(6, BigDecimal.valueOf(-1)));
    position.setPlPercent(positions.optBigDecimal(7, BigDecimal.valueOf(-1)));
    position.setPriceLiquidation(positions.optBigDecimal(8, BigDecimal.valueOf(-1)));
    position.setLeverage(positions.optBigDecimal(9, BigDecimal.valueOf(-1)));
    bitfinexApiBroker.getPositionManager().updatePosition(position);
}
Also used : Position(com.github.jnidzwetzki.bitfinex.v2.entity.Position) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)

Example 9 with Position

use of com.github.jnidzwetzki.bitfinex.v2.entity.Position 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

BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)4 PositionHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.PositionHandler)3 JSONArray (org.json.JSONArray)3 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)2 ExecutedTradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler)2 ExchangeOrder (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder)2 Position (com.github.jnidzwetzki.bitfinex.v2.entity.Position)2 CurrencyEntry (com.github.jnidzwetzki.cryptobot.CurrencyEntry)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 TradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler)1 WalletHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler)1 CandlestickHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.CandlestickHandler)1 ChannelCallbackHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ChannelCallbackHandler)1 OrderbookHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.OrderbookHandler)1 RawOrderbookHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.RawOrderbookHandler)1 TickHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.TickHandler)1