(로또 사는 아빠) 살림 하는 엄마

Korea Investment & Securities API Development Reference

Created: 2024-04-22

Created: 2024-04-22 23:53

Previously, we explored why we want to create an automated trading program using the Korea Investment Securities API and what advantages it offers.

This time, I'd like to share the process of gathering the necessary information for developing the Korea Investment Securities API. Since many experienced individuals have already shared the Korea Investment Securities API, finding information wasn't difficult. Nevertheless, I want to briefly comment on what I learned and hope this content will be helpful. (It's a good idea to start with the GitHub repository!!)


Official Website

Korea Investment Securities Official Website

You can obtain basic information through the official website. Through the Korea Investment Securities official website, you can perform tasks such as setting up your ID and account, applying for a mock trading account, and applying for overseas trading. Also, the official website provides easy links to the development-related websites.

Korea Investment & Securities API Development Reference

Among the menus of Korea Investment & Securities, the contents for development are in the Trading menu.



KIS Developer Developer Center

The KIS Developer website is a site you'll need to refer to continuously during API development. You can check the detailed contents of the API documentation.

Korea Investment & Securities API Development Reference

This is the API for issuing the most basic access token.


Korea Investment & Securities API Development Reference

Detailed information on 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 helpful step-by-step guide. That's why I mentioned earlier that it's a good idea to start with GitHub.

Korea Investment & Securities API Development Reference

This is the GitHub repository.



Wikidocs

Finally, here's Wikidocs, which you can refer to for Python development. Since the author is from Korea Investment Securities, most of the content is reliable. The reason I say 'most' is that there haven't been any updates to the content over time, and personally, I encountered difficulties following the real-time data section and couldn't find a solution.

Korea Investment & Securities API Development Reference

The development guide is well documented on Wikidocs.



Additional References

If we refer to the information provided so far, it would be great to create something with it, but due to my lack of skills, I encountered quite a few obstacles. So, I searched for various resources and received help from them. I'll list the additional references that helped me. Since it's what I found, you should be able to find them easily too.

Jocoding's YouTube Video (23:41)

Through this video, I could understand the advantages of the Korea Investment Securities API from a user's perspective. And, as always, it was easier to understand when 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 quickly watching Jocoding's video (23:41).


WebSockets

As mentioned briefly before, I encountered difficulties handling real-time data, and Wikidocs used Python's websockets. However, I didn't fully understand what websockets were. In such cases, you have to ask for help. +_+


ChatGPT, Help Me.

Korea Investment & Securities API Development Reference

I think the world would be in trouble if ChatGPT disappeared.


It seems like it's a method for communication, and once connected, you can receive data continuously. From what I've seen so far, REST API sends one request and receives one response, while WebSocket registers one request and receives continuous responses related to it. For automated trading programming, both of these need to be implemented and combined effectively.


However, I encountered an issue with the Wikidocs example. I successfully sent a request using WebSocket, but it immediately entered a while True: loop and stayed in that state. There must be a way to handle it, but as a beginner, I wasn't familiar with the concept and found it difficult to grasp how to solve it. So, I searched GitHub to see if there were any alternative implementations.


GitHub Repositories

  • python-kis - Soju06/python-kis: 📈 Python Korea Investment Securities REST-based Trading API Library (github.com)
  • pykis - pjueon/pykis: Python package for easy use of the new Korea Investment Securities Open Trade API (github.com)
  • mojito - sharebook-kr/mojito: Python wrapper for the KIS (github.com)

I was reminded once again of the abundance of skilled developers. I checked three repositories, but the one I used this time was the first one, python-kis. I used the logic from this repository as a reference for the WebSocket part. Ultimately, I used the websocket and websocket-client libraries instead of the websockets library. I would like to express my sincere gratitude to Soju06 and all the other developers who share their valuable source code on GitHub.

Now, I can proceed with development using this information. Although I encountered some minor setbacks, I will share those details separately. Next, I plan to discuss the "Structure of Automated Stock Trading," which could be considered a more fundamental aspect. Based on this, I hope to reduce future setbacks and easily reuse already developed parts in the future.

Comments0