{"id":37421,"date":"2024-11-01T09:57:26","date_gmt":"2024-11-01T09:57:26","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37421"},"modified":"2024-11-01T11:50:53","modified_gmt":"2024-11-01T11:50:53","slug":"automated-trading-development-in-python-kiwoom-securities-api-handling-login-events","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37421\/","title":{"rendered":"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events"},"content":{"rendered":"<p><body><\/p>\n<h2>Handling Login Events with Kiwoom Securities API<\/h2>\n<p>Automating stock trading is becoming an increasingly important factor in today&#8217;s investment environment. In this course, we will explain in detail how to handle login events during the development process of automated trading software using the Kiwoom Securities API with Python. The Kiwoom Securities API is very popular in the Korean stock market, offering powerful features and is particularly favored by many traders.<\/p>\n<h2>Introduction to Kiwoom Securities API<\/h2>\n<p>The Kiwoom Securities API is a programming interface provided by Kiwoom Securities that allows users to programmatically execute stock trading. By using the API, various tasks such as buying and selling stocks, checking balances, and collecting market data can be performed. The designed client software can primarily perform the following functions:<\/p>\n<ul>\n<li>Buying and selling stocks<\/li>\n<li>Real-time market data inquiry<\/li>\n<li>Transaction history check<\/li>\n<li>Profit and loss analysis<\/li>\n<\/ul>\n<h2>Setting Up the Environment<\/h2>\n<p>To use the Kiwoom Securities API, the following environment setup is required.<\/p>\n<ol>\n<li>Open a Kiwoom Securities account and register a certified certificate<\/li>\n<li>Install Kiwoom Securities Open API+ on your PC<\/li>\n<li>Install the necessary libraries<\/li>\n<\/ol>\n<p>When you install Kiwoom Securities Open API+, dedicated DLL files that allow you to use &lt;OpenAPI&gt; are provided. To communicate with Python, you need to install the <code>pywin32<\/code> library. To do this, enter the following command:<\/p>\n<div class=\"example-code\">\n<pre><code>pip install pywin32<\/code><\/pre>\n<\/div>\n<h2>Handling Login Events<\/h2>\n<p>The first step of the Kiwoom Securities API is to log in. The basic procedure for handling login events is as follows:<\/p>\n<ol>\n<li>Initialize the API<\/li>\n<li>Send login request<\/li>\n<li>Check login success<\/li>\n<\/ol>\n<h3>Initializing the API<\/h3>\n<p>To use the API, you must first initialize the COM object. Below is a basic code example for initialization:<\/p>\n<div class=\"example-code\">\n<pre><code>import win32com.client\n\n# Initialize Kiwoom Securities API\nkiwoom = win32com.client.Dispatch(\"KHOpenAPI.KHOpenAPICtrl.1\")<\/code><\/pre>\n<\/div>\n<h3>Sending a Login Request<\/h3>\n<p>Login is accomplished by calling the &lt;CommConnect&gt; method. This method opens a login window and processes the login. Below is the code for sending a login request:<\/p>\n<div class=\"example-code\">\n<pre><code># Send login request\nkiwoom.CommConnect()  # Create login window<\/code><\/pre>\n<\/div>\n<h3>Handling Login Events<\/h3>\n<p>After sending the login request, you need to handle the information about the login result. You can check the login result using the &lt;OnEventConnect&gt; event handler. This event is called upon successful login and can be handled as follows:<\/p>\n<div class=\"example-code\">\n<pre><code>class MyKiwoom:\n    def __init__(self):\n        self.kiwoom = win32com.client.Dispatch(\"KHOpenAPI.KHOpenAPICtrl.1\")\n        self.kiwoom.OnEventConnect.connect(self.on_event_connect)\n\n    def login(self):\n        self.kiwoom.CommConnect()  # Send login request\n\n    def on_event_connect(self, err_code):\n        if err_code == 0:\n            print(\"Login successful\")\n        else:\n            print(\"Login failed, error code:\", err_code)\n\n# Example usage\nmy_kiwoom = MyKiwoom()\nmy_kiwoom.login()<\/code><\/pre>\n<\/div>\n<h2>Actions After Successful Login<\/h2>\n<p>After a successful login, you can now make various requests through the API. Below is how to retrieve a list of held stocks after logging in:<\/p>\n<div class=\"example-code\">\n<pre><code>def get_stock_list(self):\n        count = self.kiwoom.GetAccountList()\n        stock_list = []\n        for i in range(count):\n            stock_code = self.kiwoom.GetAccountStock(i)\n            if stock_code:\n                stock_list.append(stock_code)\n        return stock_list\n\n# Example of retrieving held stocks\nprint(my_kiwoom.get_stock_list())<\/code><\/pre>\n<\/div>\n<h2>Conclusion and Further Advice<\/h2>\n<p>In this session, we learned how to handle login events using the Kiwoom Securities API. The possibilities for automating stock trading through various API methods are limitless. It is also advisable to explore how to build automated trading algorithms using real-time data.<\/p>\n<p>Finally, remember that stock trading always carries risks, so be sure to conduct sufficient testing before proceeding with automated trading!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Handling Login Events with Kiwoom Securities API Automating stock trading is becoming an increasingly important factor in today&#8217;s investment environment. In this course, we will explain in detail how to handle login events during the development process of automated trading software using the Kiwoom Securities API with Python. The Kiwoom Securities API is very popular &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37421\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events&#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-37421","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>Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events - \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\/37421\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Handling Login Events with Kiwoom Securities API Automating stock trading is becoming an increasingly important factor in today&#8217;s investment environment. In this course, we will explain in detail how to handle login events during the development process of automated trading software using the Kiwoom Securities API with Python. The Kiwoom Securities API is very popular &hellip; \ub354 \ubcf4\uae30 &quot;Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37421\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:57:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:50:53+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\/37421\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37421\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events\",\"datePublished\":\"2024-11-01T09:57:26+00:00\",\"dateModified\":\"2024-11-01T11:50:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37421\/\"},\"wordCount\":457,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Auto Trading\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37421\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37421\/\",\"name\":\"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:57:26+00:00\",\"dateModified\":\"2024-11-01T11:50:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37421\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37421\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37421\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events\"}]},{\"@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":"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events - \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\/37421\/","og_locale":"ko_KR","og_type":"article","og_title":"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Handling Login Events with Kiwoom Securities API Automating stock trading is becoming an increasingly important factor in today&#8217;s investment environment. In this course, we will explain in detail how to handle login events during the development process of automated trading software using the Kiwoom Securities API with Python. The Kiwoom Securities API is very popular &hellip; \ub354 \ubcf4\uae30 \"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events\"","og_url":"https:\/\/atmokpo.com\/w\/37421\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:57:26+00:00","article_modified_time":"2024-11-01T11:50:53+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\/37421\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37421\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events","datePublished":"2024-11-01T09:57:26+00:00","dateModified":"2024-11-01T11:50:53+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37421\/"},"wordCount":457,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Auto Trading"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37421\/","url":"https:\/\/atmokpo.com\/w\/37421\/","name":"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:57:26+00:00","dateModified":"2024-11-01T11:50:53+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37421\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37421\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37421\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Automated Trading Development in Python, Kiwoom Securities API, Handling Login Events"}]},{"@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\/37421","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=37421"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37421\/revisions"}],"predecessor-version":[{"id":37422,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37421\/revisions\/37422"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}