Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with retrieving getAccountBalances or getBalances for Kraken #9

Closed
maakle opened this issue Mar 10, 2018 · 1 comment
Closed

Comments

@maakle
Copy link
Contributor

maakle commented Mar 10, 2018

Hey Sathya,

Both functions getAccountBalances and getBalances are failing at the guard statement:
print("Error: Cast Failed in \(#function)")

It seems like that response.json is actually not of the type [[String: String]] but actually gives back an answer. I adjusted the function now to this one here which seems works since I am creating a new Balance object and assign the values, though the rest of the krakenService.store.balances object later is then messed up e.g. ...xxx.currency.code etc. My function:

        public func getAccountBalances(completion: @escaping (ResponseType) -> Void) {
            let apiType = Kraken.API.getAccountBalance
            if apiType.checkInterval(response: store.balanceResponse) {
                completion(.cached)
            } else {
                krakenDataTaskFor(api: apiType) { (response) in
                    
                    guard let json = response.json as? Dictionary<String, Any> else {
                        print("Error: Cast Failed in \(#function)")
                        return
                    }
                    let arrayOfCryptoBalances = json["result"] as! Dictionary<String,String>
                    var balances: [Balance] = []

                    for cryptoBalance in arrayOfCryptoBalances {
                        let newBalance = ["type": cryptoBalance.key,
                                       "amount": cryptoBalance.value,
                                       "available": cryptoBalance.value]
                        
                        balances.append(Balance(json: newBalance, currencyStore: self))
                    }

                    self.store.balances = balances
                    self.store.balanceResponse = response.httpResponse
                    completion(.fetched)
                    }.resume()
            }
        }

Do you want me to create a pull request with my solution or are you taking care of it yourself? Maybe Kraken has updated the API since you wrote it. Also I found it annoying by Kraken that they decided to call most of the crypto currencies with own symbols. e.g. XBT instead of BTC for Bitcoin... is this what your overwrite function is for?

Best,
Matt

@trsathya
Copy link
Owner

PR. Yes. Please. Thanks. Highly appreciated.

Yes. Currency overrides are for exchanges using their own code vs ISO 4217 code. Ironically XBT is the ISO 4217 compliant code for Bitcoin. lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants