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);
}
}
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);
}
}
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);
}
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);
}
}
}
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);
}
Aggregations