Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[버그]: 해외주식 실시간 체결통보 #44

Closed
1 of 2 tasks
krean2 opened this issue Sep 13, 2024 · 0 comments · Fixed by #53
Closed
1 of 2 tasks

[버그]: 해외주식 실시간 체결통보 #44

krean2 opened this issue Sep 13, 2024 · 0 comments · Fixed by #53
Assignees
Labels
버그 뭔가 작동하지 않습니다.

Comments

@krean2
Copy link

krean2 commented Sep 13, 2024

빠른 문제 해결을 위해 다음을 확인했나요?

  • PyKis Issues에서 검색했지만 유사한 버그를 찾지 못했습니다.

버그 설명

안녕하세요. 해외주식 실시간 조회 내용들을 테스트 하던 중
체결통보는 콜백 응답이 오지 않는 문제를 발견하였습니다.

아래 재현 코드 실행 시 실시간 체결가 조회에 대한 콜백은 정상적으로 출력되나
체결통보에 대해서는 콜백이 전혀 오지 않아 문의드립니다.

파이썬 버전의 영향일수 있을까요?

# 구독 완료 후 등록된 구독 목록
{KisWebsocketTR(id='HDFSCNT0', key='DNASGOOGL'), KisWebsocketTR(id='H0GSCNI9', key='my_HTS_ID'), KisWebsocketTR(id='HDFSCNT0', key='DNYST'), KisWebsocketTR(id='H0STCNI9', key='my_HTS_ID')}

# 실시간 체결가 조회에 대한 콜백 response
KisForeignRealtimePrice(market='NYSE', symbol='T', time='2024-09-13T15:20:01-04:00', price=21.595, change=0.005, volume=11647275, amount=251538634)
KisForeignRealtimePrice(market='NASDAQ', symbol='GOOGL', time='2024-09-13T15:20:02-04:00', price=157.615, change=2.925, volume=12402644, amount=1946818878)
KisForeignRealtimePrice(market='NYSE', symbol='T', time='2024-09-13T15:20:02-04:00', price=21.595, change=0.005, volume=11647375, amount=251540793)
KisForeignRealtimePrice(market='NASDAQ', symbol='GOOGL', time='2024-09-13T15:20:02-04:00', price=157.6101, change=2.9201, volume=12403644, amount=1946976489)

종속성 버전 문제 진단

Version: PyKis/2.0.3
Python: CPython 3.10.14
System: Windows 10.0.22631 [AMD64]

cryptography 43.0.1
requests 2.32.3
websocket-client 1.8.0
colorlog 6.8.2

재현 방법

import time, yaml
from pykis import PyKis
from pykis import KisRealtimePrice, KisSubscriptionEventArgs, KisWebsocketClient, KisRealtimeExecution

with open('config.yaml', encoding='UTF-8') as f:
    _cfg = yaml.load(f, Loader=yaml.FullLoader)

KIS = PyKis(
            id=_cfg["PYKIS_HTS_ID"],
            account=_cfg["PYKIS_VIRTUAL_ACCOUNT_NUMBER"],
            appkey=_cfg["PYKIS_APPKEY"],
            secretkey=_cfg["PYKIS_SECRETKEY"],
            virtual_id=_cfg["PYKIS_VIRTUAL_HTS_ID"],
            virtual_appkey=_cfg["PYKIS_VIRTUAL_APPKEY"],
            virtual_secretkey=_cfg["PYKIS_VIRTUAL_SECRETKEY"],
            use_websocket=True,
            keep_token=True
        )

def add_realtime_event():
    account = KIS.account()
    balance = account.balance()
    
    # 실시간 체결 통보
    account = KIS.account()
    account.on("execution", on_execution).suppress()
    time.sleep(1)

    # 실시간 체결가 조회
    stock_list = balance.stocks
    for s in stock_list:
        if s.market != 'KRX':
            KIS.stock(s.symbol).on("price", on_price).suppress()
            time.sleep(1)

    print(KIS.websocket.subscriptions)  # 현재 구독중인 이벤트 목록(정상으로 확인)

def on_price( sender: KisWebsocketClient, e: KisSubscriptionEventArgs[KisRealtimePrice]):
    ''' 실시간 체결가 조회 callback 함수 '''
    print(e.response)

def on_execution( sender: KisWebsocketClient, e: KisSubscriptionEventArgs[KisRealtimeExecution]):
    ''' 실시간 체결결과 조회 callback 함수 '''
    print(e.response)

def main():
    _symbol = 'T'
    add_realtime_event()
    KIS.stock(_symbol).buy(qty=1)   # 1주 구매

    while True:
        pass

if __name__ =='__main__':
    main()

추가 정보

No response

PR를 통해 라이브러리에 기여하고 싶으신가요?

  • 네, PR을 제출하여 도움을 주고 싶습니다!
@krean2 krean2 added the 버그 뭔가 작동하지 않습니다. label Sep 13, 2024
@Soju06 Soju06 self-assigned this Sep 30, 2024
@Soju06 Soju06 linked a pull request Nov 6, 2024 that will close this issue
@Soju06 Soju06 closed this as completed in #53 Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
버그 뭔가 작동하지 않습니다.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants