Search in sources :

Example 1 with OrderType

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

the class BitstampTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws ExchangeException, IOException {
    BitstampOrder[] openOrders = getBitstampOpenOrders();
    List<LimitOrder> limitOrders = new ArrayList<>(openOrders.length);
    for (BitstampOrder bitstampOrder : openOrders) {
        OrderType orderType = bitstampOrder.getType() == 0 ? OrderType.BID : OrderType.ASK;
        String id = Long.toString(bitstampOrder.getId());
        BigDecimal price = bitstampOrder.getPrice();
        limitOrders.add(new LimitOrder(orderType, bitstampOrder.getAmount(), new BitstampV2.Pair(bitstampOrder.getCurrencyPair()).pair, id, bitstampOrder.getDatetime(), price, // avgPrice
        null, // cumAmount
        null, // fee
        null, Order.OrderStatus.NEW));
    }
    return new OpenOrders(limitOrders);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) BitstampV2(org.knowm.xchange.bitstamp.BitstampV2) BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BigDecimal(java.math.BigDecimal)

Example 2 with OrderType

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

the class CoingiAdapters method adaptTrade.

/**
 * Adapts a Transaction to a Trade Object
 *
 * @param tx The Coingi transaction
 * @param currencyPair (e.g. BTC/USD)
 * @param timeScale polled order books provide a timestamp in seconds, stream in ms
 * @return The XChange Trade
 */
public static Trade adaptTrade(CoingiUserTransaction tx, CurrencyPair currencyPair, int timeScale) {
    OrderType orderType = tx.getType() == 0 ? OrderType.BID : OrderType.ASK;
    final String tradeId = tx.getId();
    Date date = DateUtils.fromMillisUtc(tx.getTimestamp() * // polled order books provide a timestamp in seconds, stream in ms
    timeScale);
    return new Trade.Builder().type(orderType).originalAmount(tx.getBaseAmount()).currencyPair(currencyPair).price(tx.getPrice()).timestamp(date).id(tradeId).build();
}
Also used : UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date)

Example 3 with OrderType

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

the class CoingiAdapters method adaptTrade.

public static Trade adaptTrade(org.knowm.xchange.coingi.dto.marketdata.CoingiTransaction tx, CurrencyPair currencyPair, int timeScale) {
    OrderType orderType = tx.getType() == 0 ? OrderType.BID : OrderType.ASK;
    final String tradeId = tx.getId();
    Date date = new Date(tx.getTimestamp());
    return new Trade.Builder().type(orderType).originalAmount(tx.getAmount()).currencyPair(currencyPair).price(tx.getPrice()).timestamp(date).id(tradeId).build();
}
Also used : UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date)

Example 4 with OrderType

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

the class CoingiAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(CoingiOrdersList ordersList) {
    List<UserTrade> trades = new ArrayList<>();
    for (CoingiOrder o : ordersList.getList()) {
        final OrderType orderType = o.getType() == 0 ? OrderType.BID : OrderType.ASK;
        final CurrencyPair pair = new CurrencyPair(o.getCurrencyPair().get("base").toUpperCase(), o.getCurrencyPair().get("counter").toUpperCase());
        UserTrade trade = new UserTrade.Builder().type(orderType).originalAmount(o.getOriginalBaseAmount()).currencyPair(pair).price(o.getPrice()).timestamp(new Date(o.getTimestamp())).id(o.getId()).orderId(o.getId()).feeAmount(BigDecimal.ZERO).build();
        trades.add(trade);
    }
    return new UserTrades(trades, TradeSortType.SortByID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 5 with OrderType

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

the class KrakenLimitOrderDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    KrakenTradeServiceRaw tradeService = (KrakenTradeServiceRaw) krakenExchange.getTradeService();
    OrderType orderType = (OrderType.ASK);
    BigDecimal tradeableAmount = new BigDecimal("0.01");
    BigDecimal price = new BigDecimal("65.25");
    LimitOrder limitOrder = new LimitOrder(orderType, tradeableAmount, CurrencyPair.BTC_LTC, "", null, price);
    KrakenOrderResponse orderResponse = tradeService.placeKrakenLimitOrder(limitOrder);
    System.out.println("Limit Order response: " + orderResponse);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) KrakenTradeServiceRaw(org.knowm.xchange.kraken.service.KrakenTradeServiceRaw) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KrakenOrderResponse(org.knowm.xchange.kraken.dto.trade.KrakenOrderResponse) 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