KOAPY Tutorial¶
키움증권 OpenAPI+ 사용 예시¶
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import logging
logging.basicConfig(
format='%(asctime)s [%(levelname)s] %(message)s - %(filename)s:%(lineno)d',
level=logging.DEBUG)
logging.getLogger('matplotlib').setLevel(logging.WARNING)
1. 엔트리포인트 객체 생성¶
from koapy import KiwoomOpenApiPlusEntrypoint
entrypoint = KiwoomOpenApiPlusEntrypoint()
2022-01-18 14:22:15,134 [DEBUG] Testing if client is ready... - KiwoomOpenApiPlusEntrypoint.py:45 2022-01-18 14:22:25,146 [DEBUG] Client is not ready - KiwoomOpenApiPlusEntrypoint.py:47 2022-01-18 14:22:25,146 [DEBUG] Creating a new server... - KiwoomOpenApiPlusEntrypoint.py:48
주요한 기능들은 해당 엔트리포인트의 멤버함수로써 제공된다.
예를 들어 아래와 같이 서버 접속 이전에도 실행 가능한 아래 함수를 활용하면 OpenAPI 가 정상적으로 로드되었는지 간접적으로 확인 가능하다.
module_path = entrypoint.GetAPIModulePath()
module_path
'C:\\OpenAPI'
2. 서버 접속¶
entrypoint.EnsureConnected()
True
자동 로그인 설정이 되어있는 경우 로그인이 자동으로 처리되며, 그렇지 않은 경우에는 수동으로 아이디, 비밀번호 등 로그인 정보를 입력해 처리해주어야 한다.
credentials = {
'user_id': 'id',
'user_password': 'password',
'cert_password': 'password',
'is_simulation': True,
'account_passwords': {
'0000000000': '0000',
}
}
entrypoint.EnsureConnected(credentials)
True
참고로 여기서는 이미 로그인이 되어있는 상황이므로 위의 함수가 추가적인 로그인처리를 진행하지는 않게 된다.
3. 기본 함수 실행¶
다시 한번 기본 함수를 통해 접속상태를 확인해보자. 아래 값이 1 인 경우 정상 접속 상태이다. 접속되어 있지 않은 경우라면 0 을 반환한다.
entrypoint.GetConnectState()
1
이후 예시들에서 사용하기 위해 삼성전자의 코드를 확인한다.
codes = entrypoint.GetCodeListByMarketAsList('0')
names = [entrypoint.GetMasterCodeName(code) for code in codes]
codes_by_name = dict(zip(names, codes))
위에서 GetCodeListByMarketAsList()
함수는 기존의 GetCodeListByMarket()
함수 호출시 나오는 문자열 형태의 결과를 편의를 위해 리스트 형태로 변환해서 제공한다.
code = samsung_code = codes_by_name['삼성전자']
code
'005930'
4. TR 요청 예시¶
상위 함수 사용 예시¶
몇가지 자주 쓰이는 TR 들에 대해서는 요청 및 결과 이벤트 처리까지 완료해서 결과물만 반환하는 상위함수를 제공하고 있다.
info = entrypoint.GetStockBasicInfoAsDict(code) # opt10001
info
{'종목코드': '005930', '종목명': '삼성전자', '결산월': '12', '액면가': '100', '자본금': '7780', '상장주식': '5969783', '신용비율': '+0.13', '연중최고': '+79800', '연중최저': '-76400', '시가총액': '4596733', '시가총액비중': '', '외인소진률': '+52.23', '대용가': '60450', 'PER': '20.05', 'EPS': '3841', 'ROE': '10.0', 'PBR': '1.95', 'EV': '5.36', 'BPS': '39406', '매출액': '2368070', '영업이익': '359939', '당기순이익': '264078', '250최고': '+91800', '250최저': '-68300', '시가': '+77600', '고가': '+77800', '저가': '-76600', '상한가': '+100500', '하한가': '-54300', '기준가': '77500', '예상체결가': '-0', '예상체결수량': '0', '250최고가일': '20210115', '250최고가대비율': '-16.12', '250최저가일': '20211013', '250최저가대비율': '+12.74', '현재가': '-77000', '대비기호': '5', '전일대비': '-500', '등락율': '-0.65', '거래량': '7715780', '거래대비': '-87.83', '액면가단위': '원', '유통주식': '4456888', '유통비율': '74.7'}
data = entrypoint.GetDailyStockDataAsDataFrame(code) # opt10081
2022-01-18 14:22:38,267 [DEBUG] Received 600 records from 2022-01-18 00:00:00 to 2019-08-16 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:38,572 [DEBUG] Received 600 records from 2019-08-14 00:00:00 to 2017-03-03 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:38,880 [DEBUG] Received 600 records from 2017-03-02 00:00:00 to 2014-09-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:39,197 [DEBUG] Received 600 records from 2014-09-25 00:00:00 to 2012-04-20 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:56,202 [DEBUG] Received 600 records from 2012-04-19 00:00:00 to 2009-11-24 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:56,502 [DEBUG] Received 600 records from 2009-11-23 00:00:00 to 2007-06-27 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:56,797 [DEBUG] Received 600 records from 2007-06-26 00:00:00 to 2005-01-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:57,109 [DEBUG] Received 600 records from 2005-01-25 00:00:00 to 2002-08-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:22:57,409 [DEBUG] Received 600 records from 2002-08-23 00:00:00 to 2000-03-08 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:14,210 [DEBUG] Received 600 records from 2000-03-07 00:00:00 to 1997-12-09 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:14,499 [DEBUG] Received 600 records from 1997-12-08 00:00:00 to 1995-11-22 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:14,780 [DEBUG] Received 600 records from 1995-11-21 00:00:00 to 1993-11-10 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:15,089 [DEBUG] Received 600 records from 1993-11-09 00:00:00 to 1991-10-28 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:15,396 [DEBUG] Received 600 records from 1991-10-26 00:00:00 to 1989-10-06 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:32,236 [DEBUG] Received 600 records from 1989-10-05 00:00:00 to 1987-09-09 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:32,523 [DEBUG] Received 600 records from 1987-09-08 00:00:00 to 1985-08-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:32,641 [DEBUG] Received 192 records from 1985-08-24 00:00:00 to 1985-01-04 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573
data
종목코드 | 현재가 | 거래량 | 거래대금 | 일자 | 시가 | 고가 | 저가 | 수정주가구분 | 수정비율 | 대업종구분 | 소업종구분 | 종목정보 | 수정주가이벤트 | 전일종가 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 005930 | 77000 | 7715780 | 595861 | 20220118 | 77600 | 77800 | 76600 | |||||||
1 | 77500 | 8785122 | 678903 | 20220117 | 77600 | 77800 | 76900 | ||||||||
2 | 77300 | 10096725 | 781575 | 20220114 | 77700 | 78100 | 77100 | ||||||||
3 | 77900 | 13889401 | 1088598 | 20220113 | 79300 | 79300 | 77900 | ||||||||
4 | 78900 | 11000502 | 868911 | 20220112 | 79500 | 79600 | 78600 | ||||||||
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
9787 | 8010 | 4970 | 1 | 19850109 | 8240 | 8240 | 7950 | ||||||||
9788 | 8300 | 12930 | 4 | 19850108 | 8400 | 8400 | 8300 | ||||||||
9789 | 8410 | 11810 | 3 | 19850107 | 8400 | 8500 | 8390 | ||||||||
9790 | 8390 | 1660 | 0 | 19850105 | 8400 | 8440 | 8390 | ||||||||
9791 | 8450 | 1710 | 0 | 19850104 | 8500 | 8500 | 8450 |
9792 rows × 15 columns
데이터가 최대한 있는 그대로 (주로 문자열 형태로) 반환되기 때문에 필요하다면 타입 변환을 거쳐 사용한다.
dates = pd.to_datetime(data['일자'], format='%Y%m%d')
closes = pd.to_numeric(data['현재가'])
plt.plot(dates, closes)
[<matplotlib.lines.Line2D at 0x1c66e74e040>]
주가 데이터에서 수정주가가 필요한 경우에는 adjusted_price=True
파라미터를 설정해 호출한다.
data_adjusted = entrypoint.GetDailyStockDataAsDataFrame(code, adjusted_price=True)
2022-01-18 14:23:33,209 [DEBUG] Received 600 records from 2022-01-18 00:00:00 to 2019-08-16 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:33,499 [DEBUG] Received 600 records from 2019-08-14 00:00:00 to 2017-03-03 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:50,269 [DEBUG] Received 600 records from 2017-03-02 00:00:00 to 2014-09-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:50,553 [DEBUG] Received 600 records from 2014-09-25 00:00:00 to 2012-04-20 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:50,856 [DEBUG] Received 600 records from 2012-04-19 00:00:00 to 2009-11-24 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:51,210 [DEBUG] Received 600 records from 2009-11-23 00:00:00 to 2007-06-27 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:23:51,505 [DEBUG] Received 600 records from 2007-06-26 00:00:00 to 2005-01-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:08,257 [DEBUG] Received 600 records from 2005-01-25 00:00:00 to 2002-08-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:08,558 [DEBUG] Received 600 records from 2002-08-23 00:00:00 to 2000-03-08 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:08,848 [DEBUG] Received 600 records from 2000-03-07 00:00:00 to 1997-12-09 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:09,238 [DEBUG] Received 600 records from 1997-12-08 00:00:00 to 1995-11-22 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:09,534 [DEBUG] Received 600 records from 1995-11-21 00:00:00 to 1993-11-10 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:26,266 [DEBUG] Received 600 records from 1993-11-09 00:00:00 to 1991-10-28 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:26,564 [DEBUG] Received 600 records from 1991-10-26 00:00:00 to 1989-10-06 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:26,885 [DEBUG] Received 600 records from 1989-10-05 00:00:00 to 1987-09-09 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:27,240 [DEBUG] Received 600 records from 1987-09-08 00:00:00 to 1985-08-26 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573 2022-01-18 14:24:27,345 [DEBUG] Received 192 records from 1985-08-24 00:00:00 to 1985-01-04 00:00:00 for code 005930 - KiwoomOpenApiPlusServiceClientStubWrapper.py:573
dates = pd.to_datetime(data_adjusted['일자'], format='%Y%m%d')
closes = pd.to_numeric(data_adjusted['현재가'])
plt.plot(dates, closes)
[<matplotlib.lines.Line2D at 0x1c66d09af70>]
하위 함수 사용 예시¶
만약에 필요한 TR 에 대한 편의함수가 제공되지 않는 경우라면 아래처럼 직접 TR 요청에 필요한 입력값을 설정해 요청하고, 이후 스트림 형태로 들어오는 이벤트 또한 직접 처리해주는 방식으로 사용할 수 있다.
rqname = '주식기본정보요청'
trcode = 'opt10001'
screen_no = '0001' # 화면번호, 0000 을 제외한 4자리 숫자 임의로 지정, None 의 경우 내부적으로 화면번호 자동할당
inputs = {'종목코드': code}
output = {}
logging.info('Requesting data for request name: %s', rqname)
for event in entrypoint.TransactionCall(rqname, trcode, screen_no, inputs):
logging.info('Got event for request: %s', rqname)
names = event.single_data.names
values = event.single_data.values
for name, value in zip(names, values):
output[name] = value
2022-01-18 14:24:27,606 [INFO] Requesting data for request name: 주식기본정보요청 - <ipython-input-30-84e17a5232d0>:1 2022-01-18 14:24:44,007 [INFO] Got event for request: 주식기본정보요청 - <ipython-input-30-84e17a5232d0>:3
output
{'종목코드': '005930', '종목명': '삼성전자', '결산월': '12', '액면가': '100', '자본금': '7780', '상장주식': '5969783', '신용비율': '+0.13', '연중최고': '+79800', '연중최저': '-76400', '시가총액': '4596733', '시가총액비중': '', '외인소진률': '+52.23', '대용가': '60450', 'PER': '20.05', 'EPS': '3841', 'ROE': '10.0', 'PBR': '1.95', 'EV': '5.36', 'BPS': '39406', '매출액': '2368070', '영업이익': '359939', '당기순이익': '264078', '250최고': '+91800', '250최저': '-68300', '시가': '+77600', '고가': '+77800', '저가': '-76600', '상한가': '+100500', '하한가': '-54300', '기준가': '77500', '예상체결가': '-0', '예상체결수량': '0', '250최고가일': '20210115', '250최고가대비율': '-16.12', '250최저가일': '20211013', '250최저가대비율': '+12.74', '현재가': '-77000', '대비기호': '5', '전일대비': '-500', '등락율': '-0.65', '거래량': '7726846', '거래대비': '-87.95', '액면가단위': '원', '유통주식': '4456888', '유통비율': '74.7'}
위의 코드에서 TransactionCall()
함수의 경우 반환되는 스트림의 event
객체는 ListenResponse
타입의 gRPC 메시지 형태로 반환된다.
from pprint import PrettyPrinter
from google.protobuf.json_format import MessageToDict
pp = PrettyPrinter()
def pprint_event(event):
pp.pprint(MessageToDict(event, preserving_proto_field_name=True))
pprint_event(event)
{'arguments': [{'string_value': '0001'}, {'string_value': '주식기본정보요청'}, {'string_value': 'opt10001'}, {'string_value': ''}, {'string_value': '0'}], 'name': 'OnReceiveTrData', 'single_data': {'names': ['종목코드', '종목명', '결산월', '액면가', '자본금', '상장주식', '신용비율', '연중최고', '연중최저', '시가총액', '시가총액비중', '외인소진률', '대용가', 'PER', 'EPS', 'ROE', 'PBR', 'EV', 'BPS', '매출액', '영업이익', '당기순이익', '250최고', '250최저', '시가', '고가', '저가', '상한가', '하한가', '기준가', '예상체결가', '예상체결수량', '250최고가일', '250최고가대비율', '250최저가일', '250최저가대비율', '현재가', '대비기호', '전일대비', '등락율', '거래량', '거래대비', '액면가단위', '유통주식', '유통비율'], 'values': ['005930', '삼성전자', '12', '100', '7780', '5969783', '+0.13', '+79800', '-76400', '4596733', '', '+52.23', '60450', '20.05', '3841', '10.0', '1.95', '5.36', '39406', '2368070', '359939', '264078', '+91800', '-68300', '+77600', '+77800', '-76600', '+100500', '-54300', '77500', '-0', '0', '20210115', '-16.12', '20211013', '+12.74', '-77000', '5', '-500', '-0.65', '7726846', '-87.95', '원', '4456888', '74.7']}}
해당 메시지의 형태는 koapy/backend/kiwoom_open_api_plus/grpc/KiwoomOpenApiPlusService.proto
파일의 내용, 구체적으로 아래와 같은 메시지의 정의 부분을 참고하기 바란다.
message ListenResponse {
string name = 1;
repeated Argument arguments = 2;
SingleData single_data = 3;
MultiData multi_data = 4;
}
각 TR 에 따라 싱글데이터/멀티데이터가 선택적으로 설정되어 반환되는데, 그러한 입력/출력과 관련된 정보들은 KOAStudio 프로그램을 활용하거나 아니면 아래처럼 KiwoomOpenApiPlusTrInfo
를 통해 프로그램 내에서 확인할 수 있다.
from koapy import KiwoomOpenApiPlusTrInfo
tr_info = KiwoomOpenApiPlusTrInfo.get_trinfo_by_code('opt10001')
tr_info.inputs
[KiwoomOpenApiPlusTrInfo.Field('종목코드', 0, 6, 9001)]
tr_info.single_outputs
[KiwoomOpenApiPlusTrInfo.Field('종목코드', 0, 20, 389), KiwoomOpenApiPlusTrInfo.Field('종목명', 20, 50, 302), KiwoomOpenApiPlusTrInfo.Field('결산월', 40, 20, 315), KiwoomOpenApiPlusTrInfo.Field('액면가', 60, 20, 310), KiwoomOpenApiPlusTrInfo.Field('자본금', 80, 20, 309), KiwoomOpenApiPlusTrInfo.Field('상장주식', 100, 20, 312), KiwoomOpenApiPlusTrInfo.Field('신용비율', 120, 20, 329), KiwoomOpenApiPlusTrInfo.Field('연중최고', 140, 20, 1006), KiwoomOpenApiPlusTrInfo.Field('연중최저', 160, 20, 1009), KiwoomOpenApiPlusTrInfo.Field('시가총액', 180, 20, 311), KiwoomOpenApiPlusTrInfo.Field('시가총액비중', 200, 20, 336), KiwoomOpenApiPlusTrInfo.Field('외인소진률', 220, 20, 314), KiwoomOpenApiPlusTrInfo.Field('대용가', 240, 20, 308), KiwoomOpenApiPlusTrInfo.Field('PER', 260, 20, 1600), KiwoomOpenApiPlusTrInfo.Field('EPS', 280, 20, 1604), KiwoomOpenApiPlusTrInfo.Field('ROE', 300, 20, 1630), KiwoomOpenApiPlusTrInfo.Field('PBR', 320, 20, 1601), KiwoomOpenApiPlusTrInfo.Field('EV', 340, 20, 1608), KiwoomOpenApiPlusTrInfo.Field('BPS', 360, 20, 1605), KiwoomOpenApiPlusTrInfo.Field('매출액', 380, 20, 1610), KiwoomOpenApiPlusTrInfo.Field('영업이익', 400, 20, 1611), KiwoomOpenApiPlusTrInfo.Field('당기순이익', 420, 20, 1614), KiwoomOpenApiPlusTrInfo.Field('250최고', 440, 20, 1000), KiwoomOpenApiPlusTrInfo.Field('250최저', 460, 20, 1003), KiwoomOpenApiPlusTrInfo.Field('시가', 480, 20, 16), KiwoomOpenApiPlusTrInfo.Field('고가', 500, 20, 17), KiwoomOpenApiPlusTrInfo.Field('저가', 520, 20, 18), KiwoomOpenApiPlusTrInfo.Field('상한가', 540, 20, 305), KiwoomOpenApiPlusTrInfo.Field('하한가', 560, 20, 306), KiwoomOpenApiPlusTrInfo.Field('기준가', 580, 20, 307), KiwoomOpenApiPlusTrInfo.Field('예상체결가', 600, 20, 10023), KiwoomOpenApiPlusTrInfo.Field('예상체결수량', 620, 20, 10024), KiwoomOpenApiPlusTrInfo.Field('250최고가일', 640, 20, 1001), KiwoomOpenApiPlusTrInfo.Field('250최고가대비율', 660, 20, 1002), KiwoomOpenApiPlusTrInfo.Field('250최저가일', 680, 20, 1004), KiwoomOpenApiPlusTrInfo.Field('250최저가대비율', 700, 20, 1005), KiwoomOpenApiPlusTrInfo.Field('현재가', 720, 20, 10), KiwoomOpenApiPlusTrInfo.Field('대비기호', 740, 20, 25), KiwoomOpenApiPlusTrInfo.Field('전일대비', 760, 20, 11), KiwoomOpenApiPlusTrInfo.Field('등락율', 780, 20, 12), KiwoomOpenApiPlusTrInfo.Field('거래량', 800, 20, 13), KiwoomOpenApiPlusTrInfo.Field('거래대비', 820, 20, 30), KiwoomOpenApiPlusTrInfo.Field('액면가단위', 840, 20, 796), KiwoomOpenApiPlusTrInfo.Field('유통주식', 840, 20, 1683), KiwoomOpenApiPlusTrInfo.Field('유통비율', 840, 20, 1684)]
tr_info.multi_outputs
[]
5. 조건검색 예시¶
조건검색을 사용하기 위해서는 먼저 서버에 저장된 조건들을 불러와야 한다.
entrypoint.EnsureConditionLoaded()
1
불러온 조건들의 목록은 아래 함수로 확인이 가능하다.
conditions = entrypoint.GetConditionNameListAsList()
conditions
[(0, '대형 저평가 우량주'), (1, '중소형 저평가주')]
이후 예시의 정상동작을 위해서는 아래에서 사용되는 조건들과 같은 이름을 가지는 조건들이 미리 저장되어 있어야 한다.
- 대형 저평가 우량주
- 중소형 저평가주
위의 조건식들은 키움에서 예시로 제공하는 추천식들을 그대로 이름을 똑같이 해서 저장한 것들이다. 참고로 조건들을 편집하고 저장하는건 영웅문 HTS 내부에서만 가능하기 때문에 따로 HTS 를 열어 편집해주어야 한다.
조건식이 편집된 이후에 해당 조건식을 기존에 동작중인 OpenAPI 에도 갱신하고 싶은 경우, 아래 함수를 통해 편집된 조건식을 새로 불러온다.
entrypoint.LoadCondition()
1
일반 조건검색 예시¶
condition_name = '대형 저평가 우량주'
codes, info = entrypoint.GetCodeListByCondition(condition_name, with_info=True)
위의 함수에서 with_info=True
로 호출하게 되면 조건을 만족하는 코드 목록 (codes
) 뿐만 아니라 해당 종목들에 대한 기본정보들도 (info
) 같이 가져와 DataFrame 형태로 제공한다.
info
종목코드 | 종목명 | 현재가 | 기준가 | 전일대비 | 전일대비기호 | 등락율 | 거래량 | 거래대금 | 체결량 | ... | ELW만기일 | 미결제약정 | 미결제전일대비 | 이론가 | 내재변동성 | 델타 | 감마 | 쎄타 | 베가 | 로 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 000240 | 한국앤컴퍼니 | -14150 | 14450 | -300 | 5 | -2.08 | 56285 | 805 | +3 | ... | 00000000 | |||||||||
1 | 001800 | 오리온홀딩스 | -14900 | 15000 | -100 | 5 | -0.67 | 52845 | 787 | +9 | ... | 00000000 | |||||||||
2 | 001880 | DL건설 | -27950 | 29500 | -1550 | 5 | -5.25 | 93302 | 2648 | +84 | ... | 00000000 | |||||||||
3 | 003230 | 삼양식품 | -91400 | 93800 | -2400 | 5 | -2.56 | 38149 | 3516 | +4 | ... | 00000000 | |||||||||
4 | 003550 | LG | -79300 | 80500 | -1200 | 5 | -1.49 | 180692 | 14450 | +14 | ... | 00000000 | |||||||||
5 | 004000 | 롯데정밀화학 | -71600 | 72500 | -900 | 5 | -1.24 | 56962 | 4103 | +1 | ... | 00000000 | |||||||||
6 | 006040 | 동원산업 | -219000 | 222500 | -3500 | 5 | -1.57 | 2350 | 520 | -1 | ... | 00000000 | |||||||||
7 | 006390 | 한일현대시멘트 | -31850 | 33050 | -1200 | 5 | -3.63 | 24037 | 775 | -1 | ... | 00000000 | |||||||||
8 | 006650 | 대한유화 | -175000 | 179000 | -4000 | 5 | -2.23 | 35023 | 6159 | +1 | ... | 00000000 | |||||||||
9 | 007310 | 오뚜기 | -438000 | 438500 | -500 | 5 | -0.11 | 1551 | 681 | -1 | ... | 00000000 | |||||||||
10 | 007700 | F&F홀딩스 | -29450 | 30150 | -700 | 5 | -2.32 | 46278 | 1390 | +28 | ... | 00000000 | |||||||||
11 | 009970 | 영원무역홀딩스 | +49550 | 49400 | +150 | 2 | +0.30 | 11145 | 554 | +1 | ... | 00000000 | |||||||||
12 | 011780 | 금호석유 | -162500 | 167500 | -5000 | 5 | -2.99 | 116046 | 19104 | -1 | ... | 00000000 | |||||||||
13 | 014830 | 유니드 | -96300 | 99500 | -3200 | 5 | -3.22 | 60141 | 5907 | +14 | ... | 00000000 | |||||||||
14 | 017960 | 한국카본 | -11400 | 11850 | -450 | 5 | -3.80 | 613468 | 7088 | -7 | ... | 00000000 | |||||||||
15 | 020000 | 한섬 | -35600 | 36350 | -750 | 5 | -2.06 | 73551 | 2649 | -1 | ... | 00000000 | |||||||||
16 | 021240 | 코웨이 | +74000 | 73100 | +900 | 2 | +1.23 | 80976 | 5959 | -1 | ... | 00000000 | |||||||||
17 | 025540 | 한국단자 | +73800 | 73300 | +500 | 2 | +0.68 | 10834 | 796 | +2 | ... | 00000000 | |||||||||
18 | 030520 | 한글과컴퓨터 | -22400 | 22900 | -500 | 5 | -2.18 | 215490 | 4889 | -60 | ... | 00000000 | |||||||||
19 | 033290 | 코웰패션 | -8260 | 8370 | -110 | 5 | -1.31 | 291428 | 2448 | +1267 | ... | 00000000 | |||||||||
20 | 033780 | KT&G | -78400 | 78900 | -500 | 5 | -0.63 | 175828 | 13818 | +1000 | ... | 00000000 | |||||||||
21 | 036830 | 솔브레인홀딩스 | -31500 | 32400 | -900 | 5 | -2.78 | 46980 | 1504 | +50 | ... | 00000000 | |||||||||
22 | 042420 | 네오위즈홀딩스 | +72700 | 70700 | +2000 | 2 | +2.83 | 360097 | 26578 | -1 | ... | 00000000 | |||||||||
23 | 049070 | 인탑스 | +35150 | 33250 | +1900 | 2 | +5.71 | 370406 | 12957 | +227 | ... | 00000000 | |||||||||
24 | 056190 | 에스에프에이 | -34600 | 35100 | -500 | 5 | -1.42 | 85382 | 2968 | +35 | ... | 00000000 | |||||||||
25 | 057050 | 현대홈쇼핑 | -62100 | 62500 | -400 | 5 | -0.64 | 5482 | 342 | -1 | ... | 00000000 | |||||||||
26 | 060150 | 인선이엔티 | -11200 | 11550 | -350 | 5 | -3.03 | 254358 | 2890 | -1 | ... | 00000000 | |||||||||
27 | 064960 | SNT모티브 | -44550 | 45900 | -1350 | 5 | -2.94 | 34147 | 1537 | +9 | ... | 00000000 | |||||||||
28 | 069080 | 웹젠 | -24600 | 25000 | -400 | 5 | -1.60 | 142598 | 3564 | -1 | ... | 00000000 | |||||||||
29 | 081660 | 휠라홀딩스 | -30800 | 31600 | -800 | 5 | -2.53 | 240610 | 7499 | +2 | ... | 00000000 | |||||||||
30 | 095660 | 네오위즈 | +32550 | 31200 | +1350 | 2 | +4.33 | 642964 | 20979 | -4 | ... | 00000000 | |||||||||
31 | 096530 | 씨젠 | -54000 | 54100 | -100 | 5 | -0.18 | 500252 | 27426 | -25 | ... | 00000000 | |||||||||
32 | 110790 | 크리스에프앤씨 | -43750 | 44250 | -500 | 5 | -1.13 | 13699 | 604 | -1 | ... | 00000000 | |||||||||
33 | 111770 | 영원무역 | +47900 | 47250 | +650 | 2 | +1.38 | 140126 | 6809 | -2 | ... | 00000000 | |||||||||
34 | 137310 | 에스디바이오센서 | +51800 | 49750 | +2050 | 2 | +4.12 | 460725 | 23807 | -30 | ... | 00000000 | |||||||||
35 | 161390 | 한국타이어앤테크놀로지 | -35600 | 37300 | -1700 | 5 | -4.56 | 339364 | 12253 | +2 | ... | 00000000 | |||||||||
36 | 161890 | 한국콜마 | -37100 | 37800 | -700 | 5 | -1.85 | 53104 | 1995 | -1 | ... | 00000000 | |||||||||
37 | 185750 | 종근당 | -96300 | 98600 | -2300 | 5 | -2.33 | 28045 | 2749 | +70 | ... | 00000000 | |||||||||
38 | 192080 | 더블유게임즈 | -53100 | 53600 | -500 | 5 | -0.93 | 44488 | 2377 | +1 | ... | 00000000 | |||||||||
39 | 192400 | 쿠쿠홀딩스 | 18450 | 18450 | 0 | 3 | 0.00 | 14766 | 273 | +1 | ... | 00000000 | |||||||||
40 | 200130 | 콜마비앤에이치 | -28650 | 29100 | -450 | 5 | -1.55 | 43936 | 1271 | +1 | ... | 00000000 | |||||||||
41 | 271560 | 오리온 | -101500 | 103500 | -2000 | 5 | -1.93 | 84031 | 8592 | -26 | ... | 00000000 | |||||||||
42 | 284740 | 쿠쿠홈시스 | 37500 | 37500 | 0 | 3 | 0.00 | 22255 | 836 | -1 | ... | 00000000 | |||||||||
43 | 285130 | SK케미칼 | -140000 | 142000 | -2000 | 5 | -1.41 | 41634 | 5872 | -1 | ... | 00000000 | |||||||||
44 | 294870 | HDC현대산업개발 | -16350 | 18750 | -2400 | 5 | -12.80 | 5960884 | 101615 | +13 | ... | 00000000 | |||||||||
45 | 300720 | 한일시멘트 | -19050 | 20900 | -1850 | 5 | -8.85 | 830264 | 16299 | -100 | ... | 00000000 | |||||||||
46 | 950130 | 엑세스바이오 | -15900 | 16600 | -700 | 5 | -4.22 | 266293 | 4292 | +1 | ... | 00000000 |
47 rows × 63 columns
실시간 조건검색 예시¶
같은 조건식은 1분에 1건 제한이므로 예시 실행시 제한을 회피하기 위해서 새로 설정한다.
condition_name = '중소형 저평가주'
logging.info('Start listening realtime condition stream...')
stream = entrypoint.GetCodeListByConditionAsStream(condition_name)
2022-01-18 14:28:20,494 [INFO] Start listening realtime condition stream... - <ipython-input-51-f04b6a919f1c>:1
실시간 조건검색의 경우 조건에 만족/불만족하는 종목이 편입/이탈할때마다 계속해서 이벤트를 반환한다. 예시에서는 10초 동안만 이벤트를 확인해본다.
import threading
def stop_listening():
logging.info('Stop listening realtime condition events...')
stream.cancel()
threading.Timer(65.0, stop_listening).start() # 65초 이후에 gRPC 커넥션 종료하도록 설정
import grpc
events = []
try:
for event in stream:
events.append(event)
pprint_event(event)
except grpc.RpcError as e:
print(e)
{'arguments': [{'string_value': '8686'}, {'string_value': '900290;900310;900340;002170;017890;036190;037710;049430;073560;084650;140910;187870;192440;210540;225220;352700;950190;900280;900250;'}, {'string_value': '중소형 저평가주'}, {'long_value': '1'}, {'long_value': '0'}], 'name': 'OnReceiveTrCondition'}
2022-01-18 14:29:25,810 [INFO] Stop listening realtime condition events... - <ipython-input-52-679886c13a31>:4
<_MultiThreadedRendezvous of RPC that terminated with: status = StatusCode.CANCELLED details = "Locally cancelled by application!" debug_error_string = "None" >
위에서 stream
결과는 grpc
의 _MultiThreadedRendezvous
객체인데 사실 해당 타입은 직접적으로 외부에 노출되는 타입은 아니다. 대신에 해당 타입은 내부적으로 grpc.RpcError
, grpc.RpcContext
, grpc.Call
, grpc.Future
인터페이스를 구현하고 있으므로 해당 객체의 사용법과 관련해서는 각각의 인터페이스를 참고하자.
최초 이벤트로 반환되는 코드 목록들에 대해서 앞선 일반조건 검색 예시에서와 같이 종목들의 기본정보들을 별도로 가져오고 싶다면 대략 아래처럼 해볼 수 있다.
if len(events) > 0:
codes = events[0].arguments[1].string_value.strip(';').split(';')
else:
codes = [samsung_code]
codes
['900290', '900310', '900340', '002170', '017890', '036190', '037710', '049430', '073560', '084650', '140910', '187870', '192440', '210540', '225220', '352700', '950190', '900280', '900250']
info = entrypoint.GetStockQuoteInfoAsDataFrame(codes)
info
종목코드 | 종목명 | 현재가 | 기준가 | 전일대비 | 전일대비기호 | 등락율 | 거래량 | 거래대금 | 체결량 | ... | ELW만기일 | 미결제약정 | 미결제전일대비 | 이론가 | 내재변동성 | 델타 | 감마 | 쎄타 | 베가 | 로 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 900290 | GRT | 1225 | 1225 | 0 | 3 | 0.00 | 123651 | 152 | -130 | ... | 00000000 | |||||||||
1 | 900310 | 컬러레이 | -1425 | 1465 | -40 | 5 | -2.73 | 147191 | 213 | +294 | ... | 00000000 | |||||||||
2 | 900340 | 윙입푸드 | -1175 | 1215 | -40 | 5 | -3.29 | 187400 | 224 | -144 | ... | 00000000 | |||||||||
3 | 002170 | 삼양통상 | -57500 | 57900 | -400 | 5 | -0.69 | 3467 | 201 | -4 | ... | 00000000 | |||||||||
4 | 017890 | 한국알콜 | -11500 | 11600 | -100 | 5 | -0.86 | 56037 | 647 | +1 | ... | 00000000 | |||||||||
5 | 036190 | 금화피에스시 | -30450 | 30800 | -350 | 5 | -1.14 | 3356 | 102 | +1 | ... | 00000000 | |||||||||
6 | 037710 | 광주신세계 | 171500 | 171500 | 0 | 3 | 0.00 | 510 | 88 | -28 | ... | 00000000 | |||||||||
7 | 049430 | 코메론 | -10450 | 10600 | -150 | 5 | -1.42 | 20522 | 215 | +2 | ... | 00000000 | |||||||||
8 | 073560 | 우리손에프앤지 | -2135 | 2150 | -15 | 5 | -0.70 | 162170 | 349 | -170 | ... | 00000000 | |||||||||
9 | 084650 | 랩지노믹스 | -22900 | 23000 | -100 | 5 | -0.43 | 138975 | 3241 | +1 | ... | 00000000 | |||||||||
10 | 140910 | 에이리츠 | +7930 | 7900 | +30 | 2 | +0.38 | 5383 | 43 | -3 | ... | 00000000 | |||||||||
11 | 187870 | 디바이스이엔지 | -27300 | 27950 | -650 | 5 | -2.33 | 17219 | 474 | -100 | ... | 00000000 | |||||||||
12 | 192440 | 슈피겐코리아 | +44150 | 43300 | +850 | 2 | +1.96 | 20554 | 907 | -5 | ... | 00000000 | |||||||||
13 | 210540 | 디와이파워 | -12950 | 13250 | -300 | 5 | -2.26 | 108583 | 1417 | -23 | ... | 00000000 | |||||||||
14 | 225220 | 제놀루션 | -13800 | 14150 | -350 | 5 | -2.47 | 32068 | 443 | +2 | ... | 00000000 | |||||||||
15 | 352700 | 씨앤투스성진 | -6540 | 6710 | -170 | 5 | -2.53 | 414227 | 2751 | -20 | ... | 00000000 | |||||||||
16 | 950190 | 미투젠 | -20200 | 20500 | -300 | 5 | -1.46 | 69198 | 1398 | +1 | ... | 00000000 | |||||||||
17 | 900280 | 골든센츄리 | +363 | 362 | +1 | 2 | +0.28 | 674649 | 243 | +1 | ... | 00000000 | |||||||||
18 | 900250 | 크리스탈신소재 | -1400 | 1430 | -30 | 5 | -2.10 | 1171968 | 1657 | +1 | ... | 00000000 |
19 rows × 63 columns
아니면 stream
생성시에 with_info=True
를 주는 경우 매 조건 이벤트마다 바로 뒤에 관심종목정보요청 이벤트를 이어서 반환하는데, 결국은 약간의 별도 데이터 처리가 필요하다.
condition_name = '중소형 저평가주'
logging.info('Start listening realtime condition stream...')
stream = entrypoint.GetCodeListByConditionAsStream(condition_name, with_info=True)
2022-01-18 14:29:25,992 [INFO] Start listening realtime condition stream... - <ipython-input-59-433baeb2b447>:1
실시간 조건검색의 경우 조건에 만족/불만족하는 종목이 편입/이탈할때마다 계속해서 이벤트를 반환한다. 예시에서는 10초 동안만 이벤트를 확인해본다.
import threading
def stop_listening():
logging.info('Stop listening realtime condition events...')
stream.cancel()
threading.Timer(10.0, stop_listening).start() # 10초 이후에 gRPC 커넥션 종료하도록 설정
import grpc
events = []
try:
for event in stream:
events.append(event)
pprint_event(event)
except grpc.RpcError as e:
print(e)
{'arguments': [{'string_value': '9991'}, {'string_value': '900290;900310;900340;002170;017890;036190;037710;049430;073560;084650;140910;187870;192440;210540;225220;352700;950190;900280;900250;'}, {'string_value': '중소형 저평가주'}, {'long_value': '1'}, {'long_value': '0'}], 'name': 'OnReceiveTrCondition'} {'arguments': [{'string_value': '9991'}, {'string_value': '관심종목정보요청'}, {'string_value': 'OPTKWFID'}, {'string_value': ''}, {'string_value': '0'}], 'multi_data': {'names': ['종목코드', '종목명', '현재가', '기준가', '전일대비', '전일대비기호', '등락율', '거래량', '거래대금', '체결량', '체결강도', '전일거래량대비', '매도호가', '매수호가', '매도1차호가', '매도2차호가', '매도3차호가', '매도4차호가', '매도5차호가', '매수1차호가', '매수2차호가', '매수3차호가', '매수4차호가', '매수5차호가', '상한가', '하한가', '시가', '고가', '저가', '종가', '체결시간', '예상체결가', '예상체결량', '자본금', '액면가', '시가총액', '주식수', '호가시간', '일자', '우선매도잔량', '우선매수잔량', '우선매도건수', '우선매수건수', '총매도잔량', '총매수잔량', '총매도건수', '총매수건수', '패리티', '기어링', '손익분기', '자본지지', 'ELW행사가', '전환비율', 'ELW만기일', '미결제약정', '미결제전일대비', '이론가', '내재변동성', '델타', '감마', '쎄타', '베가', '로'], 'values': [{'values': ['900290', 'GRT', '1225', '1225', '0', '3', '0.00', '123651', '152', '-130', '25.57', '-17.52', '+1230', '1225', '+1230', '+1235', '+1240', '+1245', '+1250', '1225', '-1220', '-1215', '-1210', '-1205', '+1590', '-860', '1225', '+1230', '1225', '1225', '142905', '1225', '535', '770', '0.00', '825', '67375', '142905', '20220118', '30482', '509886', '', '', '187501', '754859', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['900310', '컬러레이', '-1425', '1465', '-40', '5', '-2.73', '147191', '213', '+294', '38.29', '+135.98', '-1425', '-1420', '-1425', '-1430', '-1435', '-1440', '-1445', '-1420', '-1415', '-1410', '-1405', '-1400', '+1900', '-1030', '+1475', '+1485', '-1420', '-1425', '142810', '+1475', '69', '336', '0.00', '770', '54000', '142834', '20220118', '36', '10171', '', '', '12441', '56620', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['900340', '윙입푸드', '-1175', '1215', '-40', '5', '-3.29', '187400', '224', '-144', '60.89', '+192.27', '-1185', '-1175', '-1185', '-1190', '-1195', '-1200', '-1205', '-1175', '-1170', '-1165', '-1160', '-1155', '+1575', '-855', '1215', '+1230', '-1165', '-1175', '142850', '1215', '6', '294', '0.00', '564', '47973', '142912', '20220118', '3102', '5356', '', '', '35173', '30035', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['002170', '삼양통상', '-57500', '57900', '-400', '5', '-0.69', '3467', '201', '-4', '62.68', '-54.14', '-57600', '-57500', '-57600', '-57700', '-57800', '57900', '+58000', '-57500', '-57400', '-57300', '-57200', '-57100', '+75200', '-40600', '+58000', '+58500', '-57500', '-57500', '142838', '+58000', '2', '150', '5000', '1725', '3000', '142905', '20220118', '222', '19', '', '', '7971', '878', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['017890', '한국알콜', '-11500', '11600', '-100', '5', '-0.86', '56037', '647', '+1', '30.61', '+126.56', '-11500', '-11450', '-11500', '-11550', '11600', '+11650', '+11700', '-11450', '-11400', '-11350', '-11300', '-11250', '+15050', '-8150', '11600', '+11750', '-11400', '-11500', '142908', '11600', '898', '108', '500', '2485', '21606', '142913', '20220118', '2351', '2032', '', '', '22942', '20124', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['036190', '금화피에스시', '-30450', '30800', '-350', '5', '-1.14', '3356', '102', '+1', '30.63', '-91.29', '-30450', '-30350', '-30450', '-30500', '-30550', '-30600', '-30650', '-30350', '-30200', '-30150', '-30100', '-30050', '+40000', '-21600', '-30750', '30800', '-30200', '-30450', '142555', '-30750', '4', '30', '500', '1827', '6000', '142607', '20220118', '35', '2', '', '', '2160', '2879', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['037710', '광주신세계', '171500', '171500', '0', '3', '0.00', '510', '88', '-28', '44.60', '-58.76', '171500', '-171000', '171500', '+172000', '+172500', '+173000', '+173500', '-171000', '-170500', '-170000', '-169500', '-169000', '+222500', '-120500', '171500', '+173000', '-171000', '171500', '142825', '171500', '1', '80', '5000', '2744', '1600', '142914', '20220118', '6', '167', '', '', '326', '581', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['049430', '코메론', '-10450', '10600', '-150', '5', '-1.42', '20522', '215', '+2', '75.92', '-62.99', '-10450', '-10400', '-10450', '-10500', '-10550', '10600', '+10650', '-10400', '-10350', '-10300', '-10250', '-10200', '+13750', '-7450', '10600', '+10650', '-10350', '-10450', '142851', '10600', '54', '45', '500', '946', '9048', '142851', '20220118', '256', '3', '', '', '3616', '29091', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['073560', '우리손에프앤지', '-2135', '2150', '-15', '5', '-0.70', '162170', '349', '-170', '34.01', '-41.38', '-2140', '-2130', '-2140', '-2145', '2150', '+2155', '+2160', '-2130', '-2125', '-2120', '-2115', '-2110', '+2795', '-1505', '-2145', '+2170', '-2130', '-2135', '142750', '-2145', '1777', '346', '500', '1478', '69238', '142750', '20220118', '140', '3176', '', '', '44163', '80317', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['084650', '랩지노믹스', '-22900', '23000', '-100', '5', '-0.43', '138975', '3241', '+1', '69.13', '-87.60', '-22900', '-22850', '-22900', '-22950', '23000', '+23050', '+23100', '-22850', '-22800', '-22750', '-22700', '-22650', '+29900', '-16100', '23000', '+23750', '-22800', '-22900', '142921', '23000', '6118', '57', '500', '2622', '11450', '142921', '20220118', '852', '930', '', '', '5683', '15214', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['140910', '에이리츠', '+7930', '7900', '+30', '2', '+0.38', '5383', '43', '-3', '151.92', '-32.82', '+7940', '+7930', '+7940', '+7970', '+7990', '+8030', '+8040', '+7930', '+7920', '+7910', '7900', '-7890', '+10250', '-5530', '7900', '+8200', '7900', '+7930', '142341', '7900', '12', '211', '5000', '334', '4217', '142341', '20220118', '683', '15', '', '', '953', '4310', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['187870', '디바이스이엔지', '-27300', '27950', '-650', '5', '-2.33', '17219', '474', '-100', '31.97', '+131.63', '-27350', '-27300', '-27350', '-27400', '-27450', '-27500', '-27550', '-27300', '-27250', '-27200', '-27150', '-27100', '+36300', '-19600', '-27600', '+28050', '-27250', '-27300', '142830', '-27600', '374', '35', '500', '1921', '7037', '142913', '20220118', '955', '451', '', '', '4104', '3041', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['192440', '슈피겐코리아', '+44150', '43300', '+850', '2', '+1.96', '20554', '907', '-5', '139.80', '+174.04', '+44200', '+44150', '+44200', '+44250', '+44300', '+44350', '+44400', '+44150', '+44100', '+44050', '+44000', '+43950', '+56200', '-30350', '-43200', '+44600', '-43150', '+44150', '142921', '-43200', '281', '31', '500', '2745', '6216', '142921', '20220118', '115', '97', '', '', '4084', '1215', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['210540', '디와이파워', '-12950', '13250', '-300', '5', '-2.26', '108583', '1417', '-23', '12.78', '+173.32', '-13000', '-12950', '-13000', '-13050', '-13100', '-13150', '-13200', '-12950', '-12900', '-12850', '-12800', '-12750', '+17200', '-9300', '13250', '+13350', '-12950', '-12950', '142901', '13250', '23', '55', '500', '1430', '11042', '142901', '20220118', '1165', '2762', '', '', '29442', '26833', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['225220', '제놀루션', '-13800', '14150', '-350', '5', '-2.47', '32068', '443', '+2', '22.44', '-65.12', '-13800', '-13700', '-13800', '-13850', '-13900', '-13950', '-14000', '-13700', '-13650', '-13600', '-13550', '-13500', '+18350', '-9950', '14150', '14150', '-13700', '-13800', '142725', '14150', '110', '48', '500', '1320', '9567', '142845', '20220118', '440', '427', '', '', '5911', '7650', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['352700', '씨앤투스성진', '-6540', '6710', '-170', '5', '-2.53', '414227', '2751', '-20', '49.09', '-63.02', '-6550', '-6540', '-6550', '-6560', '-6570', '-6580', '-6590', '-6540', '-6530', '-6520', '-6510', '-6500', '+8720', '-4700', '6710', '+6770', '-6520', '-6540', '142924', '6710', '4257', '143', '500', '1849', '28277', '142924', '20220118', '1936', '179', '', '', '15891', '48036', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['950190', '미투젠', '-20200', '20500', '-300', '5', '-1.46', '69198', '1398', '+1', '67.76', '-78.33', '-20200', '-20100', '-20200', '-20300', '-20350', '-20400', '-20450', '-20100', '-20050', '-20000', '-19950', '-19900', '+26650', '-14350', '20500', '+20550', '-19950', '-20200', '142708', '20500', '553', '0', '0', '2743', '13580', '142919', '20220118', '760', '21', '', '', '8086', '9052', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['900280', '골든센츄리', '+363', '362', '+1', '2', '+0.28', '674649', '243', '+1', '81.03', '+150.12', '+363', '362', '+363', '+364', '+365', '+366', '+367', '362', '-361', '-360', '-359', '-358', '+470', '-254', '362', '+365', '-358', '+363', '142834', '362', '592', '35', '0.20', '641', '176574', '142834', '20220118', '10931', '12647', '', '', '71073', '184853', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}, {'values': ['900250', '크리스탈신소재', '-1400', '1430', '-30', '5', '-2.10', '1171968', '1657', '+1', '37.44', '-61.96', '-1400', '-1390', '-1400', '-1405', '-1410', '-1415', '-1420', '-1390', '-1385', '-1380', '-1375', '-1370', '+1855', '-1005', '+1435', '+1445', '-1385', '-1400', '142920', '+1435', '5363', '36', '0.50', '1006', '71831', '142920', '20220118', '3351', '30868', '', '', '123110', '189904', '0', '', '0.00', '0.00', '0.00', '0.00', '0', '0.0000', '00000000', '', '', '', '', '', '', '', '', '']}]}, 'name': 'OnReceiveTrData'}
2022-01-18 14:29:36,025 [INFO] Stop listening realtime condition events... - <ipython-input-60-c769dc00f6f7>:4
<_MultiThreadedRendezvous of RPC that terminated with: status = StatusCode.CANCELLED details = "Locally cancelled by application!" debug_error_string = "None" >
condition_event = events[0]
info_event = events[1]
records = [values.values for values in info_event.multi_data.values]
columns = info_event.multi_data.names
info = pd.DataFrame.from_records(records, columns=columns)
info
종목코드 | 종목명 | 현재가 | 기준가 | 전일대비 | 전일대비기호 | 등락율 | 거래량 | 거래대금 | 체결량 | ... | ELW만기일 | 미결제약정 | 미결제전일대비 | 이론가 | 내재변동성 | 델타 | 감마 | 쎄타 | 베가 | 로 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 900290 | GRT | 1225 | 1225 | 0 | 3 | 0.00 | 123651 | 152 | -130 | ... | 00000000 | |||||||||
1 | 900310 | 컬러레이 | -1425 | 1465 | -40 | 5 | -2.73 | 147191 | 213 | +294 | ... | 00000000 | |||||||||
2 | 900340 | 윙입푸드 | -1175 | 1215 | -40 | 5 | -3.29 | 187400 | 224 | -144 | ... | 00000000 | |||||||||
3 | 002170 | 삼양통상 | -57500 | 57900 | -400 | 5 | -0.69 | 3467 | 201 | -4 | ... | 00000000 | |||||||||
4 | 017890 | 한국알콜 | -11500 | 11600 | -100 | 5 | -0.86 | 56037 | 647 | +1 | ... | 00000000 | |||||||||
5 | 036190 | 금화피에스시 | -30450 | 30800 | -350 | 5 | -1.14 | 3356 | 102 | +1 | ... | 00000000 | |||||||||
6 | 037710 | 광주신세계 | 171500 | 171500 | 0 | 3 | 0.00 | 510 | 88 | -28 | ... | 00000000 | |||||||||
7 | 049430 | 코메론 | -10450 | 10600 | -150 | 5 | -1.42 | 20522 | 215 | +2 | ... | 00000000 | |||||||||
8 | 073560 | 우리손에프앤지 | -2135 | 2150 | -15 | 5 | -0.70 | 162170 | 349 | -170 | ... | 00000000 | |||||||||
9 | 084650 | 랩지노믹스 | -22900 | 23000 | -100 | 5 | -0.43 | 138975 | 3241 | +1 | ... | 00000000 | |||||||||
10 | 140910 | 에이리츠 | +7930 | 7900 | +30 | 2 | +0.38 | 5383 | 43 | -3 | ... | 00000000 | |||||||||
11 | 187870 | 디바이스이엔지 | -27300 | 27950 | -650 | 5 | -2.33 | 17219 | 474 | -100 | ... | 00000000 | |||||||||
12 | 192440 | 슈피겐코리아 | +44150 | 43300 | +850 | 2 | +1.96 | 20554 | 907 | -5 | ... | 00000000 | |||||||||
13 | 210540 | 디와이파워 | -12950 | 13250 | -300 | 5 | -2.26 | 108583 | 1417 | -23 | ... | 00000000 | |||||||||
14 | 225220 | 제놀루션 | -13800 | 14150 | -350 | 5 | -2.47 | 32068 | 443 | +2 | ... | 00000000 | |||||||||
15 | 352700 | 씨앤투스성진 | -6540 | 6710 | -170 | 5 | -2.53 | 414227 | 2751 | -20 | ... | 00000000 | |||||||||
16 | 950190 | 미투젠 | -20200 | 20500 | -300 | 5 | -1.46 | 69198 | 1398 | +1 | ... | 00000000 | |||||||||
17 | 900280 | 골든센츄리 | +363 | 362 | +1 | 2 | +0.28 | 674649 | 243 | +1 | ... | 00000000 | |||||||||
18 | 900250 | 크리스탈신소재 | -1400 | 1430 | -30 | 5 | -2.10 | 1171968 | 1657 | +1 | ... | 00000000 |
19 rows × 63 columns
6. 주문처리 예시¶
first_account_no = entrypoint.GetFirstAvailableAccount()
request_name = "삼성전자 1주 시장가 신규 매수" # 사용자 구분명, 구분가능한 임의의 문자열
screen_no = "0001" # 화면번호, 0000 을 제외한 4자리 숫자 임의로 지정, None 의 경우 내부적으로 화면번호 자동할당
account_no = first_account_no # 계좌번호 10자리, 여기서는 계좌번호 목록에서 첫번째로 발견한 계좌번호로 매수처리
order_type = 1 # 주문유형, 1 : 신규매수
code = samsung_code # 종목코드, 앞의 삼성전자 종목코드
quantity = 1 # 주문수량, 1주 매수
price = 0 # 주문가격, 시장가 매수는 가격설정 의미없음
quote_type = "03" # 거래구분, 03 : 시장가
original_order_no = "" # 원주문번호, 주문 정정/취소 등에서 사용
주문유형 및 거래구분 등과 관련된 자세한 정보들은 KOAStudio 프로그램에서 확인할 수 있다.
주문처리는 실제 시장이 열려있는 동안에만 테스트해볼 수 있기 때문에, 현재 장이 열려 있는지 먼저 확인하고 해당 경우에 한정해서 테스트를 진행한다.
from pandas import Timestamp
from exchange_calendars import get_calendar
krx_calendar = get_calendar('XKRX')
def is_currently_in_session():
calendar = krx_calendar
now = Timestamp.now(calendar.tz).floor("T")
previous_open = calendar.previous_open(now).astimezone(calendar.tz)
next_close = calendar.next_close(previous_open).astimezone(calendar.tz)
return previous_open <= now <= next_close
if is_currently_in_session():
logging.info('Sending order to buy %s, quantity of 1 stock, at market price...', code)
for event in entrypoint.OrderCall(request_name, screen_no, account_no, order_type, code, quantity, price, quote_type, original_order_no):
pprint_event(event)
else:
logging.info('Cannot send an order while market is not open, skipping...')
2022-01-18 14:29:41,362 [INFO] Sending order to buy 005930, quantity of 1 stock, at market price... - <ipython-input-67-37048f99b24d>:2
{'arguments': [{'string_value': '0001'}, {'string_value': '삼성전자 1주 시장가 신규 매수'}, {'string_value': 'KOA_NORMAL_BUY_KP_ORD'}, {'string_value': '[100000] 모의투자 매수주문완료'}], 'name': 'OnReceiveMsg'} {'arguments': [{'string_value': '0001'}, {'string_value': '삼성전자 1주 시장가 신규 매수'}, {'string_value': 'KOA_NORMAL_BUY_KP_ORD'}, {'string_value': ''}, {'string_value': ''}], 'name': 'OnReceiveTrData', 'single_data': {'names': ['주문번호'], 'values': ['0163911']}} {'arguments': [{'string_value': '0'}, {'long_value': '35'}, {'string_value': '9201;9203;9205;9001;912;913;302;900;901;902;903;904;905;906;907;908;909;910;911;10;27;28;914;915;938;939;919;920;921;922;923;949;10010;969;819'}], 'name': 'OnReceiveChejanData', 'single_data': {'names': ['계좌번호', '주문번호', '관리사번', '종목코드', '업무구분', '주문상태', '종목명', '주문수량', '주문가격', '미체결수량', '체결누계금액', '원주문번호', '주문구분', '매매구분', '매도수구분', '주문/체결시간', '체결번호', '체결가', '체결량', '현재가', '매도호가', '매수호가', '단위체결가', '단위체결량', '당일매매수수료', '당일매매세금', '919', '920', '921', '922', '923', '949', '시간외단일가_현재가', '969', '819'], 'values': ['8014526011', '0163911', '', 'A005930', 'JJ', '접수', '삼성전자', '1', '0', '1', '0', '0000000', '+매수', '시장가', '2', '142940', '', '', '', '-77000', '-77100', '-77000', '', '', '0', '0', '0', '0001', '', '00', '00000000', '3', '-77300', '0', '0']}} {'arguments': [{'string_value': '0'}, {'long_value': '35'}, {'string_value': '9201;9203;9205;9001;912;913;302;900;901;902;903;904;905;906;907;908;909;910;911;10;27;28;914;915;938;939;919;920;921;922;923;949;10010;969;819'}], 'name': 'OnReceiveChejanData', 'single_data': {'names': ['계좌번호', '주문번호', '관리사번', '종목코드', '업무구분', '주문상태', '종목명', '주문수량', '주문가격', '미체결수량', '체결누계금액', '원주문번호', '주문구분', '매매구분', '매도수구분', '주문/체결시간', '체결번호', '체결가', '체결량', '현재가', '매도호가', '매수호가', '단위체결가', '단위체결량', '당일매매수수료', '당일매매세금', '919', '920', '921', '922', '923', '949', '시간외단일가_현재가', '969', '819'], 'values': ['8014526011', '0163911', '', 'A005930', 'JJ', '체결', '삼성전자', '1', '0', '0', '77000', '0000000', '+매수', '시장가', '2', '142941', '1234931', '77000', '1', '-77000', '-77100', '-77000', '77000', '1', '260', '0', '0', '0001', '', '00', '00000000', '3', '-77300', '0', '0']}} {'arguments': [{'string_value': '1'}, {'long_value': '34'}, {'string_value': '9201;9001;917;916;302;10;930;931;932;933;945;946;950;951;27;28;307;8019;957;958;918;990;991;992;993;959;924;10010;25;11;12;306;305;970'}], 'name': 'OnReceiveChejanData', 'single_data': {'names': ['계좌번호', '종목코드', '신용구분', '대출일', '종목명', '현재가', '보유수량', '매입단가', '총매입가', '주문가능수량', '당일순매수량', '매도/매수구분', '당일총매도손익', '예수금', '매도호가', '매수호가', '기준가', '손익율', '신용금액', '신용이자', '만기일', '990', '991', '992', '993', '담보대출수량', '924', '시간외단일가_현재가', '전일대비기호', '전일대비', '등락율', '하한가', '상한가', '970'], 'values': ['8014526011', 'A005930', '00', '00000000', '삼성전자', '-77000', '2', '77150', '154300', '2', '1', '2', '0', '0', '-77100', '-77000', '77500', '0.00', '0', '0', '00000000', '0', '0.00', '0', '0.00', '0', '0', '-77300', '5', '-500', '-0.65', '-54300', '+100500', '10']}}
주문 이벤트는 기본적으로 주문수량이 모두 소진되기 전까지 이벤트를 듣도록 되어있으며, 다른 이벤트 스트림과 동일하게 stream.cancel()
의 형태로 이벤트 스트림을 더이상 듣지 않도록 하는것이 가능하다. 다만 이벤트 스트림을 취소하는 것이 기존 주문까지 취소하는 것은 아니기 때문에 주문취소나 정정등을 위해서는 별도의 취소/정정 주문을 넣어줘야 한다.
여기서 반환되는 이벤트 객체 역시 앞선 TR 예시에서와 동일하게 ListenResponse
타입의 gRPC 메시지 형태로 반환된다.
7. 실시간 데이터 처리 예시¶
from koapy import KiwoomOpenApiPlusRealType
code_list = [code]
fid_list = KiwoomOpenApiPlusRealType.get_fids_by_realtype_name('주식시세')
opt_type = '0' # 기존 화면에 추가가 아니라 신규 생성, 1 의 경우 기존 화면번호에 추가
logging.info('Start listening realtime stock data for code: %s', code)
stream = entrypoint.GetRealDataForCodesAsStream(
code_list,
fid_list,
opt_type,
screen_no=None, # 화면번호, 0000 을 제외한 4자리 숫자 임의로 지정, None 의 경우 내부적으로 화면번호 자동할당
infer_fids=True, # True 로 설정 시 주어진 fid_list 를 고집하지 말고 이벤트 처리 함수의 인자로 전달받는 실시간데이터 이름에 따라 유연하게 fid_list 를 추론
readable_names=True, # True 로 설정 시 각 fid 마다 숫자 대신 읽을 수 있는 이름으로 변환하여 반환
fast_parse=False, # True 로 설정 시 이벤트 처리 함수내에서 데이터 값 읽기 시 GetCommRealData() 함수 호출 대신, 이벤트 처리 함수의 인자로 넘어오는 데이터를 직접 활용, infer_fids 가 True 로 설정된 경우만 유의미함
)
2022-01-18 14:29:43,322 [INFO] Start listening realtime stock data for code: 005930 - <ipython-input-70-dd8474120071>:1
import threading
def stop_listening():
logging.info('Stop listening realtime events...')
stream.cancel()
threading.Timer(10.0, stop_listening).start() # 10초 이후에 gRPC 커넥션 종료하도록 설정
import grpc
try:
for i, event in enumerate(stream):
if i < 10:
pprint_event(event) # 노트북 출력이 너무 길어질 수 있어 최초 10개만 출력
except grpc.RpcError as e:
print(e)
{'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142942\t-77100\t-400\t-0.52\t-77100\t-76900\t' '+3\t7884712\t608869\t+77600\t+77800\t-76600\t' '5\t-900410\t-70033816000\t-89.75\t0.13\t201\t' '61.12\t4602702\t2\t0\t-89.68\t000000\t000000\t' '11814\t090003\t100015\t133453\t4817707\t' '2944634\t-37.93\t30338\t31739\t+231\t 0\t+3\t' '+3\t30840\t24672\t77222\t411'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142942', '-77100', '-400', '-0.52', '-77100', '-76900', '+3', '7884712', '608869', '+77600', '+77800', '-76600', '5', '-900410', '-70033816000', '-89.75', '0.13', '201', '61.12', '4602702', '2', '0', '-89.68', '000000', '000000', '11814', '090003', '100015', '133453', '4817707', '2944634', '-37.93', '30338', '31739', '+231', ' 0', '+3', '+3', '30840', '24672', '77222', '411']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식우선호가'}, {'string_value': '-77000\t-76900'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['매도호가', '매수호가'], 'values': ['-77000', '-76900']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식우선호가'}, {'string_value': '-77100\t-77000'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['매도호가', '매수호가'], 'values': ['-77100', '-77000']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142943\t-77000\t-500\t-0.65\t-77100\t-77000\t' '+20\t7884732\t608871\t+77600\t+77800\t-76600\t' '5\t-900390\t-70032276000\t-89.75\t0.13\t201\t' '61.12\t4596733\t2\t0\t-89.68\t000000\t000000\t' '11814\t090003\t100015\t133453\t4817707\t' '2944654\t-37.94\t30338\t31740\t+1540\t 0\t' '+20\t+20\t30800\t24640\t77222\t410'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142943', '-77000', '-500', '-0.65', '-77100', '-77000', '+20', '7884732', '608871', '+77600', '+77800', '-76600', '5', '-900390', '-70032276000', '-89.75', '0.13', '201', '61.12', '4596733', '2', '0', '-89.68', '000000', '000000', '11814', '090003', '100015', '133453', '4817707', '2944654', '-37.94', '30338', '31740', '+1540', ' 0', '+20', '+20', '30800', '24640', '77222', '410']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142945\t-77000\t-500\t-0.65\t-77100\t-77000\t' '-262\t7884994\t608891\t+77600\t+77800\t' '-76600\t5\t-900128\t-70012102000\t-89.75\t' '0.13\t201\t61.12\t4596733\t2\t0\t-89.69\t' '000000\t000000\t11814\t090003\t100015\t' '133453\t4817969\t2944654\t-37.93\t30339\t' '31740\t-20174\t-262\t 0\t-262\t30800\t24640\t' '77221\t410'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142945', '-77000', '-500', '-0.65', '-77100', '-77000', '-262', '7884994', '608891', '+77600', '+77800', '-76600', '5', '-900128', '-70012102000', '-89.75', '0.13', '201', '61.12', '4596733', '2', '0', '-89.69', '000000', '000000', '11814', '090003', '100015', '133453', '4817969', '2944654', '-37.93', '30339', '31740', '-20174', '-262', ' 0', '-262', '30800', '24640', '77221', '410']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142945\t-77000\t-500\t-0.65\t-77100\t-77000\t' '-3\t7884997\t608891\t+77600\t+77800\t-76600\t' '5\t-900125\t-70011871000\t-89.75\t0.13\t201\t' '61.12\t4596733\t2\t0\t-89.69\t000000\t000000\t' '11814\t090003\t100015\t133453\t4817972\t' '2944654\t-37.93\t30340\t31740\t-231\t-3\t 0\t' '-3\t30800\t24640\t77221\t410'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142945', '-77000', '-500', '-0.65', '-77100', '-77000', '-3', '7884997', '608891', '+77600', '+77800', '-76600', '5', '-900125', '-70011871000', '-89.75', '0.13', '201', '61.12', '4596733', '2', '0', '-89.69', '000000', '000000', '11814', '090003', '100015', '133453', '4817972', '2944654', '-37.93', '30340', '31740', '-231', '-3', ' 0', '-3', '30800', '24640', '77221', '410']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142946\t-77100\t-400\t-0.52\t-77100\t-77000\t' '+3\t7885000\t608891\t+77600\t+77800\t-76600\t' '5\t-900122\t-70011639700\t-89.75\t0.13\t201\t' '61.12\t4602702\t2\t0\t-89.69\t000000\t000000\t' '11814\t090003\t100015\t133453\t4817972\t' '2944657\t-37.93\t30340\t31741\t+231\t 0\t+3\t' '+3\t30840\t24672\t77221\t411'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142946', '-77100', '-400', '-0.52', '-77100', '-77000', '+3', '7885000', '608891', '+77600', '+77800', '-76600', '5', '-900122', '-70011639700', '-89.75', '0.13', '201', '61.12', '4602702', '2', '0', '-89.69', '000000', '000000', '11814', '090003', '100015', '133453', '4817972', '2944657', '-37.93', '30340', '31741', '+231', ' 0', '+3', '+3', '30840', '24672', '77221', '411']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142946\t-77000\t-500\t-0.65\t-77100\t-77000\t' '-1\t7885001\t608892\t+77600\t+77800\t-76600\t' '5\t-900121\t-70011562700\t-89.75\t0.13\t201\t' '61.12\t4596733\t2\t0\t-89.69\t000000\t000000\t' '11814\t090003\t100015\t133453\t4817973\t' '2944657\t-37.93\t30341\t31741\t-77\t-1\t 0\t' '-1\t30800\t24640\t77221\t410'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142946', '-77000', '-500', '-0.65', '-77100', '-77000', '-1', '7885001', '608892', '+77600', '+77800', '-76600', '5', '-900121', '-70011562700', '-89.75', '0.13', '201', '61.12', '4596733', '2', '0', '-89.69', '000000', '000000', '11814', '090003', '100015', '133453', '4817973', '2944657', '-37.93', '30341', '31741', '-77', '-1', ' 0', '-1', '30800', '24640', '77221', '410']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142947\t-77000\t-500\t-0.65\t-77100\t-77000\t' '-10\t7885011\t608892\t+77600\t+77800\t-76600\t' '5\t-900111\t-70010792700\t-89.75\t0.13\t201\t' '61.12\t4596733\t2\t0\t-89.69\t000000\t000000\t' '11814\t090003\t100015\t133453\t4817983\t' '2944657\t-37.93\t30342\t31741\t-770\t-10\t 0\t' '-10\t30800\t24640\t77221\t410'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142947', '-77000', '-500', '-0.65', '-77100', '-77000', '-10', '7885011', '608892', '+77600', '+77800', '-76600', '5', '-900111', '-70010792700', '-89.75', '0.13', '201', '61.12', '4596733', '2', '0', '-89.69', '000000', '000000', '11814', '090003', '100015', '133453', '4817983', '2944657', '-37.93', '30342', '31741', '-770', '-10', ' 0', '-10', '30800', '24640', '77221', '410']}} {'arguments': [{'string_value': '005930'}, {'string_value': '주식체결'}, {'string_value': '142947\t-77000\t-500\t-0.65\t-77100\t-77000\t' '-1\t7885012\t608892\t+77600\t+77800\t-76600\t' '5\t-900110\t-70010715700\t-89.75\t0.13\t201\t' '61.12\t4596733\t2\t0\t-89.69\t000000\t000000\t' '11814\t090003\t100015\t133453\t4817984\t' '2944657\t-37.93\t30343\t31741\t-77\t-1\t 0\t' '-1\t30800\t24640\t77221\t410'}], 'name': 'OnReceiveRealData', 'single_data': {'names': ['체결시간', '현재가', '전일대비', '등락율', '매도호가', '매수호가', '거래량', '누적거래량', '누적거래대금', '시가', '고가', '저가', '전일대비기호', '거래량전일대비', '거래대금증감', '전일거래량대비율', '거래회전율', '거래비용', '체결강도', '시가총액', '장구분', 'KO접근도', '822', '567', '568', '851', '1890', '1891', '1892', '1030', '1031', '1032', '1071', '1072', '1313', '1315', '1316', '1314', '1497', '1498', '620', '732'], 'values': ['142947', '-77000', '-500', '-0.65', '-77100', '-77000', '-1', '7885012', '608892', '+77600', '+77800', '-76600', '5', '-900110', '-70010715700', '-89.75', '0.13', '201', '61.12', '4596733', '2', '0', '-89.69', '000000', '000000', '11814', '090003', '100015', '133453', '4817984', '2944657', '-37.93', '30343', '31741', '-77', '-1', ' 0', '-1', '30800', '24640', '77221', '410']}}
2022-01-18 14:29:53,341 [INFO] Stop listening realtime events... - <ipython-input-71-f9a2c4046337>:4
<_MultiThreadedRendezvous of RPC that terminated with: status = StatusCode.CANCELLED details = "Locally cancelled by application!" debug_error_string = "None" >