{"id":37407,"date":"2024-11-01T09:57:20","date_gmt":"2024-11-01T09:57:20","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37407"},"modified":"2024-11-01T11:50:57","modified_gmt":"2024-11-01T11:50:57","slug":"automated-trading-development-kiwoom-securities-api-pyqt-basics","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37407\/","title":{"rendered":"Automated Trading Development, Kiwoom Securities API, PyQt Basics"},"content":{"rendered":"<p><body><\/p>\n<article>\n<p>Stock trading is becoming increasingly automated, with many traders seeking to use algorithms for more efficient trading. This article will cover the basics of developing an automated trading system using the Kiwoom Securities API with Python and introduce how to create a user interface using PyQt.<\/p>\n<h2>1. Introduction to Python and the Concept of Automated Trading<\/h2>\n<p>Python is a high-level programming language used in various fields. It is particularly useful in data analysis, machine learning, web development, and more. Automated trading refers to a system that automatically executes trades based on a specified algorithm, saving time and effort for many investors.<\/p>\n<h2>2. What is the Kiwoom Securities API?<\/h2>\n<p>The Kiwoom Securities API defines the interface between the programs provided by Kiwoom Securities and users. This allows developers to programmatically control stock trading, market information retrieval, order placement, and more. To use the Kiwoom Securities API, one must first open an account with Kiwoom Securities and apply for the Open API service.<\/p>\n<h3>2.1. How to Apply for Open API<\/h3>\n<ol>\n<li>Access the Kiwoom Securities website and open an account.<\/li>\n<li>Find the Open API application menu and apply.<\/li>\n<li>Once API usage approval is complete, you will receive an API authentication key.<\/li>\n<\/ol>\n<h2>3. Basic Structure of an Automated Trading System<\/h2>\n<p>An automated trading system generally consists of the following components:<\/p>\n<ul>\n<li>Data Collection: Collecting data such as stock prices and trading volumes.<\/li>\n<li>Strategy Development: Establishing trading strategies based on the collected data.<\/li>\n<li>Order Execution: Automatically placing orders according to the strategy.<\/li>\n<li>Monitoring: Monitoring the system&#8217;s status and performance in real time.<\/li>\n<\/ul>\n<h2>4. How to Use the Kiwoom Securities API<\/h2>\n<p>Below is an example code to retrieve stock information using the Kiwoom Securities API.<\/p>\n<pre>\n<code>\nimport pythoncom\nimport win32com.client\n\n# Initialize Kiwoom Securities API object\ndef init_api():\n    pythoncom.CoInitialize()\n    return win32com.client.Dispatch(\"KHOPENAPI.KHOpenAPI\")\n\n# Retrieve stock information\ndef get_stock_info(code):\n    api = init_api()\n    price = api.GetMasterLastPrice(code)\n    name = api.GetMasterCodeName(code)\n    return name, price\n\nif __name__ == \"__main__\":\n    stock_code = \"005930\"  # Samsung Electronics code\n    stock_name, stock_price = get_stock_info(stock_code)\n    print(f\"The current price of {stock_name} is: {stock_price} won\")\n<\/code>\n        <\/pre>\n<h2>5. UI Development Using PyQt<\/h2>\n<p>PyQt is a library that helps build GUIs using the Qt framework in Python. This chapter will explain how to create a basic PyQt application.<\/p>\n<h3>5.1. Installing PyQt<\/h3>\n<p>PyQt can be easily installed using pip. Use the following command to install it:<\/p>\n<pre>\n<code>pip install PyQt5<\/code>\n        <\/pre>\n<h3>5.2. Basic PyQt Application<\/h3>\n<p>Below is the code for a basic PyQt application.<\/p>\n<pre>\n<code>\nimport sys\nfrom PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout\n\nclass MyApp(QWidget):\n    def __init__(self):\n        super().__init__()\n        self.init_ui()\n\n    def init_ui(self):\n        self.setWindowTitle('Automated Trading System')\n        \n        layout = QVBoxLayout()\n        label = QLabel('Hello! This is an automated trading system.')\n        layout.addWidget(label)\n        \n        self.setLayout(layout)\n        self.show()\n\nif __name__ == '__main__':\n    app = QApplication(sys.argv)\n    ex = MyApp()\n    sys.exit(app.exec_())\n<\/code>\n        <\/pre>\n<h2>6. Implementing an Automated Trading System<\/h2>\n<p>Based on the above content, let&#8217;s implement a real automated trading system. The example will use a simple moving average strategy.<\/p>\n<h3>6.1. Moving Average Strategy<\/h3>\n<p>The moving average strategy calculates the average price over a certain period based on historical price data, and buys when the current price exceeds the average price, and sells when it is below.<\/p>\n<h3>6.2. Example Code<\/h3>\n<pre>\n<code>\nimport numpy as np\nimport pandas as pd\n\n# Fetch historical stock price data (temporary data)\ndef fetch_historical_data(code):\n    # Assume the stock price data is in a pandas DataFrame\n    dates = pd.date_range('2023-01-01', periods=100)\n    prices = np.random.randint(1000, 2000, size=(100,))\n    return pd.DataFrame({'Date': dates, 'Close': prices}).set_index('Date')\n\n# Buy\/Sell strategy\ndef trading_strategy(data, short_window=5, long_window=20):\n    signals = pd.DataFrame(index=data.index)\n    signals['price'] = data['Close']\n    signals['short_mavg'] = data['Close'].rolling(window=short_window, min_periods=1).mean()\n    signals['long_mavg'] = data['Close'].rolling(window=long_window, min_periods=1).mean()\n    \n    signals['signal'] = 0\n    signals['signal'][short_window:] = np.where(signals['short_mavg'][short_window:] > signals['long_mavg'][short_window:], 1, 0)\n    signals['positions'] = signals['signal'].diff()\n    \n    return signals\n\nif __name__ == \"__main__\":\n    stock_code = \"005930\"  # Samsung Electronics code\n    historical_data = fetch_historical_data(stock_code)\n    signals = trading_strategy(historical_data)\n    \n    print(signals.tail())  # Print signals for the last 5 days\n<\/code>\n        <\/pre>\n<h2>7. Conclusion<\/h2>\n<p>This article covered the basics of developing an automated trading system using Python, how to use the Kiwoom Securities API, and how to build a user interface using PyQt. Based on this information, try creating your own automated trading system!<\/p>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stock trading is becoming increasingly automated, with many traders seeking to use algorithms for more efficient trading. This article will cover the basics of developing an automated trading system using the Kiwoom Securities API with Python and introduce how to create a user interface using PyQt. 1. Introduction to Python and the Concept of Automated &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37407\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Automated Trading Development, Kiwoom Securities API, PyQt Basics&#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-37407","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, Kiwoom Securities API, PyQt Basics - \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\/37407\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automated Trading Development, Kiwoom Securities API, PyQt Basics - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Stock trading is becoming increasingly automated, with many traders seeking to use algorithms for more efficient trading. This article will cover the basics of developing an automated trading system using the Kiwoom Securities API with Python and introduce how to create a user interface using PyQt. 1. Introduction to Python and the Concept of Automated &hellip; \ub354 \ubcf4\uae30 &quot;Automated Trading Development, Kiwoom Securities API, PyQt Basics&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37407\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:57:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:50:57+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\/37407\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37407\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Automated Trading Development, Kiwoom Securities API, PyQt Basics\",\"datePublished\":\"2024-11-01T09:57:20+00:00\",\"dateModified\":\"2024-11-01T11:50:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37407\/\"},\"wordCount\":445,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Auto Trading\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37407\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37407\/\",\"name\":\"Automated Trading Development, Kiwoom Securities API, PyQt Basics - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:57:20+00:00\",\"dateModified\":\"2024-11-01T11:50:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37407\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37407\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37407\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automated Trading Development, Kiwoom Securities API, PyQt Basics\"}]},{\"@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, Kiwoom Securities API, PyQt Basics - \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\/37407\/","og_locale":"ko_KR","og_type":"article","og_title":"Automated Trading Development, Kiwoom Securities API, PyQt Basics - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Stock trading is becoming increasingly automated, with many traders seeking to use algorithms for more efficient trading. This article will cover the basics of developing an automated trading system using the Kiwoom Securities API with Python and introduce how to create a user interface using PyQt. 1. Introduction to Python and the Concept of Automated &hellip; \ub354 \ubcf4\uae30 \"Automated Trading Development, Kiwoom Securities API, PyQt Basics\"","og_url":"https:\/\/atmokpo.com\/w\/37407\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:57:20+00:00","article_modified_time":"2024-11-01T11:50:57+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\/37407\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37407\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Automated Trading Development, Kiwoom Securities API, PyQt Basics","datePublished":"2024-11-01T09:57:20+00:00","dateModified":"2024-11-01T11:50:57+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37407\/"},"wordCount":445,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Auto Trading"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37407\/","url":"https:\/\/atmokpo.com\/w\/37407\/","name":"Automated Trading Development, Kiwoom Securities API, PyQt Basics - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:57:20+00:00","dateModified":"2024-11-01T11:50:57+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37407\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37407\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37407\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Automated Trading Development, Kiwoom Securities API, PyQt Basics"}]},{"@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\/37407","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=37407"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37407\/revisions"}],"predecessor-version":[{"id":37408,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37407\/revisions\/37408"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}