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

get_balance 메서드의 verbose 옵션에서의 반환 값 이상 #83

Open
mr-yoo opened this issue May 14, 2022 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@mr-yoo
Copy link
Collaborator

mr-yoo commented May 14, 2022

verbose 옵션은 딕셔너리로 서버가 반환하는 값을 그대로 출력해야 한다. get_balance 메서드에서 verbose 옵션으로 리플의 잔고를 조회하는 경우를 살펴 봅시다.

upbit.get_balance(ticker="XRP", verbose=True)

리플을 보유하고 있다면 딕셔너리로 출력되지만 보유하지 않은 경우 0이 반환된다. 내부에서 초기값을 0으로 설정하고 값을 반복문 내부에서 데이터를 채워넣는데, 리플을 보유하고 있지 않아 조건을 충족하지 않으므로 초기값 0이 그대로 반환된다.

balance = 0
for x in balances:
    if x['currency'] == ticker and x['unit_currency'] == fiat:
        if verbose is True:
            balance = x 
        else:
            balance = float(x['balance'])
        break
@mr-yoo mr-yoo added the bug Something isn't working label May 14, 2022
@mr-yoo mr-yoo self-assigned this May 14, 2022
@mr-yoo
Copy link
Collaborator Author

mr-yoo commented May 14, 2022

@brayden-jo 초기화를 이렇게 하면 어떨까요?

if verbose is True:
    balance = {
        'currency': 'KRW', 
        'balance': '0.0', 
        'locked': '0.0', 
        'avg_buy_price': '0', 
        'avg_buy_price_modified': True, 
        'unit_currency': 'KRW'
    }
else:
    balance = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant