3초 간격으로 조회 요청을 반복한 결과 1001번째 조회 요청에서 조회가 차단되었음을 알 수 있다. 총 테스트 소요 시간은 약 50분이다.
또한 0.6초 간격으로 반복해도 1001번째 조회에서 차단된다.
테스트 프로그램의 소스 코드는 아래와 같다. C#이며 .NET Framework 4.8 32bit Console Application으로 작성되었다.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using AxKHOpenAPILib;
namespace KiwoomDelayTester
{
internal static class Program
{
static AxKHOpenAPI api;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
api = new AxKHOpenAPI();
new Control().Controls.Add(api);
Console.WriteLine(api.AccessibilityObject);
api.EndInit();
api.OnEventConnect += Api_OnEventConnect;
api.CommConnect();
Application.Run();
}
private static void Api_OnEventConnect(object sender, _DKHOpenAPIEvents_OnEventConnectEvent e)
{
if (e.nErrCode == 0)
{
Console.WriteLine("Enter the delay in milliseconds:");
int delay = int.Parse(Console.ReadLine());
if(delay < 200) throw new Exception("Delay must be greater than 200ms");
Stopwatch sw = Stopwatch.StartNew();
for(uint count = 0;count < 10000; count++)
{
api.SetInputValue("종목코드", "005930");
int i = api.CommRqData("test", "opt10001", 0, "1000");
if(i != 0)
{
Console.WriteLine("The error code is {0}", i);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
api.Dispose();
Application.Exit();
return;
}
else
{
long elapsed = sw.ElapsedMilliseconds;
Console.WriteLine("elms: {0}, count: {1}, average delay: {2}", elapsed, count, (elapsed+delay)/(count+1));
Thread.Sleep(delay);
}
}
}
}
}
}
'KHOpenAPI' 카테고리의 다른 글
[KHOpenAPI] 장 종료 후 주문 메시지 (0) | 2023.11.03 |
---|---|
[KHOpenAPI] test: 계좌평가현황 연속조회 (1) | 2023.11.03 |
[KHOpenAPI] RQName의 유효성 테스트: opw00013 (1) | 2023.10.09 |
[KHOpenAPI] 화면번호의 유효성 테스트 (0) | 2023.10.09 |
KHOpenAPI: 절대 OPT10085로 평가손익을 구하지 마라 (0) | 2023.09.30 |
댓글