Search in sources :

Example 71 with APIException

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

the class ExecutedTradeHandler method handleChannelData.

@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
    final BitfinexExecutedTradeSymbol configuration = (BitfinexExecutedTradeSymbol) channelSymbol;
    try {
        // Snapshots contain multiple executes entries, updates only one
        if (jsonArray.get(0) instanceof JSONArray) {
            for (int pos = 0; pos < jsonArray.length(); pos++) {
                final JSONArray parts = jsonArray.getJSONArray(pos);
                handleEntry(bitfinexApiBroker, configuration, parts);
            }
        } else {
            handleEntry(bitfinexApiBroker, configuration, jsonArray);
        }
    } catch (JSONException e) {
        throw new APIException(e);
    }
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 72 with APIException

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

the class OrderbookHandler method handleChannelData.

@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
    final OrderbookConfiguration configuration = (OrderbookConfiguration) channelSymbol;
    // Example: [13182,1,-0.1]
    try {
        // Snapshots contain multiple Orderbook entries, updates only one
        if (jsonArray.get(0) instanceof JSONArray) {
            for (int pos = 0; pos < jsonArray.length(); pos++) {
                final JSONArray parts = jsonArray.getJSONArray(pos);
                handleEntry(bitfinexApiBroker, configuration, parts);
            }
        } else {
            handleEntry(bitfinexApiBroker, configuration, jsonArray);
        }
    } catch (JSONException e) {
        throw new APIException(e);
    }
}
Also used : APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 73 with APIException

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

the class OrderManager method cancelOrderGroup.

/**
 * Cancel the given order group
 * @param cid
 * @param date
 * @throws APIException
 */
public void cancelOrderGroup(final int id) throws APIException {
    final ConnectionCapabilities capabilities = bitfinexApiBroker.getCapabilities();
    if (!capabilities.isHavingOrdersWriteCapability()) {
        throw new APIException("Unable to cancel order group " + id + " connection has not enough capabilities: " + capabilities);
    }
    logger.info("Cancel order group {}", id);
    final CancelOrderGroupCommand cancelOrder = new CancelOrderGroupCommand(id);
    bitfinexApiBroker.sendCommand(cancelOrder);
}
Also used : APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) ConnectionCapabilities(com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities) CancelOrderGroupCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand)

Example 74 with APIException

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

the class OrderManager method cancelOrderAndWaitForCompletion.

/**
 * Cancel a order
 * @param id
 * @throws APIException, InterruptedException
 */
public void cancelOrderAndWaitForCompletion(final long id) throws APIException, InterruptedException {
    final ConnectionCapabilities capabilities = bitfinexApiBroker.getCapabilities();
    if (!capabilities.isHavingOrdersWriteCapability()) {
        throw new APIException("Unable to cancel order " + id + " connection has not enough capabilities: " + capabilities);
    }
    final Callable<Boolean> orderCallable = () -> cancelOrderOnAPI(id);
    // See comment in placeOrder()
    final Retryer<Boolean> retryer = new Retryer<>(ORDER_RETRIES, RETRY_DELAY_IN_MS, orderCallable);
    retryer.execute();
    if (retryer.getNeededExecutions() > 1) {
        logger.info("Nedded {} executions for canceling the order", retryer.getNeededExecutions());
    }
    if (!retryer.isSuccessfully()) {
        final Exception lastException = retryer.getLastException();
        if (lastException == null) {
            throw new APIException("Unable to cancel order");
        } else {
            throw new APIException(lastException);
        }
    }
}
Also used : APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) ConnectionCapabilities(com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities) Retryer(org.bboxdb.commons.Retryer) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException)

Example 75 with APIException

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

the class OrderManager method cancelOrder.

/**
 * Cancel the given order
 * @param cid
 * @param date
 * @throws APIException
 */
public void cancelOrder(final long id) throws APIException {
    final ConnectionCapabilities capabilities = bitfinexApiBroker.getCapabilities();
    if (!capabilities.isHavingOrdersWriteCapability()) {
        throw new APIException("Unable to cancel order " + id + " connection has not enough capabilities: " + capabilities);
    }
    logger.info("Cancel order with id {}", id);
    final CancelOrderCommand cancelOrder = new CancelOrderCommand(id);
    bitfinexApiBroker.sendCommand(cancelOrder);
}
Also used : APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) ConnectionCapabilities(com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand)

Aggregations

BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)33 Test (org.junit.Test)33 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)25 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)20 JSONArray (org.json.JSONArray)20 CountDownLatch (java.util.concurrent.CountDownLatch)14 ExchangeOrder (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder)12 HashMap (java.util.HashMap)11 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)10 BitfinexOrder (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder)9 ConnectionCapabilities (com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities)9 Wallet (com.github.jnidzwetzki.bitfinex.v2.entity.Wallet)9 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)9 OrderManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager)8 QuoteManager (com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager)8 CurrencyEntry (com.github.jnidzwetzki.cryptobot.CurrencyEntry)8 BasePortfolioManager (com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager)8 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)7 PortfolioManager (com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager)7 ArrayList (java.util.ArrayList)7