Search in sources :

Example 21 with OrderType

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

the class IdexTradeService method placeLimitOrder.

/**
 * returns OrderHash so you can fetch it and cancel it... but there is a OrderNumber that you can
 * intercept if you need to.
 */
@Override
public String placeLimitOrder(LimitOrder placeOrder) {
    OrderType type = placeOrder.getType();
    Currency baseCurrency = placeOrder.getCurrencyPair().base;
    Currency counterCurrency = placeOrder.getCurrencyPair().counter;
    BigDecimal originalAmount = placeOrder.getOriginalAmount();
    BigDecimal limitPrice = placeOrder.getLimitPrice();
    OrderReq orderReq = createNormalizedLimitOrderReq(baseCurrency, counterCurrency, type, limitPrice, originalAmount, null, null, null);
    try {
        orderApi.order(orderReq).getOrderHash();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) Currency(org.knowm.xchange.currency.Currency) OrderReq(org.knowm.xchange.idex.dto.OrderReq) BigDecimal(java.math.BigDecimal) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException)

Example 22 with OrderType

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

the class BittrexAdapters method adaptOrder.

public static LimitOrder adaptOrder(BittrexOrder order, OrderStatus status) {
    OrderType type = order.getDirection().equalsIgnoreCase(BittrexConstants.SELL) ? OrderType.ASK : OrderType.BID;
    CurrencyPair pair = BittrexUtils.toCurrencyPair(order.getMarketSymbol());
    return new LimitOrder.Builder(type, pair).originalAmount(order.getQuantity()).id(order.getId()).timestamp(order.getUpdatedAt() != null ? order.getUpdatedAt() : order.getCreatedAt()).limitPrice(order.getLimit()).remainingAmount(order.getQuantity().subtract(order.getFillQuantity())).fee(order.getCommission()).orderStatus(status).build();
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 23 with OrderType

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

the class HitbtcAdapters method adaptTrades.

public static Trades adaptTrades(List<? extends HitbtcTrade> allHitbtcTrades, CurrencyPair currencyPair) {
    List<Trade> trades = new ArrayList<>(allHitbtcTrades.size());
    long lastTradeId = 0;
    for (int i = 0; i < allHitbtcTrades.size(); i++) {
        HitbtcTrade hitbtcTrade = allHitbtcTrades.get(i);
        Date timestamp = hitbtcTrade.getTimestamp();
        BigDecimal price = hitbtcTrade.getPrice();
        BigDecimal amount = hitbtcTrade.getQuantity();
        String tid = hitbtcTrade.getId();
        long longTradeId = tid == null ? 0 : Long.parseLong(tid);
        if (longTradeId > lastTradeId) {
            lastTradeId = longTradeId;
        }
        OrderType orderType = adaptSide(hitbtcTrade.getSide());
        Trade trade = new Trade.Builder().type(orderType).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(tid).build();
        trades.add(trade);
    }
    return new Trades(trades, lastTradeId, Trades.TradeSortType.SortByTimestamp);
}
Also used : HitbtcUserTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcUserTrade) HitbtcTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) HitbtcOwnTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcOwnTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) HitbtcTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcTrade) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 24 with OrderType

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

the class HitbtcAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(List<HitbtcOwnTrade> tradeHistoryRaw) {
    List<UserTrade> trades = new ArrayList<>(tradeHistoryRaw.size());
    for (HitbtcOwnTrade hitbtcOwnTrade : tradeHistoryRaw) {
        OrderType type = adaptOrderType(hitbtcOwnTrade.getSide().getValue());
        CurrencyPair pair = adaptSymbol(hitbtcOwnTrade.symbol);
        BigDecimal originalAmount = hitbtcOwnTrade.getQuantity();
        Date timestamp = hitbtcOwnTrade.getTimestamp();
        String id = Long.toString(hitbtcOwnTrade.getId());
        String orderId = String.valueOf(hitbtcOwnTrade.getOrderId());
        String clientOrderId = hitbtcOwnTrade.getClientOrderId();
        UserTrade trade = new HitbtcUserTrade(type, originalAmount, pair, hitbtcOwnTrade.getPrice(), timestamp, id, orderId, hitbtcOwnTrade.getFee(), pair.counter, clientOrderId);
        trades.add(trade);
    }
    return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) HitbtcUserTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcUserTrade) ArrayList(java.util.ArrayList) HitbtcOwnTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcOwnTrade) HitbtcUserTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcUserTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 25 with OrderType

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

the class RippleTradeServiceRaw method getExpectedCounterTransferFee.

/**
 * @return transfer fee for the counter leg of the order in the counter currency
 */
public BigDecimal getExpectedCounterTransferFee(final RippleLimitOrder order) throws IOException {
    final ITransferFeeSource transferFeeSource = (ITransferFeeSource) exchange.getAccountService();
    final String counterparty = order.getCounterCounterparty();
    final String currency = order.getCurrencyPair().counter.getCurrencyCode();
    final BigDecimal quantity = order.getOriginalAmount().multiply(order.getLimitPrice());
    final OrderType type;
    if (order.getType() == OrderType.BID) {
        type = OrderType.ASK;
    } else {
        type = OrderType.BID;
    }
    return getExpectedTransferFee(transferFeeSource, counterparty, currency, quantity, type);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) ITransferFeeSource(org.knowm.xchange.ripple.dto.account.ITransferFeeSource) BigDecimal(java.math.BigDecimal)

Aggregations

OrderType (org.knowm.xchange.dto.Order.OrderType)104 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)68 Date (java.util.Date)65 BigDecimal (java.math.BigDecimal)64 UserTrade (org.knowm.xchange.dto.trade.UserTrade)38 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)36 ArrayList (java.util.ArrayList)35 Trade (org.knowm.xchange.dto.marketdata.Trade)25 UserTrades (org.knowm.xchange.dto.trade.UserTrades)19 Order (org.knowm.xchange.dto.Order)15 Currency (org.knowm.xchange.currency.Currency)12 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)12 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)11 Test (org.junit.Test)10 Trades (org.knowm.xchange.dto.marketdata.Trades)10 OrderStatus (org.knowm.xchange.dto.Order.OrderStatus)9 List (java.util.List)6 BitfinexOrderType (org.knowm.xchange.bitfinex.v1.BitfinexOrderType)5 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)5 StopOrder (org.knowm.xchange.dto.trade.StopOrder)5