KevinFire2030 / Fire2025

0 stars 0 forks source link

opw00018 TR #10

Open KevinFire2030 opened 1 year ago

KevinFire2030 commented 1 year ago

싱글 데이터를 통해 계좌에 대한 평가 잔고 데이터

멀티 데이터를 통해 보유 종목별 평가 잔고 데이터


# multi data
rows = self._get_repeat_cnt(trcode, rqname)
for i in range(rows):
    name = self._comm_get_data(trcode, "", rqname, i, "종목명")
    quantity = self._comm_get_data(trcode, "", rqname, i, "보유수량")
    purchase_price = self._comm_get_data(trcode, "", rqname, i, "매입가")
    current_price = self._comm_get_data(trcode, "", rqname, i, "현재가")
    eval_profit_loss_price = self._comm_get_data(trcode, "", rqname, i, "평가손익")
    earning_rate = self._comm_get_data(trcode, "", rqname, i, "수익률(%)")

    quantity = Kiwoom.change_format(quantity)
    purchase_price = Kiwoom.change_format(purchase_price)
    current_price = Kiwoom.change_format(current_price)
    eval_profit_loss_price = Kiwoom.change_format(eval_profit_loss_price)
    earning_rate = Kiwoom.change_format2(earning_rate)

    print(name, quantity, purchase_price, current_price, eval_profit_loss_price, earning_rate)

멀티 데이터는 먼저 _get_repeat_cnt 메서드를 호출해 보유 종목의 개수를 얻어옵니다. 런 다음 해당 개수만큼 반복하면서 각 보유 종목에 대한 상세 데이터를 _comm_get_data를 통해 얻어옵니다. 참고로 opw00018 TR을 사용하는 경우 한 번의 TR 요청으로 최대 20개의 보유 종목에 대한 데이터를 얻을 수 있습니다.

opw00018 TR을 통해 얻어온 데이터를 인스턴스 변수에 저장

def reset_opw00018_output(self):
    self.opw00018_output = {'single': [], 'multi': []}

def _opw00018(self, rqname, trcode):
    # single data
    total_purchase_price = self._comm_get_data(trcode, "", rqname, 0, "총매입금액")
    total_eval_price = self._comm_get_data(trcode, "", rqname, 0, "총평가금액")
    total_eval_profit_loss_price = self._comm_get_data(trcode, "", rqname, 0, "총평가손익금액")
    total_earning_rate = self._comm_get_data(trcode, "", rqname, 0, "총수익률(%)")
    estimated_deposit = self._comm_get_data(trcode, "", rqname, 0, "추정예탁자산")

    self.opw00018_output['single'].append(Kiwoom.change_format(total_purchase_price))
    self.opw00018_output['single'].append(Kiwoom.change_format(total_eval_price))
    self.opw00018_output['single'].append(Kiwoom.change_format(total_eval_profit_loss_price))
    self.opw00018_output['single'].append(Kiwoom.change_format(total_earning_rate))
    self.opw00018_output['single'].append(Kiwoom.change_format(estimated_deposit))

    # multi data
    rows = self._get_repeat_cnt(trcode, rqname)
    for i in range(rows):
        name = self._comm_get_data(trcode, "", rqname, i, "종목명")
        quantity = self._comm_get_data(trcode, "", rqname, i, "보유수량")
        purchase_price = self._comm_get_data(trcode, "", rqname, i, "매입가")
        current_price = self._comm_get_data(trcode, "", rqname, i, "현재가")
        eval_profit_loss_price = self._comm_get_data(trcode, "", rqname, i, "평가손익")
        earning_rate = self._comm_get_data(trcode, "", rqname, i, "수익률(%)")

        quantity = Kiwoom.change_format(quantity)
        purchase_price = Kiwoom.change_format(purchase_price)
        current_price = Kiwoom.change_format(current_price)
        eval_profit_loss_price = Kiwoom.change_format(eval_profit_loss_price)
        earning_rate = Kiwoom.change_format2(earning_rate)

        self.opw00018_output['multi'].append([name, quantity, purchase_price, current_price,              
eval_profit_loss_price, earning_rate])

서버 구분

def get_server_gubun(self):
    ret = self.dynamicCall("KOA_Functions(QString, QString)", "GetServerGubun", "")
    return ret
total_earning_rate = Kiwoom.change_format(total_earning_rate)

if self.get_server_gubun():
    total_earning_rate = float(total_earning_rate) / 100
    total_earning_rate = str(total_earning_rate)

self.opw00018_output['single'].append(total_earning_rate)

[답변] 모의투자 선물 계좌는 예수금상세현황요청이 않되네요.