Search in sources :

Example 6 with OrderStatus

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

the class BitmexAdapters method adaptLimitOrder.

public static LimitOrder adaptLimitOrder(BitmexOrder bitmexOrder, String id) {
    BitmexOrderDescription orderDescription = bitmexOrder.getOrderDescription();
    OrderType type = adaptOrderType(orderDescription.getType());
    BigDecimal originalAmount = bitmexOrder.getVolume();
    BigDecimal filledAmount = bitmexOrder.getVolumeExecuted();
    CurrencyPair pair = BitmexAdapters.adaptSymbolToCurrencyPair(orderDescription.getAssetPair());
    Date timestamp = new Date((long) (bitmexOrder.getOpenTimestamp() * 1000L));
    OrderStatus status = adaptOrderStatus(bitmexOrder.getStatus());
    if (status == OrderStatus.NEW && filledAmount.compareTo(BigDecimal.ZERO) > 0 && filledAmount.compareTo(originalAmount) < 0) {
        status = OrderStatus.PARTIALLY_FILLED;
    }
    return new LimitOrder(type, originalAmount, pair, id, timestamp, orderDescription.getPrice(), orderDescription.getPrice(), filledAmount, bitmexOrder.getFee(), status);
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) BitmexOrderStatus(org.knowm.xchange.bitmex.dto.trade.BitmexOrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) BitmexOrderDescription(org.knowm.xchange.bitmex.dto.trade.BitmexOrderDescription) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 7 with OrderStatus

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

the class CoinbaseProAdapters method adaptOrderStatuses.

public static OrderStatus[] adaptOrderStatuses(CoinbaseProOrder[] orders) {
    OrderStatus[] orderStatuses = new OrderStatus[orders.length];
    int i = 0;
    for (CoinbaseProOrder coinbaseProOrder : orders) {
        orderStatuses[i++] = adaptOrderStatus(coinbaseProOrder);
    }
    return orderStatuses;
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) CoinbaseProOrder(org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder)

Example 8 with OrderStatus

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

the class GeminiAdapters method adaptOrder.

public static Order adaptOrder(GeminiOrderStatusResponse geminiOrderStatusResponse) {
    Long id = geminiOrderStatusResponse.getId();
    CurrencyPair currencyPair = adaptCurrencyPair(geminiOrderStatusResponse.getSymbol());
    BigDecimal averageExecutionPrice = geminiOrderStatusResponse.getAvgExecutionPrice();
    BigDecimal executedAmount = geminiOrderStatusResponse.getExecutedAmount();
    BigDecimal originalAmount = geminiOrderStatusResponse.getOriginalAmount();
    OrderType orderType = (geminiOrderStatusResponse.getSide().equals("buy")) ? OrderType.BID : OrderType.ASK;
    OrderStatus orderStatus = adaptOrderstatus(geminiOrderStatusResponse);
    Date timestamp = new Date(geminiOrderStatusResponse.getTimestampms());
    // Calculate Fees in counter currency
    BigDecimal fee = null;
    if (geminiOrderStatusResponse.getTrades() != null && geminiOrderStatusResponse.getTrades().length > 0) {
        for (GeminiOrderStatusResponse.OrderStatusTradeDetails trade : geminiOrderStatusResponse.getTrades()) {
            if (fee == null) {
                fee = trade.getFeeAmount();
            } else {
                fee.add(trade.getFeeAmount());
            }
        }
    }
    if (geminiOrderStatusResponse.getType().contains("limit")) {
        BigDecimal limitPrice = geminiOrderStatusResponse.getPrice();
        return new LimitOrder(orderType, originalAmount, currencyPair, id.toString(), timestamp, limitPrice, averageExecutionPrice, executedAmount, fee, orderStatus, geminiOrderStatusResponse.getClientOrderId());
    } else if (geminiOrderStatusResponse.getType().contains("market")) {
        return new MarketOrder(orderType, originalAmount, currencyPair, id.toString(), timestamp, averageExecutionPrice, executedAmount, fee, orderStatus, geminiOrderStatusResponse.getClientOrderId());
    }
    throw new NotYetImplementedForExchangeException();
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 9 with OrderStatus

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

the class KrakenAdapters method adaptOrder.

public static Order adaptOrder(String orderId, KrakenOrder krakenOrder) {
    OrderType orderType = adaptOrderType(krakenOrder.getOrderDescription().getType());
    CurrencyPair currencyPair = adaptCurrencyPair(krakenOrder.getOrderDescription().getAssetPair());
    OrderStatus orderStatus = adaptOrderStatus(krakenOrder.getStatus());
    BigDecimal filledAmount = krakenOrder.getVolumeExecuted();
    BigDecimal originalAmount = krakenOrder.getVolume();
    BigDecimal fee = krakenOrder.getFee();
    if (orderStatus == OrderStatus.NEW && filledAmount.compareTo(BigDecimal.ZERO) > 0 && filledAmount.compareTo(originalAmount) < 0) {
        orderStatus = OrderStatus.PARTIALLY_FILLED;
    }
    // eg: "opentm":1519731205.9987
    Double time = krakenOrder.getOpenTimestamp() * 1000;
    Date timestamp = new Date(time.longValue());
    if (krakenOrder.getOrderDescription().getOrderType().equals(KrakenOrderType.LIMIT))
        return new LimitOrder(orderType, krakenOrder.getVolume(), currencyPair, orderId, timestamp, krakenOrder.getOrderDescription().getPrice(), krakenOrder.getPrice(), krakenOrder.getVolumeExecuted(), fee, orderStatus, krakenOrder.getUserRefId());
    if (krakenOrder.getOrderDescription().getOrderType().equals(KrakenOrderType.MARKET))
        return new MarketOrder(orderType, krakenOrder.getVolume(), currencyPair, orderId, timestamp, krakenOrder.getPrice(), krakenOrder.getVolumeExecuted(), fee, orderStatus, krakenOrder.getUserRefId());
    throw new NotYetImplementedForExchangeException();
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) KrakenOrderStatus(org.knowm.xchange.kraken.dto.trade.KrakenOrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) KrakenOrderType(org.knowm.xchange.kraken.dto.trade.KrakenOrderType) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 10 with OrderStatus

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

the class LatokenAdapters method adaptOrder.

public static LimitOrder adaptOrder(Exchange exchange, LatokenOrder order) {
    OrderType type = adaptOrderType(order.getSide());
    CurrencyPair currencyPair = adaptCurrencyPair(exchange, order.getSymbol());
    OrderStatus orderStatus = adaptOrderStatus(order.getOrderStatus());
    return new LimitOrder.Builder(type, currencyPair).originalAmount(order.getAmount()).id(order.getOrderId()).timestamp(order.getTimeCreated()).limitPrice(order.getPrice()).cumulativeAmount(order.getExecutedAmount()).fee(BigDecimal.ZERO).orderStatus(orderStatus).build();
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) LatokenOrderStatus(org.knowm.xchange.latoken.dto.trade.LatokenOrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) 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