Search in sources :

Example 1 with OkCoinTradeResult

use of org.knowm.xchange.okcoin.dto.trade.OkCoinTradeResult in project XChange by knowm.

the class OkCoinTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
    if (!(orderParams instanceof CancelOrderByIdParams) || !(orderParams instanceof CancelOrderByCurrencyPair)) {
        throw new UnsupportedOperationException("Cancelling an order is only available for a single market and a single id.");
    }
    long id = Long.valueOf(((CancelOrderByIdParams) orderParams).getOrderId());
    String symbol = OkCoinAdapters.adaptSymbol(((CancelOrderByCurrencyPair) orderParams).getCurrencyPair());
    OkCoinTradeResult cancelResult = cancelOrder(id, symbol);
    return id == cancelResult.getOrderId();
}
Also used : OkCoinTradeResult(org.knowm.xchange.okcoin.dto.trade.OkCoinTradeResult) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)

Example 2 with OkCoinTradeResult

use of org.knowm.xchange.okcoin.dto.trade.OkCoinTradeResult in project XChange by knowm.

the class OkCoinFuturesTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
    OkCoinFuturesCancelOrderParams myParams = (OkCoinFuturesCancelOrderParams) orderParams;
    CurrencyPair currencyPair = myParams.getCurrencyPair();
    FuturesContract reqFuturesContract = myParams.futuresContract;
    long orderId = myParams.getOrderId() != null ? Long.valueOf(myParams.getOrderId()) : -1;
    boolean ret = false;
    try {
        OkCoinTradeResult cancelResult = futuresCancelOrder(orderId, OkCoinAdapters.adaptSymbol(currencyPair), reqFuturesContract);
        if (orderId == cancelResult.getOrderId()) {
            ret = true;
        }
    } catch (ExchangeException e) {
        if (e.getMessage().equals(OkCoinUtils.getErrorMessage(1009)) || e.getMessage().equals(OkCoinUtils.getErrorMessage(20015))) {
        // order not found.
        } else
            throw e;
    }
    return ret;
}
Also used : OkCoinTradeResult(org.knowm.xchange.okcoin.dto.trade.OkCoinTradeResult) FuturesContract(org.knowm.xchange.okcoin.FuturesContract) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

OkCoinTradeResult (org.knowm.xchange.okcoin.dto.trade.OkCoinTradeResult)2 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)1 FuturesContract (org.knowm.xchange.okcoin.FuturesContract)1 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)1 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)1 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)1