This is an AI translated post.
Korea Investment & Securities API Development Reference
- Writing language: Korean
- •
- Base country: All countries
- •
- Information Technology
Select Language
Summarized by durumis AI
- This document summarizes the process of collecting information needed to develop the Korea Investment & Securities API.
- Information was obtained through various materials such as the official website, KIS Developer Center, github, and Wikidocs, and the github repository was particularly helpful.
- I had difficulties in handling real-time data, but I was able to solve the problem by referring to the source code shared by other developers on github.
Previously, we explored why we are trying to create an automated trading program using the Korea Investment & Securities API and what benefits it offers.
This time, I would like to share the process of collecting the information required for developing the Korea Investment & Securities API. There are already many experienced users who have shared the Korea Investment & Securities API, making it easy to find information. However, I would like to briefly comment on what I was able to learn and hope this information is helpful to you. (It's best to start with the github repository!!)
Official Website
Korea Investment & Securities Official Website
Basic information can be obtained through the official website. Through the Korea Investment & Securities official website, you can perform tasks such as ID and account settings, mock trading applications, and overseas trading applications. Also, the official website provides easy links to sites for development.
Among the menus of Korea Investment & Securities, development-related contents are in the Trading menu.
KIS Developer Developer Center
The KIS Developer site is a site that you need to keep an eye on while developing the API. You can check the detailed contents of the API document.
This is the API for issuing the most basic access token.
This is a detailed description of the request and response values of the API. Refer to these values to call and receive responses for processing.
github - koreainvestment/open-trading-api
This is the Open Trading API github repository. The README.md file provides a friendly step-by-step guide. Therefore, as mentioned above, it would be good to start with github.
This is a github repository.
Wikidocs
Finally, here is a Wikidocs that you can refer to when developing python. Since the author is Korea Investment & Securities, most of the content is reliable. The reason I say "most" is that there is no additional content added over time, and personally, I got stuck in the real-time data section while following it and couldn't find a solution.
The development guide is well documented on Wikidocs.
Additional References
If you refer to the contents up to this point and make it quickly, it would be great, but I don't have the skills to do that, so I had a lot of difficulties. So, I searched for many things and will list the additional references that I received help from. Since this is what I found, you will be able to find it easily as well.
Jocoding's YouTube video (23:41 seconds)
Through this video, I was able to understand the advantages of the Korea Investment & Securities API from a user perspective. And as expected, it was easier to understand because the working source code was explained in the video. If you have a general understanding of what's available through the official website, I recommend watching Jocoding's video (23:41 seconds) quickly.
Websockets
As mentioned briefly earlier, I got stuck in the real-time data handling part, but Wikidocs used python's websockets. However, I didn't understand what websocket was. In such cases, you need to ask. +_+
ChatGPT Help
It seems like it would be a big deal if ChatGPT disappeared.
It seems like a method for communication and once connected, you can receive data continuously. After looking at this, my understanding is that REST API is a one-time request and one-time response, while Websocket registers a request once and then receives responses continuously related to it. To create an automated trading program, both of these need to be implemented well and combined.
However, I got stuck with the example in Wikidocs. It was good that I was able to request using websocket, but then it immediately became while True: and stayed in that state. There must be a way, but for someone like me who's a beginner, it's not easy to grasp how to solve it since I'm not familiar with the concept. So, I searched github to see if there was any source code implemented differently.
Github Repository
- python-kis - Soju06/python-kis: 📈 파이썬 한국투자증권 REST 기반 Trading API 라이브러리 (github.com)
- pykis - pjueon/pykis: 한국투자증권 신규 Open Trade API 를 쉽게 사용하기 위한 python 패키지 (github.com)
- mojito - sharebook-kr/mojito: python wrapper for the KIS (github.com)
I realized once again that there are so many experienced users. I checked three repositories, but the one I used this time was the first one, python-kis. I took the logic and referred to the websocket part. As a result, I used the websocket and websocket-client libraries, not the websockets library. I would like to take this opportunity to thank Soju06 and all the others who share great source code on github.
Now I can develop with reference to this information. I did have some trial and error, but I will separately organize and share information about it. Next, I would like to list what I have thought about regarding the "structure of automated stock trading", which might be a bit fundamental. Based on this, I hope to reduce trial and error in the future and easily reuse the parts that have already been developed.