{"id":37403,"date":"2024-11-01T09:57:18","date_gmt":"2024-11-01T09:57:18","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37403"},"modified":"2024-11-01T11:50:58","modified_gmt":"2024-11-01T11:50:58","slug":"developing-python-automated-trading-using-kiwoom-securities-api-koa-studio","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37403\/","title":{"rendered":"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio"},"content":{"rendered":"<p><body><\/p>\n<p>Auto trading is a system that automatically executes trades in the financial market using algorithms. Python is preferred by many traders and developers because it is easy to process data and implement algorithms. This article will explain in detail how to develop an auto trading system using Kiwoom Securities&#8217; API and KOA Studio with Python.<\/p>\n<h2>1. Introduction to Kiwoom Securities API<\/h2>\n<p>The Kiwoom Securities API is provided by Kiwoom Securities, allowing traders to implement their algorithms and collect market data in real-time. The Kiwoom Securities API offers the following features:<\/p>\n<ul>\n<li>Real-time price inquiry<\/li>\n<li>Order transmission and management<\/li>\n<li>Account information inquiry<\/li>\n<li>Transaction history inquiry<\/li>\n<\/ul>\n<h2>2. Introduction to KOA Studio<\/h2>\n<p>KOA Studio is an integrated development environment that allows the development of auto trading systems using Kiwoom Securities&#8217; API. It provides a variety of features to help developers develop easily. The main features of KOA Studio are:<\/p>\n<ul>\n<li>Visual user interface<\/li>\n<li>Data visualization features<\/li>\n<li>Contextual help provided<\/li>\n<li>Code templates provided<\/li>\n<\/ul>\n<h2>3. Environment Setup<\/h2>\n<p>To develop an auto trading system, the environment must be set up in the following order:<\/p>\n<h3>3.1. Open a Kiwoom Securities Account<\/h3>\n<p>First, you need to open an account with Kiwoom Securities. Without a brokerage account, you cannot use the API, so please open an account on the official website.<\/p>\n<h3>3.2. Apply for API Access Approval<\/h3>\n<p>To use the API, you need to apply for API access approval from Kiwoom Securities. Once approved, you will receive an API key, which is required for authentication in the code.<\/p>\n<h3>3.3. Install KOA Studio<\/h3>\n<p>Download and install KOA Studio. Once the installation is complete, run the program to perform the initial setup.<\/p>\n<h2>4. Basic Code Structure<\/h2>\n<p>The basic code structure for an auto trading system is as follows:<\/p>\n<pre><code>import win32com.client\nimport time\n\nclass AutoTrader:\n    def __init__(self):\n        self.app = win32com.client.Dispatch('KHOPENAPI.KHOpenAPICtrl.1')\n        self.app.CommConnect()\n        time.sleep(1)\n\n    def get_stock_price(self, code):\n        price = self.app.CommGetData(\"OPTKWM\", \"\uc870\ud68c\", 0, 0, code)\n        return price\n\n    def buy_stock(self, code, quantity):\n        order_result = self.app.SendOrder(\"Order01\", \"123456\", code, quantity, 0, 0, 0, \"\")\n        return order_result\n\n    def sell_stock(self, code, quantity):\n        order_result = self.app.SendOrder(\"Order01\", \"123456\", code, -quantity, 0, 0, 0, \"\")\n        return order_result\n<\/code><\/pre>\n<p>The above code provides basic functionality to retrieve the current price of stocks and to buy and sell stocks using the Kiwoom Securities API.<\/p>\n<h2>5. Data Collection and Analysis<\/h2>\n<p>To devise an auto trading strategy, it is necessary to collect and analyze market data. You can solidify your strategy by utilizing prices, trading volumes, and technical indicators.<\/p>\n<h3>5.1. Requesting Real-time Prices<\/h3>\n<p>The method for requesting real-time prices to utilize in trading strategies is as follows:<\/p>\n<pre><code>def request_realtime_quotes(self, code):\n    self.app.SetInputValue(\"StockCode\", code)\n    self.app.CommRQData(\"RealTimeInquiry\", \"OPTKWM\", 0, \"0101\")\n<\/code><\/pre>\n<p>The method above is necessary for querying real-time prices of a specific stock.<\/p>\n<h3>5.2. Calculating Technical Indicators<\/h3>\n<p>You can calculate technical indicators based on the collected data. For example, here is how to calculate the moving average (MA):<\/p>\n<pre><code>def calculate_moving_average(prices, period):\n    return sum(prices[-period:]) \/ period\n<\/code><\/pre>\n<h2>6. Implementing Auto Trading Strategy<\/h2>\n<p>Now let&#8217;s implement an auto trading strategy based on the collected data and analysis results. One example would be a simple moving average crossover strategy.<\/p>\n<pre><code>def trading_strategy(self):\n    short_ma = calculate_moving_average(self.prices, short_period)\n    long_ma = calculate_moving_average(self.prices, long_period)\n\n    if short_ma > long_ma:\n        self.buy_stock(self.current_stock_code, 1)\n    elif short_ma < long_ma:\n        self.sell_stock(self.current_stock_code, 1)\n<\/code><\/pre>\n<h2>7. Backtesting<\/h2>\n<p>To validate the effectiveness of the strategy, backtesting based on historical data should be conducted. The pandas library is useful for data analysis. Here\u2019s an example of backtesting:<\/p>\n<pre><code>import pandas as pd\n\ndef backtest_strategy(data, strategy):\n    results = []\n    for index, row in data.iterrows():\n        result = strategy(row)\n        results.append(result)\n    return results\n<\/code><\/pre>\n<h2>8. Conclusion<\/h2>\n<p>In this article, we explored the development of an auto trading system using Python. By utilizing the Kiwoom Securities API and KOA Studio, try to implement your own auto trading strategy. Through Python's powerful data processing capabilities and the Kiwoom Securities API, we hope you discover more opportunities and achieve successful trading.<\/p>\n<h2>9. Additional Resources<\/h2>\n<p>Additional materials and links for auto trading are as follows:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.kiwoom.com\/\">Kiwoom Securities Official Website<\/a><\/li>\n<li><a href=\"http:\/\/www.koinfo.com\/\">KOA Studio Official Website<\/a><\/li>\n<li><a href=\"https:\/\/pandas.pydata.org\/\">Pandas Official Documentation<\/a><\/li>\n<\/ul>\n<p>If you found this article helpful, please share it!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Auto trading is a system that automatically executes trades in the financial market using algorithms. Python is preferred by many traders and developers because it is easy to process data and implement algorithms. This article will explain in detail how to develop an auto trading system using Kiwoom Securities&#8217; API and KOA Studio with Python. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37403\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio&#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-37403","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>Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio - \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\/37403\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Auto trading is a system that automatically executes trades in the financial market using algorithms. Python is preferred by many traders and developers because it is easy to process data and implement algorithms. This article will explain in detail how to develop an auto trading system using Kiwoom Securities&#8217; API and KOA Studio with Python. &hellip; \ub354 \ubcf4\uae30 &quot;Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37403\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:57:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:50:58+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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37403\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37403\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio\",\"datePublished\":\"2024-11-01T09:57:18+00:00\",\"dateModified\":\"2024-11-01T11:50:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37403\/\"},\"wordCount\":544,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Auto Trading\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37403\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37403\/\",\"name\":\"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:57:18+00:00\",\"dateModified\":\"2024-11-01T11:50:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37403\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37403\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37403\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio\"}]},{\"@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":"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio - \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\/37403\/","og_locale":"ko_KR","og_type":"article","og_title":"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Auto trading is a system that automatically executes trades in the financial market using algorithms. Python is preferred by many traders and developers because it is easy to process data and implement algorithms. This article will explain in detail how to develop an auto trading system using Kiwoom Securities&#8217; API and KOA Studio with Python. &hellip; \ub354 \ubcf4\uae30 \"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio\"","og_url":"https:\/\/atmokpo.com\/w\/37403\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:57:18+00:00","article_modified_time":"2024-11-01T11:50:58+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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37403\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37403\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio","datePublished":"2024-11-01T09:57:18+00:00","dateModified":"2024-11-01T11:50:58+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37403\/"},"wordCount":544,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Auto Trading"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37403\/","url":"https:\/\/atmokpo.com\/w\/37403\/","name":"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:57:18+00:00","dateModified":"2024-11-01T11:50:58+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37403\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37403\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37403\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Developing Python Automated Trading, Using Kiwoom Securities API, KOA Studio"}]},{"@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\/37403","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=37403"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37403\/revisions"}],"predecessor-version":[{"id":37404,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37403\/revisions\/37404"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}