Search in sources :

Example 11 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class CryptopiaAccountServiceRaw method getBalances.

public List<Balance> getBalances() throws IOException {
    CryptopiaBaseResponse<List<Map>> response = cryptopia.getBalance(signatureCreator, new HashMap<>());
    List<Balance> balances = new ArrayList<>();
    for (Map datum : response.getData()) {
        Currency symbol = Currency.getInstance(datum.get("Symbol").toString());
        BigDecimal total = new BigDecimal(datum.get("Total").toString());
        BigDecimal available = new BigDecimal(datum.get("Available").toString());
        BigDecimal heldForTrades = new BigDecimal(datum.get("HeldForTrades").toString());
        BigDecimal pendingWithdraw = new BigDecimal(datum.get("PendingWithdraw").toString());
        BigDecimal unconfirmed = new BigDecimal(datum.get("Unconfirmed").toString());
        Balance balance = new Balance(symbol, total, available, heldForTrades, BigDecimal.ZERO, BigDecimal.ZERO, pendingWithdraw, unconfirmed);
        balances.add(balance);
    }
    return balances;
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Balance(org.knowm.xchange.dto.account.Balance) HashMap(java.util.HashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 12 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class CryptoFacilitiesAdapters method adaptAccounts.

public static AccountInfo adaptAccounts(CryptoFacilitiesAccounts cryptoFacilitiesAccounts, String username) {
    Map<String, CryptoFacilitiesAccountInfo> accounts = cryptoFacilitiesAccounts.getAccounts();
    List<Wallet> wallets = new ArrayList<>();
    for (String accountName : accounts.keySet()) {
        List<Balance> balances = new ArrayList<>(accounts.get(accountName).getBalances().size());
        Balance balance;
        for (Entry<String, BigDecimal> balancePair : accounts.get(accountName).getBalances().entrySet()) {
            if (!accountName.equalsIgnoreCase("cash") && balancePair.getKey().equalsIgnoreCase("xbt")) {
                // For xbt balance we construct both total=deposited xbt and available=total - margin
                // balances
                balance = new Balance(Currency.BTC, balancePair.getValue(), accounts.get(accountName).getAuxiliary().get("af"));
            } else {
                Currency currency = adaptCurrency(balancePair.getKey());
                balance = new Balance(currency, balancePair.getValue());
            }
            balances.add(balance);
        }
        wallets.add(Wallet.Builder.from(balances).id(accountName).name(accountName).build());
    }
    return new AccountInfo(username, wallets);
}
Also used : CryptoFacilitiesAccountInfo(org.knowm.xchange.cryptofacilities.dto.account.CryptoFacilitiesAccountInfo) Wallet(org.knowm.xchange.dto.account.Wallet) Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) CryptoFacilitiesAccountInfo(org.knowm.xchange.cryptofacilities.dto.account.CryptoFacilitiesAccountInfo)

Example 13 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class CryptoFacilitiesAdapters method adaptAccount.

public static AccountInfo adaptAccount(CryptoFacilitiesAccount cryptoFacilitiesAccount, String username) {
    List<Balance> balances = new ArrayList<>(cryptoFacilitiesAccount.getBalances().size());
    Balance balance;
    for (Entry<String, BigDecimal> balancePair : cryptoFacilitiesAccount.getBalances().entrySet()) {
        if (balancePair.getKey().equalsIgnoreCase("xbt")) {
            // For xbt balance we construct both total=deposited xbt and available=total - margin
            // balances
            balance = new Balance(Currency.BTC, balancePair.getValue(), cryptoFacilitiesAccount.getAuxiliary().get("af"));
        } else {
            Currency currency = adaptCurrency(balancePair.getKey());
            balance = new Balance(currency, balancePair.getValue());
        }
        balances.add(balance);
    }
    return new AccountInfo(username, Wallet.Builder.from(balances).build());
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) CryptoFacilitiesAccountInfo(org.knowm.xchange.cryptofacilities.dto.account.CryptoFacilitiesAccountInfo)

Example 14 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class UserTradeTest method testBuilder.

@Test
public void testBuilder() {
    final OrderType type = OrderType.BID;
    final BigDecimal originalAmount = new BigDecimal("99.401");
    final CurrencyPair currencyPair = CurrencyPair.LTC_BTC;
    final BigDecimal price = new BigDecimal("251.64");
    final Date timestamp = new Date();
    final String id = "id";
    final String orderId = "OrderId";
    final BigDecimal feeAmount = new BigDecimal("0.0006");
    final Currency feeCurrency = Currency.BTC;
    final String orderUserReference = "orderUserReference";
    final UserTrade copy = new UserTrade.Builder().type(type).originalAmount(originalAmount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(id).orderId(orderId).feeAmount(feeAmount).feeCurrency(feeCurrency).orderUserReference(orderUserReference).build();
    assertThat(copy.getType()).isEqualTo(type);
    assertThat(copy.getOriginalAmount()).isEqualTo(originalAmount);
    assertThat(copy.getCurrencyPair()).isEqualTo(currencyPair);
    assertThat(copy.getPrice()).isEqualTo(price);
    assertThat(copy.getTimestamp()).isEqualTo(timestamp);
    assertThat(copy.getId()).isEqualTo(id);
    assertThat(copy.getOrderId()).isEqualTo(orderId);
    assertThat(copy.getFeeAmount()).isEqualTo(feeAmount);
    assertThat(copy.getFeeCurrency()).isEqualTo(feeCurrency);
    assertThat(copy.getOrderUserReference()).isEqualTo(orderUserReference);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) Currency(org.knowm.xchange.currency.Currency) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 15 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class IndependentReserveAccountDemo method generic.

private static void generic(AccountService accountService) throws IOException {
    // Get the account information
    AccountInfo accountInfo = accountService.getAccountInfo();
    System.out.println("Account balances: (available / available for withdrawal / total)");
    Wallet wallet = accountInfo.getWallet();
    Map<Currency, Balance> balances = wallet.getBalances();
    for (Map.Entry<Currency, Balance> entry : balances.entrySet()) {
        Balance balance = entry.getValue();
        System.out.format("%s balance: %s / %s / %s\n", entry.getKey().getCurrencyCode(), balance.getAvailable(), balance.getAvailableForWithdrawal(), balance.getTotal());
    }
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) Currency(org.knowm.xchange.currency.Currency) IndependentReserveBalance(org.knowm.xchange.independentreserve.dto.account.IndependentReserveBalance) Balance(org.knowm.xchange.dto.account.Balance) Map(java.util.Map) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

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