use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CommandsCallbackTest method testAuthCommandCallback2.
/**
* Test the auth callback
* @throws APIException
*/
@Test
public void testAuthCommandCallback2() throws APIException {
final String authCallback = "{\"event\":\"auth\",\"status\":\"FAILED\",\"chanId\":0,}";
final BitfinexApiBroker bitfinexApiBroker = Mockito.spy(BitfinexApiBroker.class);
final JSONObject jsonObject = new JSONObject(authCallback);
final AuthCallbackHandler authCallbackHandler = new AuthCallbackHandler();
Assert.assertFalse(bitfinexApiBroker.isAuthenticated());
authCallbackHandler.handleChannelData(bitfinexApiBroker, jsonObject);
Assert.assertFalse(bitfinexApiBroker.isAuthenticated());
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CommandsCallbackTest method testConnectionHeartbeat.
/**
* Test the pong callback
* @throws APIException
*/
@Test
public void testConnectionHeartbeat() throws APIException {
final String jsonString = "{\"event\":\"pong\",\"ts\":1515023251265}";
final JSONObject jsonObject = new JSONObject(jsonString);
final BitfinexApiBroker bitfinexApiBroker = new BitfinexApiBroker();
final long oldHeartbeat = bitfinexApiBroker.getLastHeatbeat().get();
final ConnectionHeartbeatCallback connectionHeartbeatCallback = new ConnectionHeartbeatCallback();
connectionHeartbeatCallback.handleChannelData(bitfinexApiBroker, jsonObject);
final long newHeartbeat = bitfinexApiBroker.getLastHeatbeat().get();
Assert.assertTrue(oldHeartbeat < newHeartbeat);
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker 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);
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class WalletHandler method handleWalletcallback.
/**
* Handle the callback for a single wallet
* @param bitfinexApiBroker
* @param walletArray
* @throws APIException
*/
private void handleWalletcallback(final BitfinexApiBroker bitfinexApiBroker, final JSONArray walletArray) throws APIException {
final String walletType = walletArray.getString(0);
final String currency = walletArray.getString(1);
final BigDecimal balance = walletArray.getBigDecimal(2);
final BigDecimal unsettledInterest = walletArray.getBigDecimal(3);
final BigDecimal balanceAvailable = walletArray.optBigDecimal(4, BigDecimal.valueOf(-1));
final Wallet wallet = new Wallet(walletType, currency, balance, unsettledInterest, balanceAvailable);
final WalletManager walletManager = bitfinexApiBroker.getWalletManager();
final Table<String, String, Wallet> walletTable = walletManager.getWalletTable();
synchronized (walletTable) {
walletTable.put(walletType, currency, wallet);
walletTable.notifyAll();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CandlestickHandler method handleChannelData.
/**
* Handle a candlestick callback
* @param channel
* @param subarray
*/
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
// channel symbol trade:1m:tLTCUSD
final List<BitfinexTick> ticksBuffer = new ArrayList<>();
// Snapshots contain multiple Bars, Updates only one
if (jsonArray.get(0) instanceof JSONArray) {
for (int pos = 0; pos < jsonArray.length(); pos++) {
final JSONArray parts = jsonArray.getJSONArray(pos);
parseCandlestick(ticksBuffer, parts);
}
} else {
parseCandlestick(ticksBuffer, jsonArray);
}
// Use natural ordering
ticksBuffer.sort(null);
final BitfinexCandlestickSymbol candlestickSymbol = (BitfinexCandlestickSymbol) channelSymbol;
bitfinexApiBroker.getQuoteManager().handleCandlestickList(candlestickSymbol, ticksBuffer);
}
Aggregations