Search in sources :

Example 1 with GeminiTrade

use of org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade in project XChange by knowm.

the class GeminiAdapters method adaptTrades.

public static Trades adaptTrades(GeminiTrade[] trades, CurrencyPair currencyPair) {
    List<Trade> tradesList = new ArrayList<>(trades.length);
    long lastTradeId = 0;
    for (GeminiTrade trade : trades) {
        long tradeId = trade.getTradeId();
        if (tradeId > lastTradeId) {
            lastTradeId = tradeId;
        }
        tradesList.add(adaptTrade(trade, currencyPair));
    }
    return new Trades(tradesList, lastTradeId, TradeSortType.SortByID);
}
Also used : GeminiTrade(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) GeminiTrade(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade)

Example 2 with GeminiTrade

use of org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade in project XChange by knowm.

the class GeminiWebSocketTransaction method toGeminiTrades.

public GeminiTrade[] toGeminiTrades() {
    long timestamp = Long.valueOf(this.timestamp);
    List<GeminiTrade> trades = new ArrayList<>(1000);
    for (JsonNode jsonEvent : events) {
        if (jsonEvent.get("type").asText().equals("trade")) {
            GeminiTrade trade = toGeminiTrade(jsonEvent, timestamp);
            trades.add(trade);
        }
    }
    return trades.toArray(new GeminiTrade[trades.size()]);
}
Also used : ArrayList(java.util.ArrayList) GeminiTrade(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with GeminiTrade

use of org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade in project XChange by knowm.

the class GeminiWebSocketTransaction method toGeminiTrade.

private static GeminiTrade toGeminiTrade(JsonNode jsonEvent, long timestamp) {
    long tid = Long.valueOf(jsonEvent.get("tid").asText());
    BigDecimal price = new BigDecimal(jsonEvent.get("price").asText());
    BigDecimal amount = new BigDecimal(jsonEvent.get("amount").asText());
    String takerSide = jsonEvent.get("makerSide").asText().equals("ask") ? "buy" : "sell";
    return new GeminiTrade(price, amount, timestamp, "gemini", tid, takerSide);
}
Also used : GeminiTrade(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade) BigDecimal(java.math.BigDecimal)

Example 4 with GeminiTrade

use of org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade in project XChange by knowm.

the class GeminiAdapters method adaptTrade.

public static Trade adaptTrade(GeminiTrade trade, CurrencyPair currencyPair) {
    OrderType orderType = trade.getType().equals("buy") ? OrderType.BID : OrderType.ASK;
    BigDecimal amount = trade.getAmount();
    BigDecimal price = trade.getPrice();
    Date date = // Gemini uses Unix timestamps
    DateUtils.fromMillisUtc(trade.getTimestamp() * 1000L);
    final String tradeId = String.valueOf(trade.getTradeId());
    return new Trade.Builder().type(orderType).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(date).id(tradeId).build();
}
Also used : GeminiTrade(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Aggregations

GeminiTrade (org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade)4 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Trade (org.knowm.xchange.dto.marketdata.Trade)2 UserTrade (org.knowm.xchange.dto.trade.UserTrade)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Date (java.util.Date)1 OrderType (org.knowm.xchange.dto.Order.OrderType)1 Trades (org.knowm.xchange.dto.marketdata.Trades)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1