use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class SubscribedCallback method handleBookCallback.
/**
* Handle the book callback
*
* @param bitfinexApiBroker
* @param jsonObject
* @param channelId
*/
private void handleBookCallback(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject, final int channelId) {
if ("R0".equals(jsonObject.getString("prec"))) {
final RawOrderbookConfiguration configuration = RawOrderbookConfiguration.fromJSON(jsonObject);
logger.info("Registering raw book {} on channel {}", jsonObject, channelId);
bitfinexApiBroker.addToChannelSymbolMap(channelId, configuration);
} else {
final OrderbookConfiguration configuration = OrderbookConfiguration.fromJSON(jsonObject);
logger.info("Registering book {} on channel {}", jsonObject, channelId);
bitfinexApiBroker.addToChannelSymbolMap(channelId, configuration);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class UnsubscribedCallback method handleChannelData.
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject) throws APIException {
final int channelId = jsonObject.getInt("chanId");
final BitfinexStreamSymbol symbol = bitfinexApiBroker.getFromChannelSymbolMap(channelId);
logger.info("Channel {} ({}) is unsubscribed", channelId, symbol);
bitfinexApiBroker.removeChannel(channelId);
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project crypto-bot by jnidzwetzki.
the class DonchianBot method registerTicker.
/**
* Register the ticker
* @throws InterruptedException
* @throws APIException
*/
protected void registerTicker() throws InterruptedException, APIException {
logger.info("Register ticker");
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
// Subscribe ticket on all connections (needed for wallet in USD conversion)
for (final BitfinexApiBroker bitfinexApiBroker : apiBrokerList) {
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency);
bitfinexApiBroker.getQuoteManager().subscribeTicker(symbol);
logger.info("Wait for ticker");
while (!bitfinexApiBroker.isTickerActive(symbol)) {
Thread.sleep(100);
}
}
// Use only one connection for merging
tickMerger.put(currency, new BarMerger(currency, TIMEFRAME, (s, t) -> barDoneCallback(s, t)));
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency);
apiBrokerList.get(0).getQuoteManager().registerTickCallback(symbol, (s, c) -> handleBarCallback(s, c));
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project crypto-bot by jnidzwetzki.
the class TestCapitalAllocation method buildPortfolioManager.
/**
* Build the portfolio manager
* @return
* @throws APIException
*/
private PortfolioManager buildPortfolioManager() throws APIException {
final Collection<Wallet> wallets = new ArrayList<>();
wallets.add(new Wallet(Wallet.WALLET_TYPE_EXCHANGE, "USD", 1000, 0, 1000));
final BitfinexApiBroker apiBroker = Mockito.mock(BitfinexApiBroker.class);
final WalletManager walletManager = Mockito.mock(WalletManager.class);
Mockito.when(walletManager.getWallets()).thenReturn(wallets);
Mockito.when(apiBroker.getWalletManager()).thenReturn(walletManager);
return new BasePortfolioManager(apiBroker, 0.05);
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CommandsTest method testOrderCommand.
/**
* Test the order command
* @throws CommandException
*/
@Test
public void testOrderCommand() throws CommandException {
final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.EXCHANGE_STOP, 2).setHidden().setPostOnly().withPrice(12).withPriceAuxLimit(23).withPriceTrailing(23).withGroupId(4).build();
final OrderCommand command = new OrderCommand(order);
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
final String commandValue = command.getCommand(bitfinexApiBroker);
Assert.assertNotNull(commandValue);
Assert.assertTrue(commandValue.length() > 10);
}
Aggregations