{"id":37361,"date":"2024-11-01T09:56:58","date_gmt":"2024-11-01T09:56:58","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37361"},"modified":"2024-11-01T11:51:08","modified_gmt":"2024-11-01T11:51:08","slug":"automatic-trading-development-with-python-converting-ui-files-utilizing-pyqt-to-python-code","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37361\/","title":{"rendered":"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code"},"content":{"rendered":"<p><body><\/p>\n<p>Python is one of the programming languages widely used in the financial sector. It is particularly utilized in the development of automated trading systems. Today, I will explain in detail how to convert a user interface (UI) file developed using PyQt into Python code. Through this process, you will be able to acquire the basic skills necessary for creating GUI applications.<\/p>\n<h2>1. What is PyQt?<\/h2>\n<p>PyQt is a binding for developing Qt applications in Python. Qt is a cross-platform GUI toolkit that allows you to create applications that can run on various operating systems. PyQt provides a robust framework for desktop application development, making it easier for developers to create graphical user interfaces.<\/p>\n<h3>1.1 Features of PyQt<\/h3>\n<ul>\n<li>Cross-platform: Supports Windows, macOS, and Linux.<\/li>\n<li>Diverse Widgets: Offers a variety of UI widgets for easily constructing complex UIs.<\/li>\n<li>Rapid Development: Enhances development speed through tools that allow you to design UIs and convert them to code.<\/li>\n<\/ul>\n<h2>2. Creating UI Files Using PyQt<\/h2>\n<p>First, let&#8217;s create a simple UI with PyQt. By using a tool called Qt Designer, we can visually construct the UI and then convert the generated UI file into Python code.<\/p>\n<h3>2.1 Installing Qt Designer<\/h3>\n<p>Qt Designer is a UI design tool included in the Qt framework and can be used once installed. After installation is complete, open Qt Designer to create a new UI file.<\/p>\n<h3>2.2 Designing a Simple UI<\/h3>\n<p>Let&#8217;s design a simple UI in Qt Designer with the following components.<\/p>\n<ul>\n<li>QLineEdit: A text box for user input<\/li>\n<li>QPushButton: A button to execute automated trading<\/li>\n<li>QTextEdit: A text area for log output<\/li>\n<\/ul>\n<p>After designing this UI, save it with the name <strong>example.ui<\/strong>.<\/p>\n<h3>2.3 Converting UI Files to Python Code<\/h3>\n<p>To convert the saved UI file into Python code, use the command <code>pyuic5<\/code>. This command is a tool provided by PyQt that converts .ui files to .py files. Execute the following command in the terminal:<\/p>\n<pre><code>pyuic5 -x example.ui -o example.py<\/code><\/pre>\n<p>When you run this command, a Python file named <strong>example.py<\/strong> will be created. This file contains code based on the UI designed in Qt Designer.<\/p>\n<h2>3. Utilizing the Generated Python Code<\/h2>\n<p>Now we will use the converted Python file to create a real GUI application. Below is a simple example code for the <strong>example.py<\/strong> file:<\/p>\n<pre><code>import sys\nfrom PyQt5.QtWidgets import QApplication, QMainWindow\nfrom example import Ui_MainWindow  # Importing the automatically generated UI code\n\nclass MainWindow(QMainWindow, Ui_MainWindow):\n    def __init__(self):\n        super().__init__()\n        self.setupUi(self)  # UI initialization\n\n        # Connecting button click event\n        self.pushButton.clicked.connect(self.start_trading)\n\n    def start_trading(self):\n        input_text = self.lineEdit.text()\n        self.textEdit.append(f'Automated trading started: {input_text}')  # Adding to log\n\nif __name__ == '__main__':\n    app = QApplication(sys.argv)\n    window = MainWindow()\n    window.show()\n    sys.exit(app.exec_())<\/code><\/pre>\n<h3>3.1 Code Explanation<\/h3>\n<p>This code has a very simple structure. It inherits from <code>QMainWindow<\/code> to set up the UI and calls the <code>start_trading<\/code> method upon button click. Here, it reads the value entered by the user in the <code>QLineEdit<\/code> and outputs the corresponding content in <code>QTextEdit<\/code>.<\/p>\n<h2>4. Integrating Automated Trading Logic<\/h2>\n<p>Now that the basic UI is ready, let\u2019s integrate the actual automated trading logic. The example below adds a simple stock trading logic which generates random virtual trading results.<\/p>\n<pre><code>import random\n\nclass MainWindow(QMainWindow, Ui_MainWindow):\n    def __init__(self):\n        super().__init__()\n        self.setupUi(self)\n        self.pushButton.clicked.connect(self.start_trading)\n\n    def start_trading(self):\n        input_text = self.lineEdit.text()\n        self.textEdit.append(f'Automated trading started: {input_text}')\n        result = self.simulate_trading(input_text)\n        self.textEdit.append(result)\n\n    def simulate_trading(self, stock):\n        # Randomly generating virtual trading results\n        if random.choice([True, False]):\n            return f'{stock} Purchase successful!'\n        else:\n            return f'{stock} Sale successful!'<\/code><\/pre>\n<p>The above code randomly outputs a purchase or sale successful message for the stock entered by the user. To actually trade stocks through an API, you can utilize the trading platform\u2019s API.<\/p>\n<h2>5. API Integration and Practical Application<\/h2>\n<p>To build a real automated trading system, it is necessary to integrate a stock trading API. For instance, leading online brokerages in Korea provide OpenAPI to allow users to automate stock trading.<\/p>\n<h3>5.1 Using APIs<\/h3>\n<p>Many exchanges provide APIs that allow for real-time data collection and trade orders. Later, you can create a more complex journey by integrating this UI with APIs.<\/p>\n<h4>Example: Trading API Integration<\/h4>\n<pre><code>import requests\n\ndef execute_trade(stock, action):\n    url = 'https:\/\/api.broker.com\/trade'  # Example URL\n    data = {\n        'stock': stock,\n        'action': action\n    }\n    response = requests.post(url, json=data)\n    return response.json()\n<\/code><\/pre>\n<p>The above <code>execute_trade<\/code> function is an example of sending a POST request for stock trading. The actual API may require authentication information and additional parameters.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this lecture, we explored how to design a GUI using PyQt and convert it into Python code, and we briefly implemented automated trading logic. I hope this process has provided you with foundational experience in creating GUI applications. Finally, I also introduced how to implement actual trading using APIs. Building on this, I hope you can further develop your automated trading system.<\/p>\n<h2>References<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.riverbankcomputing.com\/software\/pyqt\/intro\">Official PyQt Documentation<\/a><\/li>\n<li><a href=\"https:\/\/www.qt.io\/\">Official Qt Website<\/a><\/li>\n<li><a href=\"https:\/\/www.codecademy.com\/\">Codecademy \u2014 Python Course<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python is one of the programming languages widely used in the financial sector. It is particularly utilized in the development of automated trading systems. Today, I will explain in detail how to convert a user interface (UI) file developed using PyQt into Python code. Through this process, you will be able to acquire the basic &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37361\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code&#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-37361","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>Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code - \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\/37361\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Python is one of the programming languages widely used in the financial sector. It is particularly utilized in the development of automated trading systems. Today, I will explain in detail how to convert a user interface (UI) file developed using PyQt into Python code. Through this process, you will be able to acquire the basic &hellip; \ub354 \ubcf4\uae30 &quot;Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37361\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:56:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:51:08+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\/37361\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37361\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code\",\"datePublished\":\"2024-11-01T09:56:58+00:00\",\"dateModified\":\"2024-11-01T11:51:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37361\/\"},\"wordCount\":657,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Auto Trading\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37361\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37361\/\",\"name\":\"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:56:58+00:00\",\"dateModified\":\"2024-11-01T11:51:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37361\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37361\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37361\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code\"}]},{\"@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":"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code - \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\/37361\/","og_locale":"ko_KR","og_type":"article","og_title":"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Python is one of the programming languages widely used in the financial sector. It is particularly utilized in the development of automated trading systems. Today, I will explain in detail how to convert a user interface (UI) file developed using PyQt into Python code. Through this process, you will be able to acquire the basic &hellip; \ub354 \ubcf4\uae30 \"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code\"","og_url":"https:\/\/atmokpo.com\/w\/37361\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:56:58+00:00","article_modified_time":"2024-11-01T11:51:08+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\/37361\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37361\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code","datePublished":"2024-11-01T09:56:58+00:00","dateModified":"2024-11-01T11:51:08+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37361\/"},"wordCount":657,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Auto Trading"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37361\/","url":"https:\/\/atmokpo.com\/w\/37361\/","name":"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:56:58+00:00","dateModified":"2024-11-01T11:51:08+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37361\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37361\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37361\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Automatic Trading Development with Python, Converting UI Files Utilizing PyQt to Python Code"}]},{"@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\/37361","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=37361"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37361\/revisions"}],"predecessor-version":[{"id":37362,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37361\/revisions\/37362"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}