ํ๊ตญํฌ์์ฆ๊ถ OpenAPI๋ฅผ ํ์ฉํด
์ด๊ธฐ์๋ REST API ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํํ๊ณ , ์ดํ ์น์์ผ ๊ธฐ๋ฐ ์ค์๊ฐ ์ฒด๊ฒฐ ์์ ๊ธฐ๋ฅ๋ ์ถ๊ฐ๋ก ์๋ ์ค์ด๋ค.
access_token
: REST API ํธ์ถ์ฉ ์ธ์ฆ ํ ํฐapproval_key
: ์น์์ผ ์ฒด๊ฒฐ ์์ ์ ์ํ ์น์ธ ํคdef get_kis_access_token():
url = "<https://openapi.koreainvestment.com:9443/oauth2/tokenP>"
...
def get_approval_key():
url = "<https://openapi.koreainvestment.com:9443/oauth2/Approval>"
...
def get_account_profit():
for item in res["output1"]:
hold_qty = int(item["hldg_qty"])
avg_price = float(item["pchs_avg_pric"])
current_price = float(item["prpr"])
eval_amt = hold_qty * current_price
invest_amt = hold_qty * avg_price
profit_amt = eval_amt - invest_amt
profit_rate = ((current_price - avg_price) / avg_price) * 100
์์) ๋ฉ์์ง ํ์
๐ ์ผ์ฑ์ ์
โ ์๋: 10์ฃผ | ํ๊ท ๋จ๊ฐ: 60,000์ | ํ์ฌ๊ฐ: 63,000์
โ ํ๊ฐ๊ธ์ก: 630,000์ | ์์ต๊ธ: 30,000์ | ์์ต๋ฅ : 5.00%