Search in sources :

Example 6 with BitfinexExecutedTradeSymbol

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

the class BitfinexApiBroker method handleChannelDataArray.

/**
 * Handle the channel data with has an array at first position
 * @param jsonArray
 * @param channelSymbol
 * @throws APIException
 */
private void handleChannelDataArray(final JSONArray jsonArray, final BitfinexStreamSymbol channelSymbol) throws APIException {
    final JSONArray subarray = jsonArray.getJSONArray(1);
    if (channelSymbol instanceof BitfinexCandlestickSymbol) {
        final ChannelCallbackHandler handler = new CandlestickHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof RawOrderbookConfiguration) {
        final RawOrderbookHandler handler = new RawOrderbookHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof OrderbookConfiguration) {
        final OrderbookHandler handler = new OrderbookHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof BitfinexTickerSymbol) {
        final ChannelCallbackHandler handler = new TickHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof BitfinexExecutedTradeSymbol) {
        final ChannelCallbackHandler handler = new ExecutedTradeHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else {
        logger.error("Unknown stream type: {}", channelSymbol);
    }
}
Also used : CandlestickHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.CandlestickHandler) RawOrderbookHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.RawOrderbookHandler) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) ChannelCallbackHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.ChannelCallbackHandler) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) JSONArray(org.json.JSONArray) RawOrderbookHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.RawOrderbookHandler) OrderbookHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.OrderbookHandler) ExecutedTradeHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) TickHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.TickHandler)

Example 7 with BitfinexExecutedTradeSymbol

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

the class SubscribedCallback method handleTradesCallback.

/**
 * Handle the trades callback
 *
 * @param bitfinexApiBroker
 * @param jsonObject
 * @param channelId
 */
private void handleTradesCallback(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject, final int channelId) {
    final String symbol2 = jsonObject.getString("symbol");
    final BitfinexExecutedTradeSymbol currencyPair = BitfinexExecutedTradeSymbol.fromBitfinexString(symbol2);
    logger.info("Registering symbol {} on channel {}", currencyPair, channelId);
    bitfinexApiBroker.addToChannelSymbolMap(channelId, currencyPair);
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)

Example 8 with BitfinexExecutedTradeSymbol

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

the class CommandsTest method testCommandsJSON.

/**
 * Call all commands and check for excepion
 * @throws CommandException
 */
@Test
public void testCommandsJSON() throws CommandException {
    final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.EXCHANGE_STOP, 2).build();
    final BitfinexCandlestickSymbol candleSymbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BCH_USD, Timeframe.HOUR_1);
    final OrderbookConfiguration orderbookConfiguration = new OrderbookConfiguration(BitfinexCurrencyPair.BCH_USD, OrderBookPrecision.P0, OrderBookFrequency.F0, 50);
    final RawOrderbookConfiguration rawOrderbookConfiguration = new RawOrderbookConfiguration(BitfinexCurrencyPair.BAT_BTC);
    final List<AbstractAPICommand> commands = Arrays.asList(new AuthCommand(), new CancelOrderCommand(123), new CancelOrderGroupCommand(1), new OrderCommand(order), new PingCommand(), new SubscribeCandlesCommand(candleSymbol), new SubscribeTickerCommand(new BitfinexTickerSymbol(BitfinexCurrencyPair.BCH_USD)), new SubscribeTradesCommand(new BitfinexExecutedTradeSymbol(BitfinexCurrencyPair.BAT_BTC)), new SubscribeOrderbookCommand(orderbookConfiguration), new SubscribeRawOrderbookCommand(rawOrderbookConfiguration), new UnsubscribeChannelCommand(12));
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    for (final AbstractAPICommand command : commands) {
        final String commandValue = command.getCommand(bitfinexApiBroker);
        Assert.assertNotNull(commandValue);
        Assert.assertTrue(commandValue.length() > 10);
    }
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand) OrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand) SubscribeOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand) CancelOrderGroupCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) UnsubscribeChannelCommand(com.github.jnidzwetzki.bitfinex.v2.commands.UnsubscribeChannelCommand) SubscribeTradesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) AbstractAPICommand(com.github.jnidzwetzki.bitfinex.v2.commands.AbstractAPICommand) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand) PingCommand(com.github.jnidzwetzki.bitfinex.v2.commands.PingCommand) SubscribeCandlesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) SubscribeTickerCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) BitfinexOrder(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder) AuthCommand(com.github.jnidzwetzki.bitfinex.v2.commands.AuthCommand) SubscribeRawOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand) Test(org.junit.Test)

Example 9 with BitfinexExecutedTradeSymbol

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

the class QuoteManager method subscribeExecutedTrades.

/**
 * Subscribe a executed trade channel
 * @param currencyPair
 * @param orderBookPrecision
 * @param orderBookFrequency
 * @param pricePoints
 */
public void subscribeExecutedTrades(final BitfinexExecutedTradeSymbol tradeSymbol) {
    final SubscribeTradesCommand subscribeOrderbookCommand = new SubscribeTradesCommand(tradeSymbol);
    bitfinexApiBroker.sendCommand(subscribeOrderbookCommand);
}
Also used : SubscribeTradesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand)

Example 10 with BitfinexExecutedTradeSymbol

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

the class ExecutedTradeHandler method handleEntry.

/**
 * Handle a new executed trade entry
 * @param bitfinexApiBroker
 * @param symbol
 * @param jsonArray
 */
private void handleEntry(final BitfinexApiBroker bitfinexApiBroker, final BitfinexExecutedTradeSymbol symbol, final JSONArray jsonArray) {
    final ExecutedTrade executedTrade = new ExecutedTrade();
    final long id = jsonArray.getNumber(0).longValue();
    executedTrade.setId(id);
    final long timestamp = jsonArray.getNumber(1).longValue();
    executedTrade.setTimestamp(timestamp);
    final BigDecimal amount = jsonArray.getBigDecimal(2);
    executedTrade.setAmount(amount);
    // Funding or Currency
    if (jsonArray.optNumber(4) != null) {
        final BigDecimal rate = jsonArray.getBigDecimal(3);
        executedTrade.setRate(rate);
        final int period = jsonArray.getNumber(4).intValue();
        executedTrade.setPeriod(period);
    } else {
        final BigDecimal price = jsonArray.getBigDecimal(3);
        executedTrade.setPrice(price);
    }
    bitfinexApiBroker.getQuoteManager().handleExecutedTradeEntry(symbol, executedTrade);
}
Also used : ExecutedTrade(com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade) BigDecimal(java.math.BigDecimal)

Aggregations

BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)8 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)4 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)4 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)4 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)4 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)4 JSONArray (org.json.JSONArray)4 Test (org.junit.Test)4 ExecutedTradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler)3 SubscribeTradesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand)3 QuoteManager (com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 SubscribeCandlesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand)2 SubscribeOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand)2 SubscribeRawOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand)2 SubscribeTickerCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand)2 UnsubscribeChannelCommand (com.github.jnidzwetzki.bitfinex.v2.commands.UnsubscribeChannelCommand)2 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)2 ExecutedTrade (com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade)2 ExecutorService (java.util.concurrent.ExecutorService)2