use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class DsxAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
List<DsxTransaction> transactions;
String currencyCode = null;
Integer limit = 1000;
int offset = 0;
if (params instanceof TradeHistoryParamCurrency) {
Currency currency = ((TradeHistoryParamCurrency) params).getCurrency();
currencyCode = currency != null ? currency.getCurrencyCode() : null;
}
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset().intValue();
}
transactions = getTransactions(currencyCode, limit, offset);
List<FundingRecord> records = new ArrayList<>();
for (DsxTransaction transaction : transactions) {
records.add(DsxAdapters.adapt(transaction));
}
return records;
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class BinanceTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
try {
Assert.isTrue(params instanceof TradeHistoryParamCurrencyPair, "You need to provide the currency pair to get the user trades.");
TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
CurrencyPair pair = pairParams.getCurrencyPair();
if (pair == null) {
throw new ExchangeException("You need to provide the currency pair to get the user trades.");
}
Long orderId = null;
Long startTime = null;
Long endTime = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
if (((TradeHistoryParamsTimeSpan) params).getStartTime() != null) {
startTime = ((TradeHistoryParamsTimeSpan) params).getStartTime().getTime();
}
if (((TradeHistoryParamsTimeSpan) params).getEndTime() != null) {
endTime = ((TradeHistoryParamsTimeSpan) params).getEndTime().getTime();
}
}
Long fromId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan idParams = (TradeHistoryParamsIdSpan) params;
try {
fromId = BinanceAdapters.id(idParams.getStartId());
} catch (Throwable ignored) {
}
}
if ((fromId != null) && (startTime != null || endTime != null)) {
throw new ExchangeException("You should either specify the id from which you get the user trades from or start and end times. If you specify both, Binance will only honour the fromId parameter.");
}
Integer limit = null;
if (params instanceof TradeHistoryParamLimit) {
TradeHistoryParamLimit limitParams = (TradeHistoryParamLimit) params;
limit = limitParams.getLimit();
}
List<BinanceTrade> binanceTrades = super.myTrades(pair, orderId, startTime, endTime, fromId, limit);
List<UserTrade> trades = binanceTrades.stream().map(t -> new UserTrade.Builder().type(BinanceAdapters.convertType(t.isBuyer)).originalAmount(t.qty).currencyPair(pair).price(t.price).timestamp(t.getTime()).id(Long.toString(t.id)).orderId(Long.toString(t.orderId)).feeAmount(t.commission).feeCurrency(Currency.getInstance(t.commissionAsset)).build()).collect(Collectors.toList());
long lastId = binanceTrades.stream().map(t -> t.id).max(Long::compareTo).orElse(0L);
return new UserTrades(trades, lastId, Trades.TradeSortType.SortByTimestamp);
} catch (BinanceException e) {
throw BinanceErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class BitmexExchange method updateExchangeMetaData.
public void updateExchangeMetaData() {
List<BitmexTicker> tickers = ((BitmexMarketDataServiceRaw) marketDataService).getActiveTickers();
List<CurrencyPair> activeCurrencyPairs = new ArrayList<>();
Set<Currency> activeCurrencies = new HashSet<>();
tickers.forEach(ticker -> collectCurrenciesAndPairs(ticker, activeCurrencyPairs, activeCurrencies));
Map<CurrencyPair, CurrencyPairMetaData> pairsMap = exchangeMetaData.getCurrencyPairs();
Map<Currency, CurrencyMetaData> currenciesMap = exchangeMetaData.getCurrencies();
// Remove pairs that are no-longer in use
pairsMap.keySet().retainAll(activeCurrencyPairs);
// Remove currencies that are no-longer in use
currenciesMap.keySet().retainAll(activeCurrencies);
// Add missing pairs and currencies
activeCurrencyPairs.forEach(cp -> {
if (!pairsMap.containsKey(cp)) {
pairsMap.put(cp, new CurrencyPairMetaData(null, BigDecimal.ONE, null, getPriceScale(tickers, cp), null));
}
if (!currenciesMap.containsKey(cp.base)) {
currenciesMap.put(cp.base, null);
}
if (!currenciesMap.containsKey(cp.counter)) {
currenciesMap.put(cp.counter, null);
}
});
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class BitstampAdapters method adaptOrder.
/**
* There is no method to discern market versus limit order type - so this returns a generic
* BitstampGenericOrder as a status
*
* @param bitstampOrderStatusResponse
* @param exchangeSymbols
* @return
*/
public static BitstampGenericOrder adaptOrder(String orderId, BitstampOrderStatusResponse bitstampOrderStatusResponse, List<CurrencyPair> exchangeSymbols) {
BitstampOrderTransaction[] bitstampTransactions = bitstampOrderStatusResponse.getTransactions();
// Use only the first transaction, because we assume that for a single order id all transactions
// will
// be of the same currency pair
Order.OrderStatus orderStatus = adaptOrderStatus(bitstampOrderStatusResponse.getStatus());
if (bitstampTransactions.length > 0) {
CurrencyPair currencyPair = adaptCurrencyPair(bitstampTransactions[0], exchangeSymbols);
Date date = bitstampTransactions[0].getDatetime();
BigDecimal averagePrice = Arrays.stream(bitstampTransactions).map(t -> t.getPrice()).reduce((x, y) -> x.add(y)).get().divide(BigDecimal.valueOf(bitstampTransactions.length), 2);
BigDecimal cumulativeAmount = Arrays.stream(bitstampTransactions).map(t -> getBaseCurrencyAmountFromBitstampTransaction(t, currencyPair)).reduce((x, y) -> x.add(y)).get();
BigDecimal totalFee = Arrays.stream(bitstampTransactions).map(t -> t.getFee()).reduce((x, y) -> x.add(y)).get();
return new BitstampGenericOrder(// not discernable from response data
null, // not discernable from the data
null, currencyPair, orderId, date, averagePrice, cumulativeAmount, totalFee, orderStatus);
} else {
return new BitstampGenericOrder(// not discernable from response data
null, // not discernable from the data
null, // not discernable from the data
null, orderId, // not discernable from the data
null, // not discernable from the data
new BigDecimal("0.0"), // not discernable from the data
new BigDecimal("0.0"), // not discernable from the data
new BigDecimal("0.0"), orderStatus);
}
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class BitmexAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) {
Currency currency = null;
Integer count = null;
Long start = null;
if (params instanceof TradeHistoryParamCurrency) {
currency = ((TradeHistoryParamCurrency) params).getCurrency();
} else {
throw new ExchangeException("Currency must be supplied");
}
if (params instanceof TradeHistoryParamLimit) {
count = ((TradeHistoryParamLimit) params).getLimit();
}
if (params instanceof TradeHistoryParamOffset) {
start = ((TradeHistoryParamOffset) params).getOffset();
}
return getBitmexWalletHistory(currency, count, start).stream().map(BitmexAdapters::adaptFundingRecord).collect(Collectors.toList());
}
Aggregations