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

Record of Trial and Error in Developing the Korea Investment & Securities API

Created: 2024-04-23

Created: 2024-04-23 00:03

I've reached a point where I've almost finished developing the Korea Investment & Securities API. It's turning into a real series, isn't it? Going through this difficult process, I find myself feeling a sense of self-deprecation and sadness, even though no one has said anything. Those who are skilled probably create this kind of thing in one go without going through such a series of steps. I'm envious of their sharp minds and talents. Nevertheless, I remind myself that life isn't made up solely of those who are skilled, and I try to comfort myself.


This is the 5th post. However, it doesn't contain much. It's a cynical take on the process of creating an automated trading program using the Korea Investment & Securities API. Still, if you're reading this, I'm truly grateful. +_+

Record of Trial and Error in Developing the Korea Investment & Securities API

When facing challenges, the solution lies in persistently trying out prepared approaches. try except


Previously, I wrote about the difficulties I encountered while developing the Korea Investment & Securities API. Some of the challenges weren't necessarily due to Korea Investment & Securities, but they were still hurdles. Summarizing those difficulties again, they are as follows:


  • Opening a Korea Investment & Securities account (ISA account transfer failure case)
  • Lack of mock trading support
  • Websockets - Real-time data reception
  • Trading methodology

I resolved the account opening issue by visiting a nearby branch. Fortunately, there was a branch about 40 minutes away. If you're not in the metropolitan area, or a major city, and are in a place with good water and air, I sincerely hope that non-face-to-face account opening becomes a possibility. In any case, you need to open an account to try developing using the API, so please open one according to your situation.

The lack of mock trading support isn't actually a critical issue. It's just a little unsettling. What if a purchase leads to margin debt? What if I keep generating real trading tokens and my account gets blocked? These are the kinds of anxieties I experience. However, for those who are skilled developers, this wouldn't be a major concern. It's due to my insufficient skills and lack of experience with stock programming. Similarly, the Websockets issue arose because my programming skills weren't up to par, so I couldn't get it to work as intended. It's all my fault. ㅠ_ㅠ

Websocket was the problem. My lack of skill caused the Websocket issue!! But it was genuinely difficult to grasp how to solve it using the provided example. In this situation, I considered "a few options for my next steps."


  • Learn Websockets and crush this problem!!
  • Find out how others have solved this problem!!


The easy way is to search. Naturally, I chose option 2. I searched the Korea Investment & Securities KIS Developer site using a few keywords, but I couldn't find a good answer. (Almost all of them were secret questions. Oh, come on...) Next up was ChatGPT. But I wasn't sure what to ask. "I'm developing the Korea Investment & Securities API and using Websockets to receive data in real-time. Here's the source code I'm currently using. However, I want to add and delete execution prices, order book information, and execution details in real-time. How can I do that?"


Record of Trial and Error in Developing the Korea Investment & Securities API

Without ChatGPT, I'm practically useless...


Record of Trial and Error in Developing the Korea Investment & Securities API

The provided example code is excellent... but the results from the examples seem to be the same..


As a final resort, I searched GitHub repositories.

Record of Trial and Error in Developing the Korea Investment & Securities API

Github is amazing. I'm truly grateful for the many individuals sharing their knowledge with the world.


When I searched for "koreainvestment," many repositories appeared. The first one was Korea Investment & Securities' official GitHub, so I skipped it. The second one was Jocoding's repository, which you can naturally skip if you've watched the 20-minute YouTube video mentioned earlier. The third one caught my eye: Soju06's python-kis!! (I don't know if they like Soju, or if their name is Soju, but I want to express my gratitude once again in this space. ❤️) Exploring this repository, I found that while domestic stock-related work was done, it seemed that overseas stocks weren't. I almost skipped it, but I saw a clue that could solve the Websockets problem. No, no. Upon testing it for domestic stocks, I found that it was working with the Websockets problem already solved. +_+ I decided I could just adapt this to make it work for overseas stocks too. I tried to look at the source code, but my Python skills were insufficient to understand what Soju06 had done. However, I discovered that they used websocket and websocket-client instead of Websockets, and I was able to resolve the issue by just using that part. Deep understanding would be amazing, but I realized that not knowing it deeply doesn't mean you can't create something. (That's why life is beautiful~ 🎶)

The only remaining challenge from the list of difficulties I presented earlier is the trading methodology. Trading methodology is still difficult. And if there was a definitive answer, the person who knew it would have all the wealth in the world. But that doesn't mean I view trading methodology pessimistically. To automate stock trading, you need buy/sell criteria. That criteria is the trading methodology. There's no right answer, but it's something logically necessary for trading methodology. My words are becoming increasingly strange, but anyway, the point is that understanding trading methodology is still difficult. However, simply thinking about why the person who requested this wants to use these specific criteria has given me valuable experience, which is great.

I've gone through these trials and errors, and I'll likely continue to do so, but I hope this has been helpful to anyone facing similar challenges. Or, if you know of a better way, please enlighten this foolish being with your wisdom. I'd be truly grateful. I welcome any form of help – comments, emails, or Open Chat.



Additionally, I accept requests for creating stock automated trading programs. To implement your own unique trading strategy that you've been contemplating, you need to implement the logic, and the process of learning programming to do so is quite challenging. That's why people often choose to cover it with money. But even if you want to pay, finding someone who can build it exactly as you envision is difficult. While I'm not claiming to be that person, if you feel that I have some potential in that regard, please don't hesitate to contact me. The cost will be determined when we've sufficiently discussed the trading methodology and decide to proceed with the actual development. One of the great ways to refine your trading strategy in your mind is to explain it to someone else. This helps you make it more concrete. I'm happy to help with that. I'll benefit from it too. ❤️



Comments0