use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class OkexAdapters method adaptToExchangeMetaData.
public static ExchangeMetaData adaptToExchangeMetaData(ExchangeMetaData exchangeMetaData, List<OkexInstrument> instruments, List<OkexCurrency> currs) {
Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs() == null ? new HashMap<>() : exchangeMetaData.getCurrencyPairs();
Map<Currency, CurrencyMetaData> currencies = exchangeMetaData.getCurrencies() == null ? new HashMap<>() : exchangeMetaData.getCurrencies();
for (OkexInstrument instrument : instruments) {
if (!"live".equals(instrument.getState())) {
continue;
}
CurrencyPair pair = adaptCurrencyPair(instrument);
CurrencyPairMetaData staticMetaData = currencyPairs.get(pair);
int priceScale = numberOfDecimals(new BigDecimal(instrument.getTickSize()));
currencyPairs.put(pair, new CurrencyPairMetaData(new BigDecimal("0.50"), new BigDecimal(instrument.getMinSize()), null, null, null, null, priceScale, null, staticMetaData != null ? staticMetaData.getFeeTiers() : null, null, pair.counter, true));
}
if (currs != null) {
currs.stream().forEach(currency -> currencies.put(adaptCurrency(currency), new CurrencyMetaData(null, new BigDecimal(currency.getMaxFee()), new BigDecimal(currency.getMinWd()), currency.isCanWd() && currency.isCanDep() ? WalletHealth.ONLINE : WalletHealth.OFFLINE)));
}
return new ExchangeMetaData(currencyPairs, currencies, exchangeMetaData.getPublicRateLimits(), exchangeMetaData.getPrivateRateLimits(), true);
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class OkexAdapters method adaptOkexBalances.
public static Wallet adaptOkexBalances(List<OkexWalletBalance> okexWalletBalanceList) {
List<Balance> balances = new ArrayList<>();
if (!okexWalletBalanceList.isEmpty()) {
OkexWalletBalance okexWalletBalance = okexWalletBalanceList.get(0);
balances = Arrays.stream(okexWalletBalance.getDetails()).map(detail -> new Balance.Builder().currency(new Currency(detail.getCurrency())).total(new BigDecimal(detail.getCashBalance())).available(checkForEmpty(detail.getAvailableBalance())).timestamp(new Date()).build()).collect(Collectors.toList());
}
return Wallet.Builder.from(balances).id(TRADING_WALLET_ID).features(new HashSet<>(Collections.singletonList(Wallet.WalletFeature.TRADING))).build();
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class OkexAdapters method adaptUserTrades.
public static UserTrades adaptUserTrades(List<OkexOrderDetails> okexTradeHistory) {
List<UserTrade> userTradeList = new ArrayList<>();
okexTradeHistory.forEach(okexOrderDetails -> {
userTradeList.add(new UserTrade.Builder().originalAmount(new BigDecimal(okexOrderDetails.getAmount())).instrument(new CurrencyPair(okexOrderDetails.getInstrumentId())).currencyPair(new CurrencyPair(okexOrderDetails.getInstrumentId())).price(new BigDecimal(okexOrderDetails.getAverageFilledPrice())).type(adaptOkexOrderSideToOrderType(okexOrderDetails.getSide())).id(okexOrderDetails.getOrderId()).orderId(okexOrderDetails.getOrderId()).timestamp(Date.from(Instant.ofEpochMilli(Long.parseLong(okexOrderDetails.getUpdateTime())))).feeAmount(new BigDecimal(okexOrderDetails.getFee())).feeCurrency(new Currency(okexOrderDetails.getFeeCurrency())).orderUserReference(okexOrderDetails.getClientOrderId()).build());
});
return new UserTrades(userTradeList, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class OkexAdapters method adaptOkexAssetBalances.
public static Wallet adaptOkexAssetBalances(List<OkexAssetBalance> okexAssetBalanceList) {
List<Balance> balances;
balances = okexAssetBalanceList.stream().map(detail -> new Balance.Builder().currency(new Currency(detail.getCurrency())).total(new BigDecimal(detail.getBalance())).available(checkForEmpty(detail.getAvailableBalance())).timestamp(new Date()).build()).collect(Collectors.toList());
return Wallet.Builder.from(balances).id(FOUNDING_WALLET_ID).features(new HashSet<>(Collections.singletonList(Wallet.WalletFeature.FUNDING))).build();
}
use of org.knowm.xchange.currency.Currency in project XChange by knowm.
the class BiboxAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) {
if (!(params instanceof TradeHistoryParamCurrency)) {
throw new RuntimeException("You must provide the currency for funding history @ Bibox.");
}
Currency c = ((TradeHistoryParamCurrency) params).getCurrency();
if (c == null) {
throw new RuntimeException("You must provide the currency for funding history @ Bibox.");
}
boolean deposits = false;
boolean withdrawals = false;
if (params instanceof HistoryParamsFundingType) {
HistoryParamsFundingType typeParams = (HistoryParamsFundingType) params;
Type type = typeParams.getType();
deposits = type == null || type == Type.DEPOSIT;
withdrawals = type == null || type == Type.WITHDRAWAL;
}
BiboxFundsCommandBody body = new BiboxFundsCommandBody(c.getCurrencyCode());
ArrayList<FundingRecord> result = new ArrayList<>();
if (deposits) {
requestBiboxDeposits(body).getItems().forEach(d -> result.add(BiboxAdapters.adaptDeposit(d)));
}
if (withdrawals) {
requestBiboxWithdrawals(body).getItems().forEach(d -> result.add(BiboxAdapters.adaptDeposit(d)));
}
return result;
}
Aggregations