Search in sources :

Example 1 with OrderStatus

use of org.knowm.xchange.dto.Order.OrderStatus in project XChange by knowm.

the class GeminiAdapters method adaptOrders.

public static OpenOrders adaptOrders(GeminiOrderStatusResponse[] activeOrders, CurrencyPair currencyPair) {
    List<LimitOrder> limitOrders = new ArrayList<>(activeOrders.length);
    for (GeminiOrderStatusResponse order : activeOrders) {
        CurrencyPair currentCurrencyPair = adaptCurrencyPair(order.getSymbol());
        if (currencyPair != null && !currentCurrencyPair.equals(currencyPair)) {
            continue;
        }
        OrderType orderType = order.getSide().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
        Date timestamp = convertBigDecimalTimestampToDate(new BigDecimal(order.getTimestamp()));
        OrderStatus status = OrderStatus.NEW;
        if (order.isCancelled()) {
            status = OrderStatus.CANCELED;
        } else if (order.getExecutedAmount().signum() > 0 && order.getExecutedAmount().compareTo(order.getOriginalAmount()) < 0) {
            status = OrderStatus.PARTIALLY_FILLED;
        } else if (order.getExecutedAmount().compareTo(order.getOriginalAmount()) == 0) {
            status = OrderStatus.FILLED;
        }
        LimitOrder limitOrder = new LimitOrder(orderType, order.getOriginalAmount(), currentCurrencyPair, String.valueOf(order.getId()), timestamp, order.getPrice(), order.getAvgExecutionPrice(), order.getExecutedAmount(), null, status);
        limitOrders.add(limitOrder);
    }
    return new OpenOrders(limitOrders);
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with OrderStatus

use of org.knowm.xchange.dto.Order.OrderStatus in project XChange by knowm.

the class KucoinAdapters method adaptOrder.

public static Order adaptOrder(OrderResponse order) {
    OrderType orderType = adaptSide(order.getSide());
    CurrencyPair currencyPair = adaptCurrencyPair(order.getSymbol());
    OrderStatus status;
    if (order.isCancelExist()) {
        status = CANCELED;
    } else if (order.isActive()) {
        if (order.getDealSize().signum() == 0) {
            status = NEW;
        } else {
            status = PARTIALLY_FILLED;
        }
    } else {
        status = UNKNOWN;
    }
    Order.Builder builder;
    if (StringUtils.isNotEmpty(order.getStop())) {
        BigDecimal limitPrice = order.getPrice();
        if (limitPrice != null && limitPrice.compareTo(BigDecimal.ZERO) == 0) {
            limitPrice = null;
        }
        builder = new StopOrder.Builder(orderType, currencyPair).limitPrice(limitPrice).stopPrice(order.getStopPrice());
    } else {
        builder = new LimitOrder.Builder(orderType, currencyPair).limitPrice(order.getPrice());
    }
    builder = builder.averagePrice(order.getDealSize().compareTo(BigDecimal.ZERO) == 0 ? MoreObjects.firstNonNull(order.getPrice(), order.getStopPrice()) : order.getDealFunds().divide(order.getDealSize(), RoundingMode.HALF_UP)).cumulativeAmount(order.getDealSize()).fee(order.getFee()).id(order.getId()).orderStatus(status).originalAmount(order.getSize()).remainingAmount(order.getSize().subtract(order.getDealSize())).timestamp(order.getCreatedAt());
    if (StringUtils.isNotEmpty(order.getTimeInForce())) {
        builder.flag(TimeInForce.getTimeInForce(order.getTimeInForce()));
    }
    return builder instanceof StopOrder.Builder ? ((StopOrder.Builder) builder).build() : ((LimitOrder.Builder) builder).build();
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) StopOrder(org.knowm.xchange.dto.trade.StopOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with OrderStatus

use of org.knowm.xchange.dto.Order.OrderStatus in project XChange by knowm.

the class BitfinexAdapters method adaptOrders.

public static OpenOrders adaptOrders(BitfinexOrderStatusResponse[] activeOrders) {
    List<LimitOrder> limitOrders = new ArrayList<>();
    List<Order> hiddenOrders = new ArrayList<>();
    for (BitfinexOrderStatusResponse order : activeOrders) {
        OrderType orderType = order.getSide().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
        OrderStatus status = adaptOrderStatus(order);
        CurrencyPair currencyPair = adaptCurrencyPair(order.getSymbol());
        Date timestamp = convertBigDecimalTimestampToDate(order.getTimestamp());
        Supplier<MarketOrder> marketOrderCreator = () -> new MarketOrder(orderType, order.getOriginalAmount(), currencyPair, String.valueOf(order.getId()), timestamp, order.getAvgExecutionPrice(), order.getExecutedAmount(), null, status);
        Supplier<LimitOrder> limitOrderCreator = () -> new LimitOrder(orderType, order.getOriginalAmount(), currencyPair, String.valueOf(order.getId()), timestamp, order.getPrice(), order.getAvgExecutionPrice(), order.getExecutedAmount(), null, status);
        Supplier<StopOrder> stopOrderCreator = () -> new StopOrder(orderType, order.getOriginalAmount(), currencyPair, String.valueOf(order.getId()), timestamp, order.getPrice(), null, order.getAvgExecutionPrice(), order.getExecutedAmount(), status);
        LimitOrder limitOrder = null;
        StopOrder stopOrder = null;
        MarketOrder marketOrder = null;
        Optional<BitfinexOrderType> bitfinexOrderType = Arrays.stream(BitfinexOrderType.values()).filter(v -> v.getValue().equals(order.getType())).findFirst();
        if (bitfinexOrderType.isPresent()) {
            switch(bitfinexOrderType.get()) {
                case FILL_OR_KILL:
                    limitOrder = limitOrderCreator.get();
                    limitOrder.addOrderFlag(BitfinexOrderFlags.FILL_OR_KILL);
                    break;
                case MARGIN_FILL_OR_KILL:
                    limitOrder = limitOrderCreator.get();
                    limitOrder.addOrderFlag(BitfinexOrderFlags.FILL_OR_KILL);
                    limitOrder.addOrderFlag(BitfinexOrderFlags.MARGIN);
                    break;
                case MARGIN_LIMIT:
                    limitOrder = limitOrderCreator.get();
                    limitOrder.addOrderFlag(BitfinexOrderFlags.MARGIN);
                    break;
                case MARGIN_STOP:
                    stopOrder = stopOrderCreator.get();
                    stopOrder.addOrderFlag(BitfinexOrderFlags.STOP);
                    stopOrder.addOrderFlag(BitfinexOrderFlags.MARGIN);
                    break;
                case MARGIN_STOP_LIMIT:
                    stopLimitWarning();
                    stopOrder = stopOrderCreator.get();
                    stopOrder.addOrderFlag(BitfinexOrderFlags.STOP);
                    stopOrder.addOrderFlag(BitfinexOrderFlags.MARGIN);
                    break;
                case MARGIN_TRAILING_STOP:
                    limitOrder = limitOrderCreator.get();
                    limitOrder.addOrderFlag(BitfinexOrderFlags.TRAILING_STOP);
                    limitOrder.addOrderFlag(BitfinexOrderFlags.MARGIN);
                    break;
                case STOP:
                    stopOrder = stopOrderCreator.get();
                    stopOrder.addOrderFlag(BitfinexOrderFlags.STOP);
                    break;
                case STOP_LIMIT:
                    stopLimitWarning();
                    stopOrder = stopOrderCreator.get();
                    stopOrder.addOrderFlag(BitfinexOrderFlags.STOP);
                    break;
                case TRAILING_STOP:
                    limitOrder = limitOrderCreator.get();
                    limitOrder.addOrderFlag(BitfinexOrderFlags.TRAILING_STOP);
                    break;
                case LIMIT:
                    limitOrder = limitOrderCreator.get();
                    break;
                case MARGIN_MARKET:
                case MARKET:
                    marketOrder = marketOrderCreator.get();
                    break;
                default:
                    log.warn("Unhandled Bitfinex order type [{}]. Defaulting to limit order", order.getType());
                    limitOrder = limitOrderCreator.get();
                    break;
            }
        } else {
            log.warn("Unknown Bitfinex order type [{}]. Defaulting to limit order", order.getType());
            limitOrder = limitOrderCreator.get();
        }
        if (limitOrder != null) {
            limitOrders.add(limitOrder);
        } else if (stopOrder != null) {
            hiddenOrders.add(stopOrder);
        } else if (marketOrder != null) {
            hiddenOrders.add(marketOrder);
        }
    }
    return new OpenOrders(limitOrders, hiddenOrders);
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) Order(org.knowm.xchange.dto.Order) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) StopOrder(org.knowm.xchange.dto.trade.StopOrder) Arrays(java.util.Arrays) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date) BitfinexBalancesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexBalancesResponse) LoggerFactory(org.slf4j.LoggerFactory) BitfinexLendLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendLevel) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BitfinexDepositWithdrawalHistoryResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexDepositWithdrawalHistoryResponse) Map(java.util.Map) BitfinexTrade(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade) BitfinexPublicTrade(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) Wallet(org.knowm.xchange.dto.account.Wallet) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) MathContext(java.math.MathContext) BitfinexAccountInfosResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse) BitfinexTradeResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse) Collection(java.util.Collection) Set(java.util.Set) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) Stream(java.util.stream.Stream) BitfinexLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel) Entry(java.util.Map.Entry) Optional(java.util.Optional) BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker) BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth) Movement(org.knowm.xchange.bitfinex.v2.dto.account.Movement) CurrencyPairDeserializer(org.knowm.xchange.utils.jackson.CurrencyPairDeserializer) BitfinexUtils(org.knowm.xchange.bitfinex.v1.BitfinexUtils) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) Supplier(java.util.function.Supplier) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) BitfinexTickerFundingCurrency(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerFundingCurrency) Order(org.knowm.xchange.dto.Order) BitfinexSymbolDetail(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Ticker(org.knowm.xchange.dto.marketdata.Ticker) Logger(org.slf4j.Logger) Fee(org.knowm.xchange.dto.account.Fee) BitfinexAccountFeesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Trades(org.knowm.xchange.dto.marketdata.Trades) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder) BitfinexTradingFeeResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Trade(org.knowm.xchange.dto.marketdata.Trade) BitfinexOrderFlags(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderFlags) BitfinexTickerTraidingPair(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerTraidingPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) WalletHealth(org.knowm.xchange.dto.meta.WalletHealth) DateUtils(org.knowm.xchange.utils.DateUtils) ArrayList(java.util.ArrayList) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Date(java.util.Date) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) StopOrder(org.knowm.xchange.dto.trade.StopOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 4 with OrderStatus

use of org.knowm.xchange.dto.Order.OrderStatus in project XChange by knowm.

the class CoinoneAdapters method adaptOrderInfo.

public static Order adaptOrderInfo(CoinoneOrderInfoResponse coinoneOrderInfoResponse) {
    ArrayList<Order> orders = new ArrayList<Order>();
    OrderStatus status = OrderStatus.NEW;
    if (coinoneOrderInfoResponse.getStatus().equals("live"))
        status = OrderStatus.NEW;
    else if (coinoneOrderInfoResponse.getStatus().equals("filled"))
        status = OrderStatus.FILLED;
    else if (coinoneOrderInfoResponse.getStatus().equals("partially_filled"))
        status = OrderStatus.PARTIALLY_FILLED;
    else
        status = OrderStatus.CANCELED;
    CoinoneOrderInfo orderInfo = coinoneOrderInfoResponse.getInfo();
    OrderType type = orderInfo.getType().equals("ask") ? OrderType.ASK : OrderType.BID;
    BigDecimal originalAmount = orderInfo.getQty();
    CurrencyPair currencyPair = new CurrencyPair(new Currency(orderInfo.getCurrency().toUpperCase()), Currency.KRW);
    String orderId = orderInfo.getOrderId();
    BigDecimal cumulativeAmount = orderInfo.getQty().subtract(orderInfo.getRemainQty());
    BigDecimal price = orderInfo.getPrice();
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(orderInfo.getTimestamp());
    LimitOrder order = new LimitOrder(type, originalAmount, currencyPair, orderId, cal.getTime(), price, price, cumulativeAmount, orderInfo.getFee(), status);
    return order;
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) Currency(org.knowm.xchange.currency.Currency) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) CoinoneOrderInfo(org.knowm.xchange.coinone.dto.trade.CoinoneOrderInfo) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 5 with OrderStatus

