Search in sources :

Example 1 with LakeBTCTradeResponse

use of org.knowm.xchange.lakebtc.dto.trade.LakeBTCTradeResponse in project XChange by knowm.

the class LakeBTCTradeHistoryDemo method raw.

private static void raw(Exchange lakeBtcExchange) throws IOException {
    LakeBTCTradeServiceRaw tradeService = (LakeBTCTradeServiceRaw) lakeBtcExchange.getTradeService();
    // Get the trade history
    LakeBTCTradeResponse[] trades = tradeService.getLakeBTCTradeHistory(0);
    System.out.println(Arrays.toString(trades));
}
Also used : LakeBTCTradeResponse(org.knowm.xchange.lakebtc.dto.trade.LakeBTCTradeResponse) LakeBTCTradeServiceRaw(org.knowm.xchange.lakebtc.service.LakeBTCTradeServiceRaw)

Example 2 with LakeBTCTradeResponse

use of org.knowm.xchange.lakebtc.dto.trade.LakeBTCTradeResponse in project XChange by knowm.

the class LakeBTCAdapters method adaptTrades.

/**
 * Adapts a Transaction[] to a Trades Object
 *
 * @param transactions The LakeBtc transactions
 * @param currencyPair (e.g. BTC/USD)
 * @return The XChange Trades
 */
public static Trades adaptTrades(LakeBTCTradeResponse[] transactions, CurrencyPair currencyPair) {
    List<Trade> trades = new ArrayList<>();
    long lastTradeId = 0;
    for (LakeBTCTradeResponse trade : transactions) {
        final OrderType orderType = trade.getType().startsWith("buy") ? OrderType.BID : OrderType.ASK;
        trades.add(new Trade.Builder().type(orderType).originalAmount(trade.getAmount()).currencyPair(currencyPair).price(trade.getTotal()).timestamp(DateUtils.fromMillisUtc(trade.getAt() * 1000L)).id(trade.getId()).build());
    }
    return new Trades(trades, lastTradeId, Trades.TradeSortType.SortByTimestamp);
}
Also used : UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) LakeBTCTradeResponse(org.knowm.xchange.lakebtc.dto.trade.LakeBTCTradeResponse) 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)

Example 3 with LakeBTCTradeResponse

use of org.knowm.xchange.lakebtc.dto.trade.LakeBTCTradeResponse in project XChange by knowm.

the class LakeBTCAdapters method adaptTradeHistory.

/**
 * Adapt the user's trades
 *
 * @param transactions
 * @return
 */
public static UserTrades adaptTradeHistory(LakeBTCTradeResponse[] transactions) {
    List<UserTrade> trades = new ArrayList<>();
    long lastTradeId = 0;
    for (LakeBTCTradeResponse trade : transactions) {
        final OrderType orderType = trade.getType().startsWith("buy") ? OrderType.BID : OrderType.ASK;
        BigDecimal originalAmount = trade.getAmount();
        BigDecimal price = trade.getTotal().abs();
        Date timestamp = DateUtils.fromMillisUtc(trade.getAt() * 1000L);
        final String tradeId = trade.getId();
        final CurrencyPair currencyPair = CurrencyPair.BTC_CNY;
        UserTrade userTrade = new UserTrade.Builder().type(orderType).originalAmount(originalAmount).currencyPair(currencyPair).price(price).timestamp(timestamp).feeCurrency(Currency.getInstance(currencyPair.counter.getCurrencyCode())).build();
        trades.add(userTrade);
    }
    return new UserTrades(trades, lastTradeId, Trades.TradeSortType.SortByTimestamp);
}
Also used : LakeBTCTradeResponse(org.knowm.xchange.lakebtc.dto.trade.LakeBTCTradeResponse) UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

LakeBTCTradeResponse (org.knowm.xchange.lakebtc.dto.trade.LakeBTCTradeResponse)3 ArrayList (java.util.ArrayList)2 OrderType (org.knowm.xchange.dto.Order.OrderType)2 UserTrade (org.knowm.xchange.dto.trade.UserTrade)2 UserTrades (org.knowm.xchange.dto.trade.UserTrades)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 Trade (org.knowm.xchange.dto.marketdata.Trade)1 Trades (org.knowm.xchange.dto.marketdata.Trades)1 LakeBTCTradeServiceRaw (org.knowm.xchange.lakebtc.service.LakeBTCTradeServiceRaw)1