Search in sources :

Example 16 with Currency

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);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) OkexInstrument(org.knowm.xchange.okex.v5.dto.marketdata.OkexInstrument) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 17 with Currency

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();
}
Also used : OkexWalletBalance(org.knowm.xchange.okex.v5.dto.account.OkexWalletBalance) Currency(org.knowm.xchange.currency.Currency) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) OkexWalletBalance(org.knowm.xchange.okex.v5.dto.account.OkexWalletBalance) OkexAssetBalance(org.knowm.xchange.okex.v5.dto.account.OkexAssetBalance) BigDecimal(java.math.BigDecimal) Date(java.util.Date) HashSet(java.util.HashSet)

Example 18 with Currency

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) Currency(org.knowm.xchange.currency.Currency) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 19 with Currency

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();
}
Also used : Currency(org.knowm.xchange.currency.Currency) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) Balance(org.knowm.xchange.dto.account.Balance) OkexWalletBalance(org.knowm.xchange.okex.v5.dto.account.OkexWalletBalance) OkexAssetBalance(org.knowm.xchange.okex.v5.dto.account.OkexAssetBalance) BigDecimal(java.math.BigDecimal) Date(java.util.Date) HashSet(java.util.HashSet)

Example 20 with Currency

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;
}
Also used : HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) Type(org.knowm.xchange.dto.account.FundingRecord.Type) BiboxFundsCommandBody(org.knowm.xchange.bibox.dto.account.BiboxFundsCommandBody) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Currency(org.knowm.xchange.currency.Currency) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)

Aggregations

Currency (org.knowm.xchange.currency.Currency)159 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)75 BigDecimal (java.math.BigDecimal)67 ArrayList (java.util.ArrayList)60 Balance (org.knowm.xchange.dto.account.Balance)38 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)35 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)32 HashMap (java.util.HashMap)28 Test (org.junit.Test)27 Map (java.util.Map)22 Date (java.util.Date)21 AccountInfo (org.knowm.xchange.dto.account.AccountInfo)19 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)19 IOException (java.io.IOException)18 ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)18 List (java.util.List)17 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)15 OrderType (org.knowm.xchange.dto.Order.OrderType)14 UserTrade (org.knowm.xchange.dto.trade.UserTrade)14 Collectors (java.util.stream.Collectors)11