-
Notifications
You must be signed in to change notification settings - Fork 81
Description
빠른 문제 해결을 위해 다음을 확인했나요?
- PyKis Issues에서 검색했지만 유사한 버그를 찾지 못했습니다.
버그 설명
안녕하세요.
[상황설명]
한가지 종목을 9165원에 8주 매수 하였다가 9175원에 8주 매도 해서 보유 주식 없으며 이익도 거의 없는 상황.
account = kis.account()
balance = account.balance()
print(balance)
File ~/.local/share/virtualenvs/python-yVwRv0JJ/lib/python3.10/site-packages/pykis/api/account/balance.py:304, in KisBalanceStockBase.profit_rate(self) 301 @Property 302 def profit_rate(self) -> Decimal: 303 """손익률 (-100 ~ 100)""" --> 304 return self.profit / self.purchase_amount * 100
InvalidOperation: [<class 'decimal.DivisionUndefined'>]
에러가 발생해서 우선 아래와 같이 수정하였습니다.
def profit_rate(self) -> Decimal:
"""손익률 (-100 ~ 100)"""
if self.purchase_amount == 0:
return Decimal('0') # 매입 금액이 0이면 손익률은 0으로 처리
return self.profit / self.purchase_amount * 100
또한 account.balance().stocks 에 이미 매도하여 보유하고 있지 않은 주식도 qty=0 으로 남아있는데, 의도된 것인가요?
감사합니다.
종속성 버전 문제 진단
Version: PyKis/2.1.3
Python: CPython 3.10.12
System: Linux #22~22.04.1-Ubuntu SMP Fri Feb 21 02:22:41 UTC 2025 [aarch64]
Installed Packages:
=========== requests ===========
Required: 2.32.3>=
Installed: 2.32.3
======= websocket-client =======
Required: 1.8.0>=
Installed: 1.8.0
========= cryptography =========
Required: 43.0.0>=
Installed: 44.0.2
=========== colorlog ===========
Required: 6.8.2>=
Installed: 6.9.0
재현 방법
보유 주식, 손익이 거의 없는 상태에서 balance 조회 시 InvalidOperation: [<class 'decimal.DivisionUndefined'>]
추가 정보
No response
PR를 통해 라이브러리에 기여하고 싶으신가요?
- 네, PR을 제출하여 도움을 주고 싶습니다!