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

Adding functionality to get_balances to return for a specified account id only #25

Open
YinYin-blip opened this issue Dec 16, 2020 · 2 comments

Comments

@YinYin-blip
Copy link

Instead of the response having all accounts in a list. It would return a single account.
Example call:
print(luno.get_balances(account_id='12345678910'))

Example output:
{'account_id': '12345678910', 'asset': 'XBT', 'balance': '0.00', 'reserved': '0.00', 'unconfirmed': '0.00'}

@amustapha
Copy link

honestly, It's more efficient to fetch all balances and use a filter/find to return a specific balance.

@YinYin-blip
Copy link
Author

YinYin-blip commented Aug 6, 2022

@aamustapha I think we are saying the same thing. I just created this issue to start a conversation about whether this filtering would be useful to have in this client or if the filtering should be done by some calling function.

Here is my suggestion:

    def get_balances(self, assets=None, account_id=None):
        """
        :param account_id: filter api response to return a specific account only 
        """
        req = {
            'assets': assets,
        }
        if account_id:
            response = self.do('GET', '/api/1/balance', req=req, auth=True)
            for account in response["balances"]:
                if account_id == account["account_id"]:
                    return account
        else:
            return self.do('GET', '/api/1/balance', req=req, auth=True)

In terms of coding design, it might be a bad idea to have this client do the filtering AND the api calls. But we could also add a "filter" argument to some functions.

def get_balances(self, assets=None, filters=None):
luno.get_balances(assets=None, filters={account_id: "123456762"})

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