Search in sources :

Example 6 with ConnectionCapabilities

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

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

ConnectionCapabilities (com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities)7 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)5 CancelOrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand)2 Retryer (org.bboxdb.commons.Retryer)2 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 AuthCallbackHandler (com.github.jnidzwetzki.bitfinex.v2.callback.command.AuthCallbackHandler)1 CancelOrderGroupCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand)1 OrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1