public static Builder from(Order order) { return new Builder(order.getType(), order.getCurrencyPair()) .originalAmount(order.getOriginalAmount()) .timestamp(order.getTimestamp()) .id(order.getId()) .flags(order.getOrderFlags()) .averagePrice(order.getAveragePrice()) .orderStatus(order.getStatus()); }
public final UserTrades getOrderTrades(Order order) throws IOException { return getOrderTrades(order.getId(), order.getCurrencyPair()); }
protected final void verifyOrder(Order order, ExchangeMetaData exchangeMetaData) { CurrencyPairMetaData metaData = exchangeMetaData.getCurrencyPairs().get(order.getCurrencyPair()); if (metaData == null) { throw new IllegalArgumentException("Invalid CurrencyPair"); } BigDecimal originalAmount = order.getOriginalAmount(); if (originalAmount == null) { throw new IllegalArgumentException("Missing originalAmount"); } BigDecimal amount = originalAmount.stripTrailingZeros(); BigDecimal minimumAmount = metaData.getMinimumAmount(); if (minimumAmount != null) { if (amount.scale() > minimumAmount.scale()) { throw new IllegalArgumentException("Unsupported amount scale " + amount.scale()); } else if (amount.compareTo(minimumAmount) < 0) { throw new IllegalArgumentException("Order amount less than minimum"); } } } }
public static Builder from(final Order order) { final Builder builder = new Builder(order.getType(), order.getCurrencyPair()); builder .id(order.getId()) .orderType(order.getType()) .originalAmount(order.getOriginalAmount()) .currencyPair(order.getCurrencyPair()) .timestamp(order.getTimestamp()) .id(order.getId()) .flags(order.getOrderFlags()); if (order instanceof LimitOrder) { final LimitOrder limitOrder = (LimitOrder) order; builder.limitPrice(limitOrder.getLimitPrice()); } if (order instanceof RippleLimitOrder) { final RippleLimitOrder ripple = (RippleLimitOrder) order; builder .baseCounterparty(ripple.getBaseCounterparty()) .counterCounterparty(ripple.getCounterCounterparty()); } return builder; }
private String placeOrder( OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice, TimeInForce tif) throws IOException { try { Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow"); BinanceNewOrder newOrder = newOrder( order.getCurrencyPair(), BinanceAdapters.convert(order.getType()), type, tif, order.getOriginalAmount(), limitPrice, getClientOrderId(order), stopPrice, null, recvWindow, getTimestamp()); return Long.toString(newOrder.orderId); } catch (BinanceException e) { throw BinanceErrorAdapter.adapt(e); } }
@AssistedInject public SpecificOrder(@Assisted org.knowm.xchange.dto.Order exchangeOrder, @Assisted Market market, @Assisted @Nullable Portfolio portfolio) { super(new Instant(exchangeOrder.getTimestamp())); this.getId(); this.orderUpdates = new CopyOnWriteArrayList<OrderUpdate>(); this.transactions = new CopyOnWriteArrayList<Transaction>(); this.market = market; this.remoteKey = exchangeOrder.getId(); (exchangeOrder.getType() != null && (exchangeOrder.getType() == OrderType.ASK || exchangeOrder.getType() == OrderType.EXIT_BID) ? exchangeOrder.getOriginalAmount().negate() : exchangeOrder.getOriginalAmount()), market.getVolumeBasis()); double minimumOrderSize = unadjustedVolumeCount < 0 ? market.getMinimumOrderSize(market) * -1 : market.getMinimumOrderSize(market); super.setPortfolio(portfolio); this.placementCount = 1; this.positionEffect = (exchangeOrder.getType() != null && (exchangeOrder.getType() == OrderType.EXIT_BID || exchangeOrder.getType() == OrderType.EXIT_ASK) ? PositionEffect.CLOSE : PositionEffect.OPEN); LimitOrder limitXchangeOrder;
DiscreteAmount.roundedCountForBasis(exchangeOrder.getOriginalAmount(), order.getMarket().getVolumeBasis()), order.getMarket().getVolumeBasis()); DiscreteAmount.roundedCountForBasis(exchangeOrder.getCumulativeAmount(), order.getMarket().getVolumeBasis()), order.getMarket().getVolumeBasis()); DiscreteAmount exchangeUnfilledVolume = (DiscreteAmount) exchangeVolume.minus(exchangeFilledVolume); DecimalAmount averagePrice = new DecimalAmount(exchangeOrder.getAveragePrice()); fillPrice.toBasis(order.getMarket().getPriceBasis(), Remainder.ROUND_EVEN).getCount(), fillVolume.toBasis(order.getMarket().getVolumeBasis(), Remainder.ROUND_EVEN).getCount(), Long.toString(exchangeOrder.getTimestamp().getTime()));
if (openOrder instanceof SpecificOrder) { specificOpenOrder = (SpecificOrder) openOrder; if (specificOpenOrder.getRemoteKey().equals(exchangeOrder.getId())) { orderFound = true; Fill fill = createFill(exchangeOrder, specificOpenOrder); if (!adaptOrderState(exchangeOrder.getStatus()).equals(orderStateMap.get(openOrder))) if (adaptOrderState(exchangeOrder.getStatus()) != OrderState.FILLED || adaptOrderState(exchangeOrder.getStatus()) != OrderState.PARTFILLED) updateOrderState(openOrder, adaptOrderState(exchangeOrder.getStatus()), true); if (specificOpenOrder != null && specificOpenOrder.getRemoteKey().equals(xchangeOrder.getId())) { if (specificOpenOrder.getVolume().asBigDecimal().compareTo(xchangeOrder.getOriginalAmount()) != 0) { long updateVolumeCount = DiscreteAmount.roundedCountForBasis(xchangeOrder.getOriginalAmount(), market.getVolumeBasis()); specificOpenOrder.setVolumeCount(updateVolumeCount);
@Override public Collection<Order> getOrder(String... orderIds) throws IOException { List<String> orderIdList = Arrays.asList(orderIds); OpenOrders openOrders = getOpenOrders(); List<Order> returnValue = openOrders .getOpenOrders() .stream() .filter(f -> orderIdList.contains(f.getId())) .collect(Collectors.toList()); returnValue.addAll( orderIdList .stream() .filter( f -> !returnValue.stream().filter(a -> a.getId().equals(f)).findFirst().isPresent()) .map( f -> { try { return PoloniexAdapters.adaptUserTradesToOrderStatus(f, returnOrderTrades(f)); } catch (IOException e) { LOG.error("Unable to find status for Poloniex order id: " + f, e); } return null; }) .filter(f -> f != null) .collect(Collectors.toList())); return returnValue; }
@Override public int compareTo(Order o) { return type.compareTo(o.getType()); }
private String getClientOrderId(Order order) { String clientOrderId = null; for (IOrderFlags flags : order.getOrderFlags()) { if (flags instanceof BinanceOrderFlags) { BinanceOrderFlags bof = (BinanceOrderFlags) flags; if (clientOrderId == null) { clientOrderId = bof.getClientId(); } } } return clientOrderId; }
openOrder.getPrice()); if (openOrder.getFieldAmount().compareTo(BigDecimal.ZERO) == 0) { order.setAveragePrice(BigDecimal.ZERO); } else { order.setAveragePrice( openOrder .getFieldCashAmount() order.setOrderStatus(adaptOrderStatus(openOrder.getState()));
@Override public Collection<Order> getOrder(String... orderIds) throws IOException { try { Collection<Order> orders = new ArrayList<>(); for (String orderId : orderIds) { CoingiGetOrderRequest request = new CoingiGetOrderRequest().setOrderId(orderId); CoingiOrder coingiOrder; coingiOrder = getCoingiOrder(request); CurrencyPair currencyPair = CoingiAdapters.adaptCurrency(coingiOrder.getCurrencyPair()); Date date = new Date(coingiOrder.getTimestamp() * 1000); Order order = new LimitOrder( coingiOrder.getType() == 0 ? Order.OrderType.BID : Order.OrderType.ASK, coingiOrder.getOriginalBaseAmount(), currencyPair, coingiOrder.getId(), date, coingiOrder.getPrice()); order.setOrderStatus(CoingiAdapters.adaptOrderStatus(coingiOrder.getStatus())); orders.add(order); } return orders; } catch (CoingiException e) { throw CoingiErrorAdapter.adapt(e); } } }
public void placeTestOrder( OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice) throws IOException { try { Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow"); testNewOrder( order.getCurrencyPair(), BinanceAdapters.convert(order.getType()), type, TimeInForce.GTC, order.getOriginalAmount(), limitPrice, getClientOrderId(order), stopPrice, null, recvWindow, getTimestamp()); } catch (BinanceException e) { throw BinanceErrorAdapter.adapt(e); } }
public final UserTrades getOrderTrades(Order order) throws IOException { return getOrderTrades(order.getId(), order.getCurrencyPair()); }
protected final void verifyOrder(Order order, ExchangeMetaData exchangeMetaData) { CurrencyPairMetaData metaData = exchangeMetaData.getCurrencyPairs().get(order.getCurrencyPair()); if (metaData == null) { throw new IllegalArgumentException("Invalid CurrencyPair"); } BigDecimal originalAmount = order.getOriginalAmount(); if (originalAmount == null) { throw new IllegalArgumentException("Missing originalAmount"); } BigDecimal amount = originalAmount.stripTrailingZeros(); BigDecimal minimumAmount = metaData.getMinimumAmount(); if (minimumAmount != null) { if (amount.scale() > minimumAmount.scale()) { throw new IllegalArgumentException("Unsupported amount scale " + amount.scale()); } else if (amount.compareTo(minimumAmount) < 0) { throw new IllegalArgumentException("Order amount less than minimum"); } } } }
@Override public Collection<Order> getOrder(String... orderIds) throws IOException { List<String> orderIdList = Arrays.asList(orderIds); OpenOrders openOrders = getOpenOrders(); List<Order> returnValue = openOrders.getOpenOrders().stream() .filter(f -> orderIdList.contains(f.getId())) .collect(Collectors.toList()); returnValue.addAll( orderIdList.stream() .filter( f -> !returnValue.stream().filter(a -> a.getId().equals(f)).findFirst().isPresent()) .map( f -> { try { return PoloniexAdapters.adaptUserTradesToOrderStatus(f, returnOrderTrades(f)); } catch (IOException e) { LOG.error("Unable to find status for Poloniex order id: " + f, e); } return null; }) .filter(f -> f != null) .collect(Collectors.toList())); return returnValue; }
private String getClientOrderId(Order order) { String clientOrderId = null; for (IOrderFlags flags : order.getOrderFlags()) { if (flags instanceof BinanceOrderFlags) { BinanceOrderFlags bof = (BinanceOrderFlags) flags; if (clientOrderId == null) { clientOrderId = bof.getClientId(); } } } return clientOrderId; }
public static Builder from(Order order) { Builder builder = (Builder) new Builder(order.getType(), order.getCurrencyPair()) .originalAmount(order.getOriginalAmount()) .cumulativeAmount(order.getCumulativeAmount()) .timestamp(order.getTimestamp()) .id(order.getId()) .flags(order.getOrderFlags()) .orderStatus(order.getStatus()) .averagePrice(order.getAveragePrice()); if (order instanceof LimitOrder) { LimitOrder limitOrder = (LimitOrder) order; builder.limitPrice(limitOrder.getLimitPrice()); } return builder; }