use of org.knowm.xchange.dto.Order.OrderStatus in project XChange by knowm.

the class CoinsuperAdapters method adaptOrder.

/**
 * There is no method to discern market versus limit order type - so this returns a generic
 * GenericOrder as a status
 *
 * @param
 * @return
 */
public static CoinsuperGenericOrder adaptOrder(String orderId, OrderList orderList) {
    BigDecimal averagePrice = new BigDecimal(orderList.getPriceLimit());
    BigDecimal cumulativeAmount = new BigDecimal(orderList.getQuantity());
    BigDecimal totalFee = new BigDecimal(orderList.getFee());
    BigDecimal amount = new BigDecimal(orderList.getQuantity());
    OrderType action = OrderType.ASK;
    if (orderList.getAction().equals("Buy")) {
        action = OrderType.BID;
    }
    // Order Status UNDEAL:Not Executed,PARTDEAL:Partially Executed,DEAL:Order Complete,CANCEL:
    // Canceled
    OrderStatus orderStatus = OrderStatus.PENDING_NEW;
    if (orderList.getState().equals("UNDEAL")) {
        orderStatus = OrderStatus.PENDING_NEW;
    } else if (orderList.getState().equals("Canceled")) {
        orderStatus = OrderStatus.CANCELED;
    }
    CoinsuperGenericOrder coinsuperGenericOrder = new CoinsuperGenericOrder(action, amount, new CurrencyPair(orderList.getSymbol()), orderId, CommonUtil.timeStampToDate(orderList.getUtcCreate()), averagePrice, cumulativeAmount, totalFee, orderStatus);
    return coinsuperGenericOrder;
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) CoinsuperGenericOrder(org.knowm.xchange.coinsuper.dto.trade.CoinsuperGenericOrder) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

OrderStatus (org.knowm.xchange.dto.Order.OrderStatus)10 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)9 OrderType (org.knowm.xchange.dto.Order.OrderType)9 BigDecimal (java.math.BigDecimal)8 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)7 Date (java.util.Date)5 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)4 ArrayList (java.util.ArrayList)3 Order (org.knowm.xchange.dto.Order)3 Currency (org.knowm.xchange.currency.Currency)2 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IOException (java.io.IOException)1 MathContext (java.math.MathContext)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1