๐Ÿ“Œ ํ•œ๊ตญํˆฌ์ž์ฆ๊ถŒ API ๊ธฐ๋ฐ˜ ์‹ค์‹œ๊ฐ„ ์ฒด๊ฒฐ ๋ฐ ์ˆ˜์ต๋ฅ  ์•Œ๋ฆผ ๋ด‡ ๊ฐœ๋ฐœ ๊ธฐ๋ก


๐Ÿ“ ๊ฐœ์š”

ํ•œ๊ตญํˆฌ์ž์ฆ๊ถŒ OpenAPI๋ฅผ ํ™œ์šฉํ•ด

์ดˆ๊ธฐ์—๋Š” REST API ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๊ณ , ์ดํ›„ ์›น์†Œ์ผ“ ๊ธฐ๋ฐ˜ ์‹ค์‹œ๊ฐ„ ์ฒด๊ฒฐ ์ˆ˜์‹  ๊ธฐ๋Šฅ๋„ ์ถ”๊ฐ€๋กœ ์‹œ๋„ ์ค‘์ด๋‹ค.


๐Ÿš€ ์ฃผ์š” ๊ธฐ๋Šฅ ๋ฐ ํ๋ฆ„

โœ… 1. ์ธ์ฆ ๋ฐ ํ† ํฐ ๋ฐœ๊ธ‰

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>"
    ...

โœ… 2. ๋ณด์œ  ์ข…๋ชฉ ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ ๋ฐ ๋ฆฌํฌํŠธ ์ „์†ก

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%