binance-exchange / binance-java-api

binance-java-api is a lightweight Java library for the Binance API, supporting synchronous and asynchronous requests, as well as event streaming using WebSockets.
MIT License
831 stars 628 forks source link

a problem in the examples #361

Open amirshamaei opened 3 years ago

amirshamaei commented 3 years ago

Hi, I am new here, I just tested an example (TotalAccountBalanceExample), and there is a problem in calling "BTCBTC" price. the symbol is invalid. I modify the function in the following way:

public double getTotalAccountBalance(BinanceApiRestClient client, Account account) {
        double totalBalance = 0;
        for (AssetBalance balance : account.getBalances()) {
            double free = Double.parseDouble(balance.getFree());
            double locked = Double.parseDouble(balance.getLocked());
            if (!balance.getAsset().equals(Util.BTC_TICKER)) {
                String ticker = balance.getAsset() + Util.BTC_TICKER;
                String tickerReverse = Util.BTC_TICKER +  balance.getAsset();
                if (free + locked != 0) {
                    if (Util.isFiatCurrency(balance.getAsset())) {
                        double price = Double.parseDouble(client.getPrice(tickerReverse).getPrice());
                        double amount = (free + locked) / price;
                        totalBalance += amount;
                    } else {
                        double price = Double.parseDouble(client.getPrice(ticker).getPrice());
                        double amount = price * (free + locked);
                        totalBalance += amount;
                    }

                }
            } else {
                totalBalance += (free + locked);
            }
        }

        return totalBalance;

    }

cheers,