diff --git a/kis_agent/account/balance_query_api.py b/kis_agent/account/balance_query_api.py index 91d748a..addaf84 100644 --- a/kis_agent/account/balance_query_api.py +++ b/kis_agent/account/balance_query_api.py @@ -28,22 +28,33 @@ def __init__( def get_account_balance(self) -> Optional[Dict]: """계좌 잔고 조회. output1=보유종목, output2=요약(예수금/총평가/순자산).""" + is_irp = self.account["ACNT_PRDT_CD"] == "29" + endpoint = ( + "/uapi/domestic-stock/v1/trading/inquire-balance" + if not is_irp + else "/uapi/domestic-stock/v1/trading/pension/inquire-balance" + ) + tr_id = "TTTC8434R" if not is_irp else "TTTC2208R" + params = { + "CANO": self.account["CANO"], + "ACNT_PRDT_CD": self.account["ACNT_PRDT_CD"], + "INQR_DVSN": "01" if not is_irp else "00", + "CTX_AREA_FK100": "", + "CTX_AREA_NK100": "", + } + if not is_irp: + params["AFHR_FLPR_YN"] = "N" + params["OFL_YN"] = "" + params["UNPR_DVSN"] = "01" + params["FUND_STTL_ICLD_YN"] = "N" + params["FNCG_AMT_AUTO_RDPT_YN"] = "N" + params["PRCS_DVSN"] = "00" + else: + params["ACCA_DVSN_CD"] = "00" return self._make_request_dict( - endpoint="/uapi/domestic-stock/v1/trading/inquire-balance", - tr_id="TTTC8434R", - params={ - "CANO": self.account["CANO"], - "ACNT_PRDT_CD": self.account["ACNT_PRDT_CD"], - "AFHR_FLPR_YN": "N", - "OFL_YN": "", - "INQR_DVSN": "01", - "UNPR_DVSN": "01", - "FUND_STTL_ICLD_YN": "N", - "FNCG_AMT_AUTO_RDPT_YN": "N", - "PRCS_DVSN": "00", - "CTX_AREA_FK100": "", - "CTX_AREA_NK100": "", - }, + endpoint=endpoint, + tr_id=tr_id, + params=params, ) def get_cash_available( @@ -192,18 +203,31 @@ def inquire_psbl_order( ) -> Optional[Dict]: """매수가능 조회. ord_psbl_cash/max_buy_qty/ord_psbl_qty 반환.""" try: + is_irp = self.account["ACNT_PRDT_CD"] == "29" + endpoint = ( + "/uapi/domestic-stock/v1/trading/inquire-psbl-order" + if not is_irp + else "/uapi/domestic-stock/v1/trading/pension/inquire-psbl-order" + ) + tr_id = ( + "TTTC8908R" if not is_irp else "TTTC0503R" + ) # 모의투자 변환은 client.make_request가 처리 + params = { + "CANO": self.account["CANO"], + "ACNT_PRDT_CD": self.account["ACNT_PRDT_CD"], + "PDNO": pdno, + "ORD_UNPR": str(price), + "ORD_DVSN": ord_dvsn, + "CMA_EVLU_AMT_ICLD_YN": "Y", + } + if not is_irp: + params["OVRS_ICLD_YN"] = "N" + else: + params["ACCA_DVSN_CD"] = "00" res = self.client.make_request( - endpoint="/uapi/domestic-stock/v1/trading/inquire-psbl-order", - tr_id="TTTC8908R", # 모의투자 변환은 client.make_request가 처리 - params={ - "CANO": self.account["CANO"], - "ACNT_PRDT_CD": self.account["ACNT_PRDT_CD"], - "PDNO": pdno, - "ORD_UNPR": str(price), - "ORD_DVSN": ord_dvsn, - "CMA_EVLU_AMT_ICLD_YN": "Y", - "OVRS_ICLD_YN": "N", - }, + endpoint=endpoint, + tr_id=tr_id, # 모의투자 변환은 client.make_request가 처리 + params=params, ) if res and res.get("rt_cd") == "0": return res.get("output", {}) diff --git a/kis_agent/core/auth.py b/kis_agent/core/auth.py index 8b1bd72..57604b8 100644 --- a/kis_agent/core/auth.py +++ b/kis_agent/core/auth.py @@ -363,6 +363,10 @@ def changeTREnv( svr == "prod" and product == "03" or svr == "prod" and product == "08" ): # 실전투자 선물옵션(파생) cfg["my_acct"] = _cfg.get("my_acct_future", "") + elif svr == "prod" and product == "22": # 연금계좌 + cfg["my_acct"] = _cfg.get("my_acct_stock", "") + elif svr == "prod" and product == "29": # IRP. 주문 불가. 계좌조회/시세조회만 가능 + cfg["my_acct"] = _cfg.get("my_acct_stock", "") elif svr == "vps" and product == "01": # 모의투자 주식투자, 위탁계좌, 투자계좌 cfg["my_acct"] = _cfg.get("my_paper_stock", "") elif svr == "vps" and product == "03": # 모의투자 선물옵션(파생)