{"id":37415,"date":"2024-11-01T09:57:23","date_gmt":"2024-11-01T09:57:23","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37415"},"modified":"2024-11-01T11:50:55","modified_gmt":"2024-11-01T11:50:55","slug":"python-automated-trading-development-kiwoom-securities-api-fetching-account-information","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37415\/","title":{"rendered":"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information"},"content":{"rendered":"<p><body><\/p>\n<p>Developing an automated trading system has become a very popular topic among stock investors these days. Such systems refer to mechanisms that use computer programs to buy and sell stocks automatically. In this course, we will learn about the first step in automated trading development using Python, focusing on how to retrieve account information using the Kiwoom Securities API.<\/p>\n<h2>1. What is the Kiwoom Securities API?<\/h2>\n<p>The Kiwoom Securities API is a service provided through Kiwoom Securities&#8217; Open API, which enables users to view and trade stocks, futures, and options, as well as access account information and market data through programs. This API allows investors to automatically execute various strategies.<\/p>\n<h2>2. Preparing to Use the Kiwoom Securities API<\/h2>\n<p>To use the Kiwoom Securities API, the following preparations are necessary.<\/p>\n<ol>\n<li>Open a Kiwoom Securities account: You need to open an account with Kiwoom Securities.<\/li>\n<li>Apply for Open API: You need to apply for permission to use the Open API at Kiwoom Securities.<\/li>\n<li>Set up API environment: You need to configure the environment on the computer where the API will be used.<\/li>\n<\/ol>\n<h3>2.1 How to Apply for Open API<\/h3>\n<p>After logging into the Kiwoom Securities website, you can request permission to use the API through the Open API service application. Once your request is approved, you will receive an API key, allowing you to access the API.<\/p>\n<h3>2.2 API Environment Setup<\/h3>\n<p>To use the API, you need a package that can send and receive HTTP requests in Python. We will mainly use the <code>pywin32<\/code> library to interact with Windows COM objects. This library can be installed using the following method.<\/p>\n<pre><code>pip install pywin32<\/code><\/pre>\n<h2>3. Retrieving Account Information<\/h2>\n<p>Now, let&#8217;s learn how to retrieve account information through the Kiwoom Securities API with actual code.<\/p>\n<h3>3.1 Logging into the Kiwoom Securities API<\/h3>\n<p>To use the API, you must first log in. The following code shows how to create a login window using PyQt5 and check the login status.<\/p>\n<pre><code>import os\nimport sys\nimport pythoncom\nimport win32com.client\n\nfrom PyQt5 import QtWidgets\n\nclass Kiwoom:\n    def __init__(self):\n        self.app = QtWidgets.QApplication(sys.argv)\n        self.khw = win32com.client.Dispatch(\"KH OPENAPI\")  # Create Kiwoom API object\n        self.khw.OnEventConnect.connect(self._on_event_connect)\n\n    def login(self):\n        self.khw.CommConnect()  # Request login\n\n    def _on_event_connect(self, err_code):\n        if err_code == 0:\n            print(\"Login successful\")\n        else:\n            print(\"Login failed\")\n\nif __name__ == \"__main__\":\n    kiwoom = Kiwoom()\n    kiwoom.login()\n    pythoncom.PumpThreads()  # Maintain event loop\n<\/code><\/pre>\n<h3>3.2 Retrieving Account Information<\/h3>\n<p>If you have successfully logged in, you can now retrieve account information. Here is how to query account information through the Kiwoom Securities API.<\/p>\n<pre><code>class Kiwoom:\n    # Following the previous code\n    def get_account_info(self):\n        account_list = self.khw.GetLoginInfo(\"ACCNO\")  # Query account numbers\n        print(\"Account list:\", account_list)\n\n        # Request information for all accounts\n        for account in account_list.split(';'):\n            if account:\n                print(\"Account number:\", account)\n\nif __name__ == \"__main__\":\n    kiwoom = Kiwoom()\n    kiwoom.login()\n    pythoncom.PumpThreads()\n    kiwoom.get_account_info()  # Retrieve account information\n<\/code><\/pre>\n<p>The code above retrieves the user&#8217;s account list and prints each account number. You can retrieve account information using the <code>GetLoginInfo<\/code> method. Based on this information, you can retrieve other necessary information or proceed with trading.<\/p>\n<h2>4. Querying Asset Information by Account<\/h2>\n<p>Let&#8217;s learn how to query asset information for each account. You can check the quantity of stocks held and the assessed value, among other details.<\/p>\n<pre><code>class Kiwoom:\n    # Following the previous code\n    def get_account_assets(self):\n        # Request asset information (AT: assessed value\/current price)\n        self.khw.SetInputValue(\"Account Number\", \"Enter account number\")\n        self.khw.SetInputValue(\"Password\", \"\")  # Password\n        self.khw.SetInputValue(\"Consultation Type\", \"0\")  # 0: General, 1: Spot, 2: Futures, 3: Options\n        self.khw.CommRcvData(\"010101\", 0)  # Request\n\nif __name__ == \"__main__\":\n    kiwoom = Kiwoom()\n    kiwoom.login()\n    pythoncom.PumpThreads()\n    kiwoom.get_account_assets()  # Retrieve asset information\n<\/code><\/pre>\n<h2>5. Conclusion<\/h2>\n<p>In this course, we explained how to retrieve account information using the Kiwoom Securities API. In the future, you will learn how to implement trading functionalities and market information retrieval to develop your own automated trading system. In the next course, we will implement additional features for actual trading.<\/p>\n<h2>6. Reference Materials<\/h2>\n<ul>\n<li><a href=\"https:\/\/openapi.koreainvestment.com\">Kiwoom Securities Open API Documentation<\/a><\/li>\n<li><a href=\"https:\/\/www.python.org\/\">Official Python Website<\/a><\/li>\n<li><a href=\"https:\/\/planetscale.com\/\">PyQt5 Installation Documentation<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Developing an automated trading system has become a very popular topic among stock investors these days. Such systems refer to mechanisms that use computer programs to buy and sell stocks automatically. In this course, we will learn about the first step in automated trading development using Python, focusing on how to retrieve account information using &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37415\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[147],"tags":[],"class_list":["post-37415","post","type-post","status-publish","format-standard","hentry","category-python-auto-trading"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/37415\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Developing an automated trading system has become a very popular topic among stock investors these days. Such systems refer to mechanisms that use computer programs to buy and sell stocks automatically. In this course, we will learn about the first step in automated trading development using Python, focusing on how to retrieve account information using &hellip; \ub354 \ubcf4\uae30 &quot;Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37415\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:57:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:50:55+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37415\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37415\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information\",\"datePublished\":\"2024-11-01T09:57:23+00:00\",\"dateModified\":\"2024-11-01T11:50:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37415\/\"},\"wordCount\":482,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Auto Trading\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37415\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37415\/\",\"name\":\"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:57:23+00:00\",\"dateModified\":\"2024-11-01T11:50:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37415\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37415\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37415\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/37415\/","og_locale":"ko_KR","og_type":"article","og_title":"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Developing an automated trading system has become a very popular topic among stock investors these days. Such systems refer to mechanisms that use computer programs to buy and sell stocks automatically. In this course, we will learn about the first step in automated trading development using Python, focusing on how to retrieve account information using &hellip; \ub354 \ubcf4\uae30 \"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information\"","og_url":"https:\/\/atmokpo.com\/w\/37415\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:57:23+00:00","article_modified_time":"2024-11-01T11:50:55+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37415\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37415\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information","datePublished":"2024-11-01T09:57:23+00:00","dateModified":"2024-11-01T11:50:55+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37415\/"},"wordCount":482,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Auto Trading"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37415\/","url":"https:\/\/atmokpo.com\/w\/37415\/","name":"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:57:23+00:00","dateModified":"2024-11-01T11:50:55+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37415\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37415\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37415\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Python Automated Trading Development, Kiwoom Securities API, Fetching Account Information"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=37415"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37415\/revisions"}],"predecessor-version":[{"id":37416,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37415\/revisions\/37416"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}