{"id":37423,"date":"2024-11-01T09:57:28","date_gmt":"2024-11-01T09:57:28","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37423"},"modified":"2024-11-01T11:50:52","modified_gmt":"2024-11-01T11:50:52","slug":"automated-trading-development-with-python-kiwoom-securities-api-sign-up-for-paper-trading","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37423\/","title":{"rendered":"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading"},"content":{"rendered":"<article>\n<p>This article will detail how to develop an automated trading system using Python and how to use the Kiwoom Securities API. It will also include the process of signing up for simulated trading, providing a way to safely test the developed program before investing real money.<\/p>\n<h2>1. What is Automated Trading?<\/h2>\n<p>Automated trading (Algorithmic Trading) refers to a system where a program automatically executes trades according to a specific algorithm. This allows for faster and more accurate trading, eliminating emotional judgment.<\/p>\n<h2>2. What is the Kiwoom Securities API?<\/h2>\n<p>The Kiwoom Securities API is a program interface provided by Kiwoom Securities that allows investors to directly trade stocks through their own programs. The API enables easy access to real-time pricing information, order entry, execution confirmation, and more.<\/p>\n<h3>2.1 Advantages of the API<\/h3>\n<ul>\n<li>Real-time data provision<\/li>\n<li>Automation of orders and trades programmatically<\/li>\n<li>Implementation of various strategies<\/li>\n<\/ul>\n<h3>2.2 Disadvantages of the API<\/h3>\n<ul>\n<li>Requires a thorough understanding and practice<\/li>\n<li>Need to ensure system stability and reliability<\/li>\n<\/ul>\n<h2>3. How to Sign Up for Simulated Trading<\/h2>\n<p>Simulated trading is a system that allows you to experience investing under the same conditions as real trading. Open a simulated trading account provided by Kiwoom Securities and try it for free.<\/p>\n<h3>3.1 How to Open a Simulated Trading Account<\/h3>\n<ol>\n<li>Visit the Kiwoom Securities website and complete the registration process.<\/li>\n<li>After logging in, select the &#8216;Simulated Trading&#8217; menu.<\/li>\n<li>Proceed with the application for opening a simulated trading account.<\/li>\n<li>Once the application is completed, you will receive your account number and password.<\/li>\n<\/ol>\n<h2>4. Installing the Kiwoom Securities API<\/h2>\n<p>Next, you need to install the necessary software to use the Kiwoom Securities API as follows.<\/p>\n<h3>4.1 Prerequisites<\/h3>\n<ul>\n<li>Install Kiwoom Securities OpenAPI+<\/li>\n<li>Install Python (recommended version: 3.8 or higher)<\/li>\n<li>Python modules: pywin32, numpy, pandas, etc.<\/li>\n<\/ul>\n<h3>4.2 Installing Kiwoom Securities OpenAPI+<\/h3>\n<p>The Kiwoom Securities OpenAPI+ can be downloaded from Kiwoom Securities, and after installation, you need to log in to configure your settings. After installation, you must activate the &#8216;Switch to Simulated Trading&#8217; checkbox in the &#8216;API Settings&#8217;.<\/p>\n<h2>5. Writing an Automated Trading Program in Python<\/h2>\n<p>Now, let&#8217;s create an automated trading program in Python. Below is an example code for a basic trading system.<\/p>\n<h3>5.1 Basic Code Structure<\/h3>\n<pre><code>import sys\nimport time\nimport win32com.client\n\nclass AutoTrade:\n    def __init__(self):\n        self.api = win32com.client.Dispatch(\"KHOPENAPI.KHOpenAPICtrl.1\")\n        self.login()\n\n    def login(self):\n        # Login\n        self.api.CommConnect()\n        print(\"Login completed\")\n\n    def buy(self, code, qty):\n        # Buy function\n        self.api.SendOrder(\"buyOrder\", \"0101\", self.api.GetAccountList(0), 1, code, qty, 0, \"03\", \"\")\n\n    def sell(self, code, qty):\n        # Sell function\n        self.api.SendOrder(\"sellOrder\", \"0101\", self.api.GetAccountList(0), 2, code, qty, 0, \"03\", \"\")\n\n    def check_balance(self):\n        # Check balance\n        balance = self.api.GetAccInfo(1)\n        print(\"Current balance:\", balance)\n\nif __name__ == \"__main__\":\n    trader = AutoTrade()\n    trader.check_balance()\n    trader.buy(\"005930\", 1)  # Buy Samsung Electronics\n    time.sleep(1)\n    trader.sell(\"005930\", 1)  # Sell Samsung Electronics\n<\/code><\/pre>\n<h3>5.2 Code Explanation<\/h3>\n<p>The above code demonstrates connecting to the Kiwoom Securities API through the AutoTrade class and trading stocks using the buy and sell functions. It also includes a balance-checking feature.<\/p>\n<h2>6. Implementing Strategies<\/h2>\n<p>The core of an automated trading program is the investment strategy. Let&#8217;s implement a simple moving average crossover strategy.<\/p>\n<h3>6.1 Implementing the Moving Average Crossover Strategy<\/h3>\n<pre><code>import pandas as pd\n\nclass MovingAverageStrategy:\n    def __init__(self, trader):\n        self.trader = trader\n\n    def execute(self, code):\n        data = self.get_historical_data(code)\n        data['SMA20'] = data['close'].rolling(window=20).mean()\n        data['SMA50'] = data['close'].rolling(window=50).mean()\n\n        # Generate trading signals\n        if data['SMA20'].iloc[-1] > data['SMA50'].iloc[-1]:\n            self.trader.buy(code, 1)\n        elif data['SMA20'].iloc[-1] < data['SMA50'].iloc[-1]:\n            self.trader.sell(code, 1)\n\n    def get_historical_data(self, code):\n        # Collect historical data (example)\n        # Implement actual data collection logic\n        return pd.DataFrame()  # Placeholder\n\nif __name__ == \"__main__\":\n    trader = AutoTrade()\n    strategy = MovingAverageStrategy(trader)\n    strategy.execute(\"005930\")  # Samsung Electronics\n<\/code><\/pre>\n<h3>6.2 Strategy Explanation<\/h3>\n<p>The moving average strategy above generates trading signals by comparing the 20-day and 50-day simple moving averages (SMA). A buy signal occurs when the 20-day SMA crosses above the 50-day SMA, and a sell signal occurs when it crosses below.<\/p>\n<h2>7. Analyzing Automated Trading Performance<\/h2>\n<p>Automated trading systems should continuously analyze and improve performance. The following elements should be included in performance analysis:<\/p>\n<h3>7.1 Performance Indicators<\/h3>\n<ul>\n<li>Total return<\/li>\n<li>Maximum drawdown<\/li>\n<li>Sharpe ratio<\/li>\n<\/ul>\n<h3>7.2 Recording Results<\/h3>\n<p>Record trading results for analysis. Trading results can be saved in formats such as CSV files.<\/p>\n<h2>8. Conclusion<\/h2>\n<p>In this article, we explored automated trading using Python, how to use the Kiwoom Securities API, and how to sign up for simulated trading. This enables beginners to easily develop automated trading systems and test them in an environment similar to real trading. Continue to research and develop various strategies!<\/p>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>This article will detail how to develop an automated trading system using Python and how to use the Kiwoom Securities API. It will also include the process of signing up for simulated trading, providing a way to safely test the developed program before investing real money. 1. What is Automated Trading? Automated trading (Algorithmic Trading) &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37423\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading&#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-37423","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 with Python, Kiwoom Securities API, Sign Up for Paper Trading - \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\/37423\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"This article will detail how to develop an automated trading system using Python and how to use the Kiwoom Securities API. It will also include the process of signing up for simulated trading, providing a way to safely test the developed program before investing real money. 1. What is Automated Trading? Automated trading (Algorithmic Trading) &hellip; \ub354 \ubcf4\uae30 &quot;Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37423\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:57:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:50:52+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\/37423\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37423\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading\",\"datePublished\":\"2024-11-01T09:57:28+00:00\",\"dateModified\":\"2024-11-01T11:50:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37423\/\"},\"wordCount\":567,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Auto Trading\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37423\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37423\/\",\"name\":\"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:57:28+00:00\",\"dateModified\":\"2024-11-01T11:50:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37423\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37423\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37423\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading\"}]},{\"@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 with Python, Kiwoom Securities API, Sign Up for Paper Trading - \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\/37423\/","og_locale":"ko_KR","og_type":"article","og_title":"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"This article will detail how to develop an automated trading system using Python and how to use the Kiwoom Securities API. It will also include the process of signing up for simulated trading, providing a way to safely test the developed program before investing real money. 1. What is Automated Trading? Automated trading (Algorithmic Trading) &hellip; \ub354 \ubcf4\uae30 \"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading\"","og_url":"https:\/\/atmokpo.com\/w\/37423\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:57:28+00:00","article_modified_time":"2024-11-01T11:50:52+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\/37423\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37423\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading","datePublished":"2024-11-01T09:57:28+00:00","dateModified":"2024-11-01T11:50:52+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37423\/"},"wordCount":567,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Auto Trading"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37423\/","url":"https:\/\/atmokpo.com\/w\/37423\/","name":"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:57:28+00:00","dateModified":"2024-11-01T11:50:52+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37423\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37423\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37423\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Automated Trading Development with Python, Kiwoom Securities API, Sign Up for Paper Trading"}]},{"@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\/37423","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=37423"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37423\/revisions"}],"predecessor-version":[{"id":37424,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37423\/revisions\/37424"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}