Search in sources :

Example 11 with Trade

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

use of com.github.jnidzwetzki.bitfinex.v2.entity.Trade 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);
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray)

Example 13 with Trade

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

Example 14 with Trade

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

Test (org.junit.Test)5 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)4 JSONArray (org.json.JSONArray)4 TradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler)3 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)3 BitfinexOrder (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder)3 Trade (com.github.jnidzwetzki.cryptobot.entity.Trade)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutedTradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler)2 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)2 QuoteManager (com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager)2 ArrayList (java.util.ArrayList)2 Session (org.hibernate.Session)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 SubscribeTradesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand)1