├── README.md
├── images
├── aladin.png
├── bandi.png
├── banner_2.png
├── bookconcert.png
├── interpark.png
├── kyobo.png
└── yes24.png
├── license.txt
├── 교재학습코드_1쇄2쇄
├── chapter02
│ ├── basic_v1.py
│ ├── basic_v1_problem.py
│ ├── basic_v2.py
│ ├── basic_v2_problem.py
│ ├── basic_v3.py
│ ├── basic_v3_problem.py
│ ├── basic_v4.py
│ └── basic_v4_problem.py
├── chapter06
│ └── dict.py
├── condition_sample
│ ├── __init__.py
│ ├── config
│ │ ├── errorCode.py
│ │ ├── kiwoomType.py
│ │ ├── log_class.py
│ │ ├── logging.conf
│ │ └── slack.py
│ ├── kiwoom
│ │ └── kiwoom.py
│ ├── kiwoomStart.bat
│ └── log
│ │ └── 2019-11-27.log
└── example
│ ├── 2.49___init__.py
│ ├── 3.1___init__.py
│ ├── 8.7_kiwoomStart.bat
│ ├── __init__.py
│ ├── config
│ ├── 4.3_errorCode.py
│ ├── 7.4_kiwoomType.py
│ ├── 8.1_log_class.py
│ ├── 8.2_logging.conf
│ ├── 8.5_slack.py
│ ├── errorCode.py
│ ├── kiwoomType.py
│ ├── log_class.py
│ ├── logging.conf
│ └── slack.py
│ ├── kiwoom
│ ├── 2.50_kiwoom.py
│ ├── 3.2_kiwoom.py
│ ├── 3.38_kiwoom.py
│ ├── 4.10_kiwoom.py
│ ├── 4.11_kiwoom.py
│ ├── 4.12_kiwoom.py
│ ├── 4.13_kiwoom.py
│ ├── 4.14_kiwoom.py
│ ├── 4.15_kiwoom.py
│ ├── 4.16_kiwoom.py
│ ├── 4.17_kiwoom.py
│ ├── 4.18_kiwoom.py
│ ├── 4.19_kiwoom.py
│ ├── 4.1_kiwoom.py
│ ├── 4.20_kiwoom.py
│ ├── 4.21_kiwoom.py
│ ├── 4.22_kiwoom.py
│ ├── 4.23_kiwoom.py
│ ├── 4.24_kiwoom.py
│ ├── 4.25_kiwoom.py
│ ├── 4.26_kiwoom.py
│ ├── 4.27_kiwoom.py
│ ├── 4.28_kiwoom.py
│ ├── 4.29_kiwoom.py
│ ├── 4.2_kiwoom.py
│ ├── 4.30_kiwoom.py
│ ├── 4.31_kiwoom.py
│ ├── 4.32_kiwoom.py
│ ├── 4.33_kiwoom.py
│ ├── 4.34_kiwoom.py
│ ├── 4.35_kiwoom.py
│ ├── 4.36_kiwoom.py
│ ├── 4.37_kiwoom.py
│ ├── 4.38_kiwoom.py
│ ├── 4.4_kiwoom.py
│ ├── 4.5_kiwoom.py
│ ├── 4.6_kiwoom.py
│ ├── 4.7_kiwoom.py
│ ├── 4.8_kiwoom.py
│ ├── 4.9_kiwoom.py
│ ├── 5.10_kiwoom.py
│ ├── 5.11_kiwoom.py
│ ├── 5.12_kiwoom.py
│ ├── 5.13_kiwoom.py
│ ├── 5.14_kiwoom.py
│ ├── 5.15_kiwoom.py
│ ├── 5.1_kiwoom.py
│ ├── 5.2_kiwoom.py
│ ├── 5.3_kiwoom.py
│ ├── 5.4_kiwoom.py
│ ├── 5.5_kiwoom.py
│ ├── 5.6_kiwoom.py
│ ├── 5.7_kiwoom.py
│ ├── 5.8_kiwoom.py
│ ├── 5.9_kiwoom.py
│ ├── 6.1_kiwoom.py
│ ├── 6.2_kiwoom.py
│ ├── 6.3_kiwoom.py
│ ├── 6.6_kiwoom.py
│ ├── 6.7_kiwoom.py
│ ├── 6.8_kiwoom.py
│ ├── 7.10_kiwoom.py
│ ├── 7.11_kiwoom.py
│ ├── 7.12_kiwoom.py
│ ├── 7.13_kiwoom.py
│ ├── 7.14_kiwoom.py
│ ├── 7.15_kiwoom.py
│ ├── 7.16_kiwoom.py
│ ├── 7.17_kiwoom.py
│ ├── 7.18_kiwoom.py
│ ├── 7.19_kiwoom.py
│ ├── 7.1_kiwoom.py
│ ├── 7.20_kiwoom.py
│ ├── 7.21_kiwoom.py
│ ├── 7.22_kiwoom.py
│ ├── 7.23_kiwoom.py
│ ├── 7.24_kiwoom.py
│ ├── 7.25_kiwoom.py
│ ├── 7.26_kiwoom.py
│ ├── 7.27_kiwoom.py
│ ├── 7.28_kiwoom.py
│ ├── 7.29_kiwoom.py
│ ├── 7.2_kiwoom.py
│ ├── 7.30_kiwoom.py
│ ├── 7.31_kiwoom.py
│ ├── 7.32_kiwoom.py
│ ├── 7.33_kiwoom.py
│ ├── 7.34_kiwoom.py
│ ├── 7.35_kiwoom.py
│ ├── 7.36_kiwoom.py
│ ├── 7.37_kiwoom.py
│ ├── 7.3_kiwoom.py
│ ├── 7.5_kiwoom.py
│ ├── 7.6_kiwoom.py
│ ├── 7.7_kiwoom.py
│ ├── 7.8_kiwoom.py
│ ├── 7.9_kiwoom.py
│ ├── 8.4_kiwoom.py
│ ├── 8.6_kiwoom.py
│ └── kiwoom.py
│ ├── kiwoomStart.bat
│ └── log
│ └── 2020-01-21.log
├── 교재학습코드_3쇄
├── chapter02
│ ├── basic_v1.py
│ ├── basic_v1_problem.py
│ ├── basic_v2.py
│ ├── basic_v2_problem.py
│ ├── basic_v3.py
│ ├── basic_v3_problem.py
│ ├── basic_v4.py
│ └── basic_v4_problem.py
├── chapter06
│ └── dict.py
├── condition_sample
│ ├── __init__.py
│ ├── config
│ │ ├── errorCode.py
│ │ ├── kiwoomType.py
│ │ ├── log_class.py
│ │ └── slack.py
│ ├── kiwoom
│ │ └── kiwoom.py
│ ├── kiwoomStart.bat
│ └── log
│ │ └── 2019-11-27.log
└── example
│ ├── 2.49___init__.py
│ ├── 3.1___init__.py
│ ├── 8.5_kiwoomStart.bat
│ ├── __init__.py
│ ├── config
│ ├── 4.3_errorCode.py
│ ├── 7.4_kiwoomType.py
│ ├── 8.1_log_class.py
│ ├── 8.3_slack.py
│ ├── errorCode.py
│ ├── kiwoomType.py
│ ├── log_class.py
│ └── slack.py
│ ├── kiwoom
│ ├── 2.50_kiwoom.py
│ ├── 3.2_kiwoom.py
│ ├── 3.38_kiwoom.py
│ ├── 4.10_kiwoom.py
│ ├── 4.11_kiwoom.py
│ ├── 4.12_kiwoom.py
│ ├── 4.13_kiwoom.py
│ ├── 4.14_kiwoom.py
│ ├── 4.15_kiwoom.py
│ ├── 4.16_kiwoom.py
│ ├── 4.17_kiwoom.py
│ ├── 4.18_kiwoom.py
│ ├── 4.19_kiwoom.py
│ ├── 4.1_kiwoom.py
│ ├── 4.20_kiwoom.py
│ ├── 4.21_kiwoom.py
│ ├── 4.22_kiwoom.py
│ ├── 4.23_kiwoom.py
│ ├── 4.24_kiwoom.py
│ ├── 4.25_kiwoom.py
│ ├── 4.26_kiwoom.py
│ ├── 4.27_kiwoom.py
│ ├── 4.28_kiwoom.py
│ ├── 4.29_kiwoom.py
│ ├── 4.2_kiwoom.py
│ ├── 4.30_kiwoom.py
│ ├── 4.31_kiwoom.py
│ ├── 4.32_kiwoom.py
│ ├── 4.33_kiwoom.py
│ ├── 4.34_kiwoom.py
│ ├── 4.35_kiwoom.py
│ ├── 4.36_kiwoom.py
│ ├── 4.37_kiwoom.py
│ ├── 4.38_kiwoom.py
│ ├── 4.4_kiwoom.py
│ ├── 4.5_kiwoom.py
│ ├── 4.6_kiwoom.py
│ ├── 4.7_kiwoom.py
│ ├── 4.8_kiwoom.py
│ ├── 4.9_kiwoom.py
│ ├── 5.10_kiwoom.py
│ ├── 5.11_kiwoom.py
│ ├── 5.12_kiwoom.py
│ ├── 5.13_kiwoom.py
│ ├── 5.14_kiwoom.py
│ ├── 5.15_kiwoom.py
│ ├── 5.1_kiwoom.py
│ ├── 5.2_kiwoom.py
│ ├── 5.3_kiwoom.py
│ ├── 5.4_kiwoom.py
│ ├── 5.5_kiwoom.py
│ ├── 5.6_kiwoom.py
│ ├── 5.7_kiwoom.py
│ ├── 5.8_kiwoom.py
│ ├── 5.9_kiwoom.py
│ ├── 6.1_kiwoom.py
│ ├── 6.2_kiwoom.py
│ ├── 6.3_kiwoom.py
│ ├── 6.6_kiwoom.py
│ ├── 6.7_kiwoom.py
│ ├── 6.8_kiwoom.py
│ ├── 7.10_kiwoom.py
│ ├── 7.11_kiwoom.py
│ ├── 7.12_kiwoom.py
│ ├── 7.13_kiwoom.py
│ ├── 7.14_kiwoom.py
│ ├── 7.15_kiwoom.py
│ ├── 7.16_kiwoom.py
│ ├── 7.17_kiwoom.py
│ ├── 7.18_kiwoom.py
│ ├── 7.19_kiwoom.py
│ ├── 7.1_kiwoom.py
│ ├── 7.20_kiwoom.py
│ ├── 7.21_kiwoom.py
│ ├── 7.22_kiwoom.py
│ ├── 7.23_kiwoom.py
│ ├── 7.24_kiwoom.py
│ ├── 7.25_kiwoom.py
│ ├── 7.26_kiwoom.py
│ ├── 7.27_kiwoom.py
│ ├── 7.28_kiwoom.py
│ ├── 7.29_kiwoom.py
│ ├── 7.2_kiwoom.py
│ ├── 7.30_kiwoom.py
│ ├── 7.31_kiwoom.py
│ ├── 7.32_kiwoom.py
│ ├── 7.33_kiwoom.py
│ ├── 7.34_kiwoom.py
│ ├── 7.35_kiwoom.py
│ ├── 7.36_kiwoom.py
│ ├── 7.37_kiwoom.py
│ ├── 7.3_kiwoom.py
│ ├── 7.5_kiwoom.py
│ ├── 7.6_kiwoom.py
│ ├── 7.7_kiwoom.py
│ ├── 7.8_kiwoom.py
│ ├── 7.9_kiwoom.py
│ ├── 8.2_kiwoom.py
│ ├── 8.4_kiwoom.py
│ └── kiwoom.py
│ ├── kiwoomStart.bat
│ └── log
│ └── 2020-01-21.log
├── 교재학습코드_4쇄
├── chapter02
│ ├── basic_v1.py
│ ├── basic_v1_problem.py
│ ├── basic_v2.py
│ ├── basic_v2_problem.py
│ ├── basic_v3.py
│ ├── basic_v3_problem.py
│ ├── basic_v4.py
│ └── basic_v4_problem.py
├── chapter06
│ └── dict.py
├── condition_sample
│ ├── __init__.py
│ ├── config
│ │ ├── errorCode.py
│ │ ├── kiwoomType.py
│ │ ├── log_class.py
│ │ └── slack.py
│ ├── kiwoom
│ │ └── kiwoom.py
│ ├── kiwoomStart.bat
│ └── log
│ │ └── 2019-11-27.log
└── example
│ ├── 2.49___init__.py
│ ├── 3.1___init__.py
│ ├── 8.5_kiwoomStart.bat
│ ├── __init__.py
│ ├── config
│ ├── 4.3_errorCode.py
│ ├── 7.4_kiwoomType.py
│ ├── 8.1_log_class.py
│ ├── 8.3_slack.py
│ ├── errorCode.py
│ ├── kiwoomType.py
│ ├── log_class.py
│ └── slack.py
│ ├── kiwoom
│ ├── 2.50_kiwoom.py
│ ├── 3.2_kiwoom.py
│ ├── 3.38_kiwoom.py
│ ├── 4.10_kiwoom.py
│ ├── 4.11_kiwoom.py
│ ├── 4.12_kiwoom.py
│ ├── 4.13_kiwoom.py
│ ├── 4.14_kiwoom.py
│ ├── 4.15_kiwoom.py
│ ├── 4.16_kiwoom.py
│ ├── 4.17_kiwoom.py
│ ├── 4.18_kiwoom.py
│ ├── 4.19_kiwoom.py
│ ├── 4.1_kiwoom.py
│ ├── 4.20_kiwoom.py
│ ├── 4.21_kiwoom.py
│ ├── 4.22_kiwoom.py
│ ├── 4.23_kiwoom.py
│ ├── 4.24_kiwoom.py
│ ├── 4.25_kiwoom.py
│ ├── 4.26_kiwoom.py
│ ├── 4.27_kiwoom.py
│ ├── 4.28_kiwoom.py
│ ├── 4.29_kiwoom.py
│ ├── 4.2_kiwoom.py
│ ├── 4.30_kiwoom.py
│ ├── 4.31_kiwoom.py
│ ├── 4.32_kiwoom.py
│ ├── 4.33_kiwoom.py
│ ├── 4.34_kiwoom.py
│ ├── 4.35_kiwoom.py
│ ├── 4.36_kiwoom.py
│ ├── 4.37_kiwoom.py
│ ├── 4.38_kiwoom.py
│ ├── 4.4_kiwoom.py
│ ├── 4.5_kiwoom.py
│ ├── 4.6_kiwoom.py
│ ├── 4.7_kiwoom.py
│ ├── 4.8_kiwoom.py
│ ├── 4.9_kiwoom.py
│ ├── 5.10_kiwoom.py
│ ├── 5.11_kiwoom.py
│ ├── 5.12_kiwoom.py
│ ├── 5.13_kiwoom.py
│ ├── 5.14_kiwoom.py
│ ├── 5.15_kiwoom.py
│ ├── 5.1_kiwoom.py
│ ├── 5.2_kiwoom.py
│ ├── 5.3_kiwoom.py
│ ├── 5.4_kiwoom.py
│ ├── 5.5_kiwoom.py
│ ├── 5.6_kiwoom.py
│ ├── 5.7_kiwoom.py
│ ├── 5.8_kiwoom.py
│ ├── 5.9_kiwoom.py
│ ├── 6.1_kiwoom.py
│ ├── 6.2_kiwoom.py
│ ├── 6.3_kiwoom.py
│ ├── 6.6_kiwoom.py
│ ├── 6.7_kiwoom.py
│ ├── 6.8_kiwoom.py
│ ├── 7.10_kiwoom.py
│ ├── 7.11_kiwoom.py
│ ├── 7.12_kiwoom.py
│ ├── 7.13_kiwoom.py
│ ├── 7.14_kiwoom.py
│ ├── 7.15_kiwoom.py
│ ├── 7.16_kiwoom.py
│ ├── 7.17_kiwoom.py
│ ├── 7.18_kiwoom.py
│ ├── 7.19_kiwoom.py
│ ├── 7.1_kiwoom.py
│ ├── 7.20_kiwoom.py
│ ├── 7.21_kiwoom.py
│ ├── 7.22_kiwoom.py
│ ├── 7.23_kiwoom.py
│ ├── 7.24_kiwoom.py
│ ├── 7.25_kiwoom.py
│ ├── 7.26_kiwoom.py
│ ├── 7.27_kiwoom.py
│ ├── 7.28_kiwoom.py
│ ├── 7.29_kiwoom.py
│ ├── 7.2_kiwoom.py
│ ├── 7.30_kiwoom.py
│ ├── 7.31_kiwoom.py
│ ├── 7.32_kiwoom.py
│ ├── 7.33_kiwoom.py
│ ├── 7.34_kiwoom.py
│ ├── 7.35_kiwoom.py
│ ├── 7.36_kiwoom.py
│ ├── 7.37_kiwoom.py
│ ├── 7.3_kiwoom.py
│ ├── 7.5_kiwoom.py
│ ├── 7.6_kiwoom.py
│ ├── 7.7_kiwoom.py
│ ├── 7.8_kiwoom.py
│ ├── 7.9_kiwoom.py
│ ├── 8.2_kiwoom.py
│ ├── 8.4_kiwoom.py
│ └── kiwoom.py
│ ├── kiwoomStart.bat
│ └── log
│ └── 2020-01-21.log
├── 사용하지않는 코드
├── 완성된코드
│ └── week1
│ │ ├── __init__.py
│ │ ├── config
│ │ ├── errorCode.py
│ │ ├── kiwoomType.py
│ │ ├── log_class.py
│ │ └── slack.py
│ │ ├── files
│ │ └── condition_stock.txt
│ │ ├── kiwoom
│ │ └── kiwoom.py
│ │ ├── kiwoomStart.bat
│ │ ├── license.txt
│ │ └── log
│ │ ├── 2020-01-21.log
│ │ └── 2020-12-20.log
├── 조건검색코드
│ └── condition_sample
│ │ ├── __init__.py
│ │ ├── config
│ │ ├── errorCode.py
│ │ ├── kiwoomType.py
│ │ ├── log_class.py
│ │ └── logging.conf
│ │ ├── files
│ │ └── condition_stock.txt
│ │ ├── kiwoom
│ │ └── kiwoom.py
│ │ ├── kiwoomStart.bat
│ │ └── log
│ │ └── 2019-11-27.log
└── 파이썬기초
│ └── week1
│ ├── basic_1week
│ ├── basic_v1.py
│ └── basic_v1_problem.py
│ ├── basic_2week
│ ├── basic_v2.py
│ └── basic_v2_problem.py
│ ├── basic_3week
│ ├── basic_v3.py
│ └── basic_v3_problem.py
│ └── basic_4week
│ ├── basic_v4.py
│ └── basic_v4_problem.py
└── 키움API 주문접수_확인_체결 참고자료
├── 매도후 매도정정후 매도취소.txt
├── 매도후 매도정정후 체결완료.txt
├── 매도후 매도취소.txt
├── 매수후 매수정정.txt
├── 매수후 매수정정후 매수취소.txt
└── 매수후 매수취소.txt
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
PROGRAM GARDEN
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | 국내/해외 주식 시스템, 금융AI, 금융서버 그리고 다양한 IT교육 커뮤니티
채널 가입하고 초보에서 전문가 수준의 금융IT 코딩 배우기
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | ## 📚 책 정보
24 |
25 | ### 교재 출판 1쇄,2쇄, 3쇄, 4쇄본 폴더로 나눔
26 | >인쇄 버전에 맞는 예제코드를 사용해 주세요.
27 |
28 |
29 |
30 | ### 8장 수정사항 (교재출판 1쇄, 2쇄 버전용)
31 | >2020년 5월6일을 시점으로 슬랙에서 토큰 정책을 변경했습니다.
32 |
33 | 기존 방식은 다이렉트로 토큰을 생성하는 거였지만 이제는 불가능합니다. 이전에 생성한 사용자에게는 영향이 없지만, 5월6일 이후로 슬랙 토큰을 생성하려는 분들은 기존 방식으로 불가능 합니다.
34 |
그래서 초판 교재로 공부중이신 분들은 **교재 281페이지 ~ 285페이지**까지의 내용을 아래 링크에 업데이트된 내용으로 학습하면 됩니다.
35 |
36 | 슬랙 토큰 받는 새로운 방법 ▶ [https://cafe.naver.com/programgarden/102][https://cafe.naver.com/programgarden/102]
37 |
38 | 3쇄 버전을 이용중이면 아래 링크로 학습하면 됩니다.
39 |
40 | 슬랙 토큰 받는 새로운 방법 ▶ https://cafe.naver.com/programgarden/1664
41 |
42 |
43 |
44 | ### 교재 정보
45 | [](http://wikibook.co.kr/pystock/)
46 |
47 | >무료 강의 영상에 없는 내용이 서적에 많이 포함되어 있습니다.
48 | 대표적으로 메세지 받는 방법과 HTS의 조건검색식을 파이썬과 연동하는 방법
49 | 그리고 데이터 관리하는 커스텀 로그 구축입니다.
50 | 그 외에도 폭 넓은 내용들 책에서 볼 수 있고 eBook으로도 제공하고 있습니다.
51 |
52 | [](http://aladin.kr/p/7NIXc)
53 |
54 | [](http://inpk.kr/r5L3)
55 |
56 | [](http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791158392024&orderClick=LAG&Kc=)
57 |
58 | [](http://www.yes24.com/Product/Goods/89999945)
59 |
60 | [](http://www.bandinlunis.com/front/product/detailProduct.do?prodId=4332846)
61 |
62 |
--------------------------------------------------------------------------------
/images/aladin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/programgarden/book/0b49f39169a4984c7440a3145607383031c904d8/images/aladin.png
--------------------------------------------------------------------------------
/images/bandi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/programgarden/book/0b49f39169a4984c7440a3145607383031c904d8/images/bandi.png
--------------------------------------------------------------------------------
/images/banner_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/programgarden/book/0b49f39169a4984c7440a3145607383031c904d8/images/banner_2.png
--------------------------------------------------------------------------------
/images/bookconcert.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/programgarden/book/0b49f39169a4984c7440a3145607383031c904d8/images/bookconcert.png
--------------------------------------------------------------------------------
/images/interpark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/programgarden/book/0b49f39169a4984c7440a3145607383031c904d8/images/interpark.png
--------------------------------------------------------------------------------
/images/kyobo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/programgarden/book/0b49f39169a4984c7440a3145607383031c904d8/images/kyobo.png
--------------------------------------------------------------------------------
/images/yes24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/programgarden/book/0b49f39169a4984c7440a3145607383031c904d8/images/yes24.png
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Library name: programgarden_coding
2 | Copyright (C) 2019-05-01, Yong-Joon Jang
3 | Contact: stockisgame@gmail.com
4 |
5 | 본 교육용 코드, 영상자료, 이미지자료는 Free software license 기준을 따르지 않습니다.
6 | 그러므로 무단배포 및 상업적 이용을 금지합니다.
7 | 그리고 수정배포 및 상업적 이용으로는 저작권자의 허가가 필요합니다.
8 |
9 | 라이브러리를 제공받으면 위 라이선스에 동의됩니다.
10 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v1.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.1 ==========")
2 | print("Hello world")
3 |
4 |
5 | print("\n\n========== 예제 2.2 ==========")
6 | print("Hello world")
7 | #Hello world
8 |
9 |
10 | print("\n\n========== 예제 2.3 ==========")
11 | print("Hello world" + " Thank you")
12 | #Hello world Thank you
13 |
14 |
15 | print("\n\n========== 예제 2.4 ==========")
16 | print(900629)
17 | #900629
18 |
19 |
20 | print("\n\n========== 예제 2.5 ==========")
21 | print("%s 입니다." % "홍길동")
22 | #홍길동 입니다.
23 | print("%s 입니다." % "이순신")
24 | #이순신 입니다.
25 | print("%s원 입니다." % 5000)
26 | #5000원 입니다.
27 |
28 |
29 | print("\n\n========== 예제 2.6 ==========")
30 | print("이름은 %s 이고 %s에 삽니다." % ("홍길동", "서울"))
31 | #이름은 홍길동 이고 서울에 삽니다.
32 |
33 |
34 | print("\n\n========== 예제 2.7 ==========")
35 | #int 변수, 최대값 : 9223372036854775807
36 | stock_price = 3900
37 | print(stock_price)
38 | stock_price = 4500
39 | print(stock_price)
40 | stock_price_type = type(stock_price) #
41 | print(stock_price_type)
42 |
43 |
44 | print("\n\n========== 예제 2.8 ==========")
45 | #float 변수
46 | stock_percent = 3.8 # 3.8
47 | print(stock_percent)
48 | stock_percent_type = type(stock_percent) #
49 | print(stock_percent_type)
50 |
51 |
52 | print("\n\n========== 예제 2.9 ==========")
53 | #string 변수
54 | stock_name = "홀딩스" # 홀딩스
55 | print(stock_name)
56 | stock_name_type = type(stock_name) #
57 | print(stock_name_type)
58 | stock_name = "3900" # 3900
59 | print(stock_name)
60 | stock_name_type = type(stock_name) #
61 | print(stock_name_type)
62 |
63 |
64 | print("\n\n========== 예제 2.10 ==========")
65 | #bool 변수
66 | stock_buy = False
67 | print(stock_buy)
68 | stock_buy_type = type(stock_buy) #
69 | print(stock_buy_type)
70 |
71 |
72 | print("\n\n========== 예제 2.11 ==========")
73 | stock_price = 2000
74 | stock_price2 = 2500
75 | stock_result = stock_price + stock_price2
76 | print(stock_result) # 4500
77 |
78 |
79 | print("\n\n========== 예제 2.12 ==========")
80 | stock_price = 2000
81 | stock_price2 = 1000
82 | stock_result= stock_price - stock_price2
83 | print(stock_result) # 1000
84 |
85 |
86 | print("\n\n========== 예제 2.13 ==========")
87 | stock_price = 1000
88 | stock_price2 = 1200
89 | stock_result = stock_price * stock_price2
90 | print(stock_result) # 1200000
91 |
92 |
93 | print("\n\n========== 예제 2.14 ==========")
94 | stock_price = 2000
95 | stock_price2 = 2200
96 | stock_result = stock_price / stock_price2
97 | print(stock_result) # 0.9090909090909091
98 | stock_result = stock_price // stock_price2
99 | print(stock_result) # 0
100 |
101 |
102 | print("\n\n========== 예제 2.15 ==========")
103 | stock_price = 1000
104 | stock_price2 = 900
105 | stock_result = stock_price % stock_price2
106 | print(stock_result) # 100
107 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v1_problem.py:
--------------------------------------------------------------------------------
1 | print("========== 문제 1 ==========")
2 | stock_name = "키움증권"
3 | stock_price = 3900
4 | stock_percent = 3.8
5 | print("주식이름 : %s, 가격 : %s원, 등락율 : %s" % (stock_name, stock_price, stock_percent))
6 |
7 |
8 | print("\n\n========== 문제 2 ==========")
9 | print("등락율 : %s %%" % stock_percent)
10 | print("등락율 : %s %s" % (stock_percent, "%"))
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v2.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.16 ==========")
2 | stock_name = "키움증권"
3 | if stock_name == "키움증권":
4 | print("통과!")
5 |
6 |
7 | print("\n\n========== 예제 2.17 ==========")
8 | stock_price = 3000
9 | if stock_price > 3000:
10 | print("통과!1")
11 | elif stock_price >= 3000:
12 | print("통과!2")
13 | elif stock_price <= 3000:
14 | print("통과!3")
15 | else:
16 | print("조건에 해당하는 게 없음!")
17 |
18 |
19 | print("\n\n========== 예제 2.18 ==========")
20 | stock_price = 3000
21 | if stock_price < 3000 or stock_price >= 3000:
22 | print("둘 중 아무거나 맞으면 출력")
23 |
24 | print("\n\n========== 예제 2.19 ==========")
25 | stock_price = 3000
26 | if stock_price > 2000 or stock_price < 2500:
27 | print("2000~2500 사이")
28 | elif stock_price >= 2500 and stock_price <= 3000:
29 | print("2500~3000 사이")
30 |
31 | stock_price = 3000
32 | if stock_price > 2000 and stock_price <= 3000:
33 | print("2001~3000 사이")
34 | elif stock_price > 3000 and stock_price <= 4000:
35 | print("3001~4000 사이")
36 |
37 |
38 | print("\n\n========== 예제 2.20 ==========")
39 | for i in range(5, 100):
40 | print(i)
41 |
42 |
43 | print("\n\n========== 예제 2.21 ==========")
44 | for i in range(5, 100):
45 | print(i)
46 |
47 | if i == 50:
48 | break
49 |
50 | print("\n\n========== 예제 2.22 ==========")
51 | for i in range(0, 10):
52 | for k in range(0, 5):
53 | print("for 문 안에 for 문 %s" % k)
54 |
55 |
56 | print("\n\n========== 예제 2.23 ==========")
57 | stock_buy = True
58 | count = 0
59 | while stock_buy:
60 | count = count + 1
61 |
62 | if count == 10:
63 | break
64 |
65 | print(count)
66 |
67 |
68 | print("\n\n========== 예제 2.24 ==========")
69 | stock_buy = True
70 | count = 0
71 | while stock_buy:
72 | count = count + 1
73 |
74 | if count == 10:
75 | # break
76 | stock_buy = False
77 |
78 | print(count)
79 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v2_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 3 ==========")
2 | kakao_price = 1000
3 | kiwoom_price = 500
4 |
5 | for i in range(0, 3):
6 | kakao_price += 500
7 | kiwoom_price += 1000
8 |
9 | if kakao_price > kiwoom_price:
10 | print("카카오가 더 높다")
11 | elif kakao_price < kiwoom_price:
12 | print("키움이 더 높다")
13 | elif kakao_price == kiwoom_price:
14 | print("키움과 카카오가 같다")
15 |
16 |
17 | print("\n\n========== 문제 4 ==========")
18 | for i in range(1, 10):
19 | for j in range(1, 10):
20 | result = i * j
21 | print("%s x %s = %s" % (i, j, result))
22 |
23 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v3.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.25 ==========")
3 | a_list = ("키움", "카카오", "대신")
4 | for val in a_list:
5 | print(val)
6 |
7 |
8 | print("\n\n========== 예제 2.26 ==========")
9 | a_list = ["키움", "카카오", "네이버"]
10 | for val in a_list:
11 | print(val)
12 |
13 |
14 | print("\n\n========== 예제 2.27 ==========")
15 | a_list = ["키움", "카카오", "네이버"]
16 | a_list.append("대신증권")
17 | for val in a_list:
18 | print(val)
19 |
20 |
21 | print("\n\n========== 예제 2.28 ==========")
22 | print(a_list[0])
23 |
24 |
25 | print("\n\n========== 예제 2.29 ==========")
26 | a_list = ["키움", "카카오", "네이버"] #list
27 | print(a_list)
28 | a_list[2] = "다음" #수정하기
29 | print(a_list)
30 | del a_list[1] #삭제하기
31 | print(a_list)
32 |
33 |
34 | print("\n\n========== 예제 2.30 ==========")
35 | a_list = ["키움", "카카오", "네이버"]
36 | for idx, val in enumerate(a_list):
37 | print("인덱스: %s, 값: %s" % (idx, val))
38 |
39 |
40 | print("\n\n========== 예제 2.31 ==========")
41 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
42 | print(a_dict.get("키움증권")) # 1300
43 | print(a_dict['키움증권']) # 1300
44 |
45 |
46 | print("\n\n========== 예제 2.32 ==========")
47 | for key in a_dict.keys():
48 | print(a_dict.get(key))
49 |
50 |
51 | print("\n\n========== 예제 2.33 ==========")
52 | for key, value in a_dict.items(): #key와 value 값 모두 가져옴
53 | print("키값 : %s , value값 : %s" % (key, value))
54 |
55 |
56 | print("\n\n========== 예제 2.34 ==========")
57 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
58 | a_dict["다음증권"] = 2500
59 | print(a_dict)
60 |
61 |
62 | print("\n\n========== 예제 2.35 ==========")
63 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
64 | a_dict.update({"다음증권":2500})
65 | print(a_dict)
66 |
67 |
68 | print("\n\n========== 예제 2.36 ==========")
69 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
70 | a_dict["다음증권"] = 2500
71 | a_dict["애플"] = 152000
72 | a_dict["삼성"] = 221500
73 | a_dict["LG"] = 25800
74 | print(a_dict)
75 |
76 |
77 | print("\n\n========== 예제 2.37 ==========")
78 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
79 | a_dict.update({"다음증권":2000, "애플":152000, "삼성":221500, "LG":25800})
80 | print(a_dict)
81 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v3_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 5 ==========")
2 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
3 | a_plus = 0
4 | for val in a_dict.keys():
5 | a_plus = a_plus + a_dict[val] # a_plus += a_dict[val] 형태와 같다
6 | print("종목 : %s, 가격: %s " % (val, a_dict[val]))
7 | print("더한값 %s " % a_plus)
8 |
9 |
10 | print("\n\n========== 문제 6 ==========")
11 | a_dict = {"키움증권": 5000, "카카오": 3000, "네이버": 2000}
12 | my_account = 111000
13 | for val in a_dict.keys():
14 | if val == "키움증권":
15 | my_account = my_account - a_dict[val] * 5
16 | elif val == "카카오":
17 | my_account -= a_dict[val] * 2
18 | elif val == "네이버":
19 | my_account -= a_dict[val] * 5
20 |
21 | print("남은 금액 : %s " % my_account)
22 |
23 |
24 | print("\n\n========== 문제 7 ==========")
25 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
26 | ee_bool = True
27 | while ee_bool:
28 | a_dict['키움증권'] = a_dict['키움증권'] + 1000
29 |
30 | if a_dict['키움증권'] == 10000:
31 | a_dict.update({"이베스트증권" : 5000})
32 | break
33 |
34 | print(a_dict)
35 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v4.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.38 ==========")
3 | def english():
4 | print("영어과입니다.")
5 | english()
6 |
7 |
8 | print("\n\n========== 예제 2.39 ==========")
9 | def math(student_name):
10 | print(student_name)
11 | math("토마스")
12 |
13 |
14 | print("\n\n========== 예제 2.40 ==========")
15 | def academy(student_name1, student_name2, student_name3):
16 | print(student_name1)
17 | print(student_name2)
18 | print(student_name3)
19 |
20 | academy("토마스", "에디슨", "빌리")
21 |
22 |
23 | print("\n\n========== 예제 2.41 ==========")
24 | def english(help):
25 | help()
26 |
27 | def help():
28 | print("도와주러 왔습니다.")
29 |
30 | english(help)
31 |
32 |
33 | print("\n\n========== 예제 2.42 ==========")
34 | def math():
35 | name = "광수"
36 | return name
37 |
38 | who = math()
39 | print(who)
40 |
41 |
42 | print("\n\n========== 예제 2.43 ==========")
43 | def multi():
44 | return "a", "b"
45 |
46 | a, b = multi()
47 | result = multi()
48 | print(result)
49 |
50 |
51 | print("\n\n========== 예제 2.44 ==========")
52 | class B_school():
53 | def __init__(self):
54 | print("b대학교 초기화")
55 |
56 | B_school()
57 |
58 |
59 | print("\n\n========== 예제 2.45 ==========")
60 | class A_school():
61 | def __init__(self):
62 | print("초기화, 생성자")
63 | self.student1_name = None
64 | self.student2_name = None
65 |
66 | print(dir(self))
67 |
68 | A_school()
69 |
70 |
71 | print("\n\n========== 예제 2.46 ==========")
72 | class A_school():
73 | def __init__(self):
74 | print("초기화, 생성자")
75 | self.student1_name = None
76 |
77 | b = self.math()
78 | print("수학과 학생 %s" % b)
79 |
80 | def math(self):
81 | self.student1_name = "영수"
82 | name = self.student1_name
83 |
84 | return name
85 |
86 |
87 | print("\n\n========== 예제 2.47 ==========")
88 | class B_school():
89 | def __init__(self):
90 | print("b대학교 초기화")
91 |
92 | self.school_name = "b학교"
93 |
94 | class A_school():
95 | def __init__(self):
96 | print("초기화, 생성자")
97 | self.student1_name = None
98 |
99 | b = self.math()
100 | print("수학과 학생 %s" % b)
101 |
102 | b_school = B_school()
103 | print(b_school.school_name)
104 |
105 | def math(self):
106 | self.student1_name = "영수"
107 | name = self.student1_name
108 |
109 | return name
110 |
111 | A_school()
112 |
113 |
114 | print("\n\n========== 예제 2.48 ==========")
115 | class Parent():
116 | def __init__(self):
117 | print("부모입니다.")
118 |
119 | self.money = 50000000
120 |
121 | def home(self):
122 | return "부모의 집"
123 |
124 | class ChildA(Parent):
125 | def __init__(self):
126 | print("자식A")
127 |
128 | print("부모의 돈을 물려받을 수 없습니다.")
129 | print("%s을 물려받았습니다." % self.home())
130 |
131 | class ChildB(Parent):
132 | def __init__(self):
133 | super().__init__()
134 | print("자식B")
135 |
136 | print("부모의 돈 %s" % self.money)
137 | print("%s을 물려받았습니다." % self.home())
138 |
139 | ChildA()
140 | ChildB()
141 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter02/basic_v4_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 8 ==========")
2 | class Condition():
3 | def sell_filtering(self, my_dict):
4 | for key in my_dict.keys():
5 | if 5000 >= my_dict[key]:
6 | print("종목 %s, 가격 %s" % (key, my_dict[key]))
7 |
8 | class Kiwoom():
9 | def __init__(self):
10 | self.my_dict = {"네이버":6000, "애플":15000, "다음":3000, "넷플릭스":5000, "구글":100000, "삼성":3000, "LG":1000, "키움":500, "호랑":8000, "셀트리온":8500, "코난":6050, "컬링":1000, "하이원":3200}
11 |
12 | condition = Condition()
13 | condition.sell_filtering(self.my_dict)
14 |
15 | Kiwoom()
16 |
17 | print("\n\n========== 문제 9 ==========")
18 | class Condition():
19 | def sell_filtering(self, my_dict):
20 | for key in my_dict.keys():
21 | if key == "넷플릭스":
22 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
23 |
24 | elif key == "애플":
25 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
26 |
27 | elif key == "구글":
28 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
29 |
30 | return my_dict
31 |
32 | class Kiwoom():
33 | def __init__(self):
34 | self.my_dict = {'네이버':{'현재가':3000, '보유량':100}, '애플':{'현재가':10000, '보유량':200}, '다음':{'현재가':4000, '보유량':50}, '넷플릭스':{'현재가':7000, '보유량':200}, '구글':{'현재가':13000, '보유량':30}}
35 |
36 | condition = Condition()
37 | result = condition.sell_filtering(self.my_dict)
38 | print(result)
39 |
40 | Kiwoom()
41 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/chapter06/dict.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 예제 6.4 ==========")
2 | sample_dict = {"1":"테스트1", "2":"테스트2", "3":"테스트3"}
3 |
4 | a_test = sample_dict
5 | a_test["1"] = "변경하기"
6 |
7 | print("할당 %s" % a_test)
8 | print("원본 %s" % sample_dict)
9 |
10 |
11 | print("\n\n========== 예제 6.5 ==========")
12 | sample_dict = {"1":"테스트1", "2":"테스트2", "3":"테스트3"}
13 |
14 | a_test = sample_dict.copy()
15 | a_test["1"] = "변경하기"
16 |
17 | print("할당 %s" % a_test)
18 | print("원본 %s" % sample_dict)
19 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/condition_sample/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path.append("C:/Users/USER/PycharmProjects/week1/")
3 |
4 | from kiwoom.kiwoom import *
5 | from PyQt5.QtWidgets import *
6 |
7 | class Main():
8 | def __init__(self):
9 | print("Main() start")
10 |
11 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
12 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
13 | self.app.exec_() # 이벤트 루프 실행
14 |
15 | if __name__ == "__main__":
16 | Main()
17 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/condition_sample/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/condition_sample/config/kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/condition_sample/config/log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | from datetime import datetime
3 |
4 | class Logging():
5 | def __init__(self, config_path='config/logging.conf', log_path='log'):
6 | self.config_path = config_path
7 | self.log_path = log_path
8 |
9 | logging.config.fileConfig(self.config_path)
10 | self.logger = logging.getLogger('Kiwoom')
11 | self.kiwoom_log()
12 |
13 | #로그설정
14 | def kiwoom_log(self):
15 | fh = logging.FileHandler(self.log_path+'/{:%Y-%m-%d}.log'.format(datetime.now()), encoding="utf-8")
16 | formatter = logging.Formatter('[%(asctime)s] I %(filename)s | %(name)s-%(funcName)s-%(lineno)04d I %(levelname)-8s > %(message)s')
17 |
18 | fh.setFormatter(formatter)
19 | self.logger.addHandler(fh)
20 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/condition_sample/config/logging.conf:
--------------------------------------------------------------------------------
1 | [loggers]
2 | keys=root, Kiwoom
3 |
4 | [handlers]
5 | keys=consoleHandler
6 |
7 | [formatters]
8 | keys=consoleFormatter
9 |
10 | [logger_root]
11 | level=DEBUG
12 | handlers=consoleHandler
13 |
14 | [logger_Kiwoom]
15 | level=DEBUG
16 | handlers=consoleHandler
17 | qualname=Kiwoom
18 | propagate=0
19 |
20 | [handler_consoleHandler]
21 | class=StreamHandler
22 | level=DEBUG
23 | formatter=consoleFormatter
24 | args=(sys.stdout,)
25 |
26 | [formatter_consoleFormatter]
27 | format=%(asctime)s | %(levelname)-8s | %(filename)s-%(funcName)s-%(lineno)04d | %(message)s
28 | datefmt=
29 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/condition_sample/config/slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxp-572370529330-573807301142-572331691188-####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/condition_sample/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/2.49___init__.py:
--------------------------------------------------------------------------------
1 | from kiwoom.kiwoom import *
2 |
3 | class Main():
4 | def __init__(self):
5 | print("Main() start")
6 |
7 | Kiwoom()
8 |
9 | if __name__ == "__main__":
10 | Main()
11 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/3.1___init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from kiwoom.kiwoom import *
4 | from PyQt5.QtWidgets import *
5 |
6 | class Main():
7 | def __init__(self):
8 | print("Main() start")
9 |
10 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
11 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
12 | self.app.exec_() # 이벤트 루프 실행
13 |
14 | if __name__ == "__main__":
15 | Main()
16 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/8.7_kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path.append("C:/Users/USER/PycharmProjects/week1/")
3 |
4 | from kiwoom.kiwoom import *
5 | from PyQt5.QtWidgets import *
6 |
7 | class Main():
8 | def __init__(self):
9 | print("Main() start")
10 |
11 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
12 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
13 | self.app.exec_() # 이벤트 루프 실행
14 |
15 |
16 | if __name__ == "__main__":
17 | Main()
18 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/4.3_errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
38 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/7.4_kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/8.1_log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | from datetime import datetime
3 |
4 | class Logging():
5 | def __init__(self, config_path='config/logging.conf', log_path='log'):
6 | self.config_path = config_path
7 | self.log_path = log_path
8 |
9 | logging.config.fileConfig(self.config_path)
10 | self.logger = logging.getLogger('Kiwoom')
11 | self.kiwoom_log()
12 |
13 | #로그설정
14 | def kiwoom_log(self):
15 | fh = logging.FileHandler(self.log_path+'/{:%Y-%m-%d}.log'.format(datetime.now()), encoding="utf-8")
16 | formatter = logging.Formatter('[%(asctime)s] I %(filename)s | %(name)s-%(funcName)s-%(lineno)04d I %(levelname)-8s > %(message)s')
17 |
18 | fh.setFormatter(formatter)
19 | self.logger.addHandler(fh)
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/8.2_logging.conf:
--------------------------------------------------------------------------------
1 | [loggers]
2 | keys=root, Kiwoom
3 |
4 | [handlers]
5 | keys=consoleHandler
6 |
7 | [formatters]
8 | keys=consoleFormatter
9 |
10 | [logger_root]
11 | level=DEBUG
12 | handlers=consoleHandler
13 |
14 | [logger_Kiwoom]
15 | level=DEBUG
16 | handlers=consoleHandler
17 | qualname=Kiwoom
18 | propagate=0
19 |
20 | [handler_consoleHandler]
21 | class=StreamHandler
22 | level=DEBUG
23 | formatter=consoleFormatter
24 | args=(sys.stdout,)
25 |
26 | [formatter_consoleFormatter]
27 | format=%(asctime)s | %(levelname)-8s | %(filename)s-%(funcName)s-%(lineno)04d | %(message)s
28 | datefmt=
29 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/8.5_slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxb-1126585321985-1114180369955-#####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
38 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | from datetime import datetime
3 |
4 | class Logging():
5 | def __init__(self, config_path='config/logging.conf', log_path='log'):
6 | self.config_path = config_path
7 | self.log_path = log_path
8 |
9 | logging.config.fileConfig(self.config_path)
10 | self.logger = logging.getLogger('Kiwoom')
11 | self.kiwoom_log()
12 |
13 | #로그설정
14 | def kiwoom_log(self):
15 | fh = logging.FileHandler(self.log_path+'/{:%Y-%m-%d}.log'.format(datetime.now()), encoding="utf-8")
16 | formatter = logging.Formatter('[%(asctime)s] I %(filename)s | %(name)s-%(funcName)s-%(lineno)04d I %(levelname)-8s > %(message)s')
17 |
18 | fh.setFormatter(formatter)
19 | self.logger.addHandler(fh)
20 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/logging.conf:
--------------------------------------------------------------------------------
1 | [loggers]
2 | keys=root, Kiwoom
3 |
4 | [handlers]
5 | keys=consoleHandler
6 |
7 | [formatters]
8 | keys=consoleFormatter
9 |
10 | [logger_root]
11 | level=DEBUG
12 | handlers=consoleHandler
13 |
14 | [logger_Kiwoom]
15 | level=DEBUG
16 | handlers=consoleHandler
17 | qualname=Kiwoom
18 | propagate=0
19 |
20 | [handler_consoleHandler]
21 | class=StreamHandler
22 | level=DEBUG
23 | formatter=consoleFormatter
24 | args=(sys.stdout,)
25 |
26 | [formatter_consoleFormatter]
27 | format=%(asctime)s | %(levelname)-8s | %(filename)s-%(funcName)s-%(lineno)04d | %(message)s
28 | datefmt=
29 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/config/slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxb-1126585321985-1114180369955-#####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/2.50_kiwoom.py:
--------------------------------------------------------------------------------
1 | class Kiwoom():
2 | def __init__(self):
3 | print("Kiwoom() class start.")
4 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/3.2_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 |
3 | class Kiwoom(QAxWidget):
4 | def __init__(self):
5 | super().__init__()
6 | print("Kiwoom() class start.")
7 |
8 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
9 |
10 | def get_ocx_instance(self):
11 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
12 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.10_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 | self.OnReceiveTrData.connect(self.trdata_slot) # 트랜잭션 요청 관련 이벤트
41 |
42 | def signal_login_commConnect(self):
43 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
44 |
45 | self.login_event_loop.exec_() # 이벤트 루프 실행
46 |
47 | def login_slot(self, err_code):
48 | print(errors(err_code)[1])
49 |
50 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
51 | self.login_event_loop.exit()
52 |
53 | def get_account_info(self):
54 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
55 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
56 |
57 | self.account_num = account_num
58 |
59 | print("계좌번호 : %s" % account_num)
60 |
61 | def detail_account_info(self, sPrevNext="0"):
62 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
64 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
65 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
66 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
67 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.11_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 | self.OnReceiveTrData.connect(self.trdata_slot) # 트랜잭션 요청 관련 이벤트
41 |
42 | def signal_login_commConnect(self):
43 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
44 |
45 | self.login_event_loop.exec_() # 이벤트 루프 실행
46 |
47 | def login_slot(self, err_code):
48 | print(errors(err_code)[1])
49 |
50 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
51 | self.login_event_loop.exit()
52 |
53 | def get_account_info(self):
54 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
55 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
56 |
57 | self.account_num = account_num
58 |
59 | print("계좌번호 : %s" % account_num)
60 |
61 | def detail_account_info(self, sPrevNext="0"):
62 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
64 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
65 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
66 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
67 |
68 |
69 | def trdata_slot(self, sScrNo, sRQName, sTrCode, sRecordName, sPrevNext):
70 |
71 | if sRQName == "예수금상세현황요청":
72 | deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "예수금")
73 | self.deposit = int(deposit)
74 |
75 | use_money = float(self.deposit) * self.use_money_percent
76 | self.use_money = int(use_money)
77 | self.use_money = self.use_money / 4
78 |
79 | output_deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "출금가능금액")
80 | self.output_deposit = int(output_deposit)
81 |
82 | print("예수금 : %s" % self.output_deposit)
83 |
84 | self.stop_screen_cancel(self.screen_my_info)
85 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.12_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 | self.OnReceiveTrData.connect(self.trdata_slot) # 트랜잭션 요청 관련 이벤트
41 |
42 | def signal_login_commConnect(self):
43 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
44 |
45 | self.login_event_loop.exec_() # 이벤트 루프 실행
46 |
47 | def login_slot(self, err_code):
48 | print(errors(err_code)[1])
49 |
50 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
51 | self.login_event_loop.exit()
52 |
53 | def get_account_info(self):
54 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
55 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
56 |
57 | self.account_num = account_num
58 |
59 | print("계좌번호 : %s" % account_num)
60 |
61 | def detail_account_info(self, sPrevNext="0"):
62 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
64 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
65 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
66 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
67 |
68 |
69 | def trdata_slot(self, sScrNo, sRQName, sTrCode, sRecordName, sPrevNext):
70 |
71 | if sRQName == "예수금상세현황요청":
72 | deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "예수금")
73 | self.deposit = int(deposit)
74 |
75 | use_money = float(self.deposit) * self.use_money_percent
76 | self.use_money = int(use_money)
77 | self.use_money = self.use_money / 4
78 |
79 | output_deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "출금가능금액")
80 | self.output_deposit = int(output_deposit)
81 |
82 | print("예수금 : %s" % self.output_deposit)
83 |
84 | self.stop_screen_cancel(self.screen_my_info)
85 |
86 | def stop_screen_cancel(self, sScrNo=None):
87 | self.dynamicCall("DisconnectRealData(QString)", sScrNo) # 스크린 번호 연결 끊기
88 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.1_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 |
4 | class Kiwoom(QAxWidget):
5 | def __init__(self):
6 | super().__init__()
7 | print("Kiwoom() class start.")
8 |
9 | ######### 초기 셋팅 함수들 바로 실행
10 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
11 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
12 | self.signal_login_commConnect() # 로그인 요청 함수 포함
13 | #########################################
14 |
15 | def get_ocx_instance(self):
16 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
17 |
18 | def event_slots(self):
19 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
20 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.2_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 |
4 | class Kiwoom(QAxWidget):
5 | def __init__(self):
6 | super().__init__()
7 | print("Kiwoom() class start.")
8 |
9 | ####### event loop를 실행하기 위한 변수 모음
10 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
11 | #########################################
12 |
13 | ######### 초기 셋팅 함수들 바로 실행
14 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
15 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
16 | self.signal_login_commConnect() # 로그인 요청 함수 포함
17 | #########################################
18 |
19 | def get_ocx_instance(self):
20 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
21 |
22 | def event_slots(self):
23 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
24 |
25 | def login_slot(self, err_code):
26 | print(errors(err_code)[1])
27 |
28 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
29 | self.login_event_loop.exit()
30 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.4_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def login_slot(self, err_code):
27 | print(errors(err_code)[1])
28 |
29 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
30 | self.login_event_loop.exit()
31 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.5_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.6_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.7_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
37 | def get_account_info(self):
38 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
39 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
40 |
41 | self.account_num = account_num
42 |
43 | print("계좌번호 : %s" % account_num)
44 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.8_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | self.get_account_info() #계좌번호 가져오기
19 | #########################################
20 |
21 | def get_ocx_instance(self):
22 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
23 |
24 | def event_slots(self):
25 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
26 |
27 | def signal_login_commConnect(self):
28 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
29 |
30 | self.login_event_loop.exec_() # 이벤트 루프 실행
31 |
32 | def login_slot(self, err_code):
33 | print(errors(err_code)[1])
34 |
35 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
36 | self.login_event_loop.exit()
37 |
38 | def get_account_info(self):
39 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
40 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
41 |
42 | self.account_num = account_num
43 |
44 | print("계좌번호 : %s" % account_num)
45 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoom/4.9_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 |
41 | def signal_login_commConnect(self):
42 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
43 |
44 | self.login_event_loop.exec_() # 이벤트 루프 실행
45 |
46 | def login_slot(self, err_code):
47 | print(errors(err_code)[1])
48 |
49 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
50 | self.login_event_loop.exit()
51 |
52 | def get_account_info(self):
53 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
54 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
55 |
56 | self.account_num = account_num
57 |
58 | print("계좌번호 : %s" % account_num)
59 |
60 | def detail_account_info(self, sPrevNext="0"):
61 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
62 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
64 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
65 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
66 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_1쇄2쇄/example/log/2020-01-21.log:
--------------------------------------------------------------------------------
1 | [2020-01-21 11:27:21,183] I kiwoom.py | Kiwoom-__init__-0019 I DEBUG > Kiwoom() class start.
2 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v1.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.1 ==========")
2 | print("Hello world")
3 |
4 |
5 | print("\n\n========== 예제 2.2 ==========")
6 | print("Hello world")
7 | #Hello world
8 |
9 |
10 | print("\n\n========== 예제 2.3 ==========")
11 | print("Hello world" + " Thank you")
12 | #Hello world Thank you
13 |
14 |
15 | print("\n\n========== 예제 2.4 ==========")
16 | print(900629)
17 | #900629
18 |
19 |
20 | print("\n\n========== 예제 2.5 ==========")
21 | print("%s 입니다." % "홍길동")
22 | #홍길동 입니다.
23 | print("%s 입니다." % "이순신")
24 | #이순신 입니다.
25 | print("%s원 입니다." % 5000)
26 | #5000원 입니다.
27 |
28 |
29 | print("\n\n========== 예제 2.6 ==========")
30 | print("이름은 %s 이고 %s에 삽니다." % ("홍길동", "서울"))
31 | #이름은 홍길동 이고 서울에 삽니다.
32 |
33 |
34 | print("\n\n========== 예제 2.7 ==========")
35 | #int 변수, 최대값 : 9223372036854775807
36 | stock_price = 3900
37 | print(stock_price)
38 | stock_price = 4500
39 | print(stock_price)
40 | stock_price_type = type(stock_price) #
41 | print(stock_price_type)
42 |
43 |
44 | print("\n\n========== 예제 2.8 ==========")
45 | #float 변수
46 | stock_percent = 3.8 # 3.8
47 | print(stock_percent)
48 | stock_percent_type = type(stock_percent) #
49 | print(stock_percent_type)
50 |
51 |
52 | print("\n\n========== 예제 2.9 ==========")
53 | #string 변수
54 | stock_name = "홀딩스" # 홀딩스
55 | print(stock_name)
56 | stock_name_type = type(stock_name) #
57 | print(stock_name_type)
58 | stock_name = "3900" # 3900
59 | print(stock_name)
60 | stock_name_type = type(stock_name) #
61 | print(stock_name_type)
62 |
63 |
64 | print("\n\n========== 예제 2.10 ==========")
65 | #bool 변수
66 | stock_buy = False
67 | print(stock_buy)
68 | stock_buy_type = type(stock_buy) #
69 | print(stock_buy_type)
70 |
71 |
72 | print("\n\n========== 예제 2.11 ==========")
73 | stock_price = 2000
74 | stock_price2 = 2500
75 | stock_result = stock_price + stock_price2
76 | print(stock_result) # 4500
77 |
78 |
79 | print("\n\n========== 예제 2.12 ==========")
80 | stock_price = 2000
81 | stock_price2 = 1000
82 | stock_result= stock_price - stock_price2
83 | print(stock_result) # 1000
84 |
85 |
86 | print("\n\n========== 예제 2.13 ==========")
87 | stock_price = 1000
88 | stock_price2 = 1200
89 | stock_result = stock_price * stock_price2
90 | print(stock_result) # 1200000
91 |
92 |
93 | print("\n\n========== 예제 2.14 ==========")
94 | stock_price = 2000
95 | stock_price2 = 2200
96 | stock_result = stock_price / stock_price2
97 | print(stock_result) # 0.9090909090909091
98 | stock_result = stock_price // stock_price2
99 | print(stock_result) # 0
100 |
101 |
102 | print("\n\n========== 예제 2.15 ==========")
103 | stock_price = 1000
104 | stock_price2 = 900
105 | stock_result = stock_price % stock_price2
106 | print(stock_result) # 100
107 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v1_problem.py:
--------------------------------------------------------------------------------
1 | print("========== 문제 1 ==========")
2 | stock_name = "키움증권"
3 | stock_price = 3900
4 | stock_percent = 3.8
5 | print("주식이름 : %s, 가격 : %s원, 등락율 : %s" % (stock_name, stock_price, stock_percent))
6 |
7 |
8 | print("\n\n========== 문제 2 ==========")
9 | print("등락율 : %s %%" % stock_percent)
10 | print("등락율 : %s %s" % (stock_percent, "%"))
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v2.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.16 ==========")
2 | stock_name = "키움증권"
3 | if stock_name == "키움증권":
4 | print("통과!")
5 |
6 |
7 | print("\n\n========== 예제 2.17 ==========")
8 | stock_price = 3000
9 | if stock_price > 3000:
10 | print("통과!1")
11 | elif stock_price >= 3000:
12 | print("통과!2")
13 | elif stock_price <= 3000:
14 | print("통과!3")
15 | else:
16 | print("조건에 해당하는 게 없음!")
17 |
18 |
19 | print("\n\n========== 예제 2.18 ==========")
20 | stock_price = 3000
21 | if stock_price < 3000 or stock_price >= 3000:
22 | print("둘 중 아무거나 맞으면 출력")
23 |
24 | print("\n\n========== 예제 2.19 ==========")
25 | stock_price = 3000
26 | if stock_price > 2000 or stock_price < 2500:
27 | print("2000~2500 사이")
28 | elif stock_price >= 2500 and stock_price <= 3000:
29 | print("2500~3000 사이")
30 |
31 | stock_price = 3000
32 | if stock_price > 2000 and stock_price <= 3000:
33 | print("2001~3000 사이")
34 | elif stock_price > 3000 and stock_price <= 4000:
35 | print("3001~4000 사이")
36 |
37 |
38 | print("\n\n========== 예제 2.20 ==========")
39 | for i in range(5, 100):
40 | print(i)
41 |
42 |
43 | print("\n\n========== 예제 2.21 ==========")
44 | for i in range(5, 100):
45 | print(i)
46 |
47 | if i == 50:
48 | break
49 |
50 | print("\n\n========== 예제 2.22 ==========")
51 | for i in range(0, 10):
52 | for k in range(0, 5):
53 | print("for 문 안에 for 문 %s" % k)
54 |
55 |
56 | print("\n\n========== 예제 2.23 ==========")
57 | stock_buy = True
58 | count = 0
59 | while stock_buy:
60 | count = count + 1
61 |
62 | if count == 10:
63 | break
64 |
65 | print(count)
66 |
67 |
68 | print("\n\n========== 예제 2.24 ==========")
69 | stock_buy = True
70 | count = 0
71 | while stock_buy:
72 | count = count + 1
73 |
74 | if count == 10:
75 | # break
76 | stock_buy = False
77 |
78 | print(count)
79 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v2_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 3 ==========")
2 | kakao_price = 1000
3 | kiwoom_price = 500
4 |
5 | for i in range(0, 3):
6 | kakao_price += 500
7 | kiwoom_price += 1000
8 |
9 | if kakao_price > kiwoom_price:
10 | print("카카오가 더 높다")
11 | elif kakao_price < kiwoom_price:
12 | print("키움이 더 높다")
13 | elif kakao_price == kiwoom_price:
14 | print("키움과 카카오가 같다")
15 |
16 |
17 | print("\n\n========== 문제 4 ==========")
18 | for i in range(1, 10):
19 | for j in range(1, 10):
20 | result = i * j
21 | print("%s x %s = %s" % (i, j, result))
22 |
23 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v3.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.25 ==========")
3 | a_list = ("키움", "카카오", "대신")
4 | for val in a_list:
5 | print(val)
6 |
7 |
8 | print("\n\n========== 예제 2.26 ==========")
9 | a_list = ["키움", "카카오", "네이버"]
10 | for val in a_list:
11 | print(val)
12 |
13 |
14 | print("\n\n========== 예제 2.27 ==========")
15 | a_list = ["키움", "카카오", "네이버"]
16 | a_list.append("대신증권")
17 | for val in a_list:
18 | print(val)
19 |
20 |
21 | print("\n\n========== 예제 2.28 ==========")
22 | print(a_list[0])
23 |
24 |
25 | print("\n\n========== 예제 2.29 ==========")
26 | a_list = ["키움", "카카오", "네이버"] #list
27 | print(a_list)
28 | a_list[2] = "다음" #수정하기
29 | print(a_list)
30 | del a_list[1] #삭제하기
31 | print(a_list)
32 |
33 |
34 | print("\n\n========== 예제 2.30 ==========")
35 | a_list = ["키움", "카카오", "네이버"]
36 | for idx, val in enumerate(a_list):
37 | print("인덱스: %s, 값: %s" % (idx, val))
38 |
39 |
40 | print("\n\n========== 예제 2.31 ==========")
41 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
42 | print(a_dict.get("키움증권")) # 1300
43 | print(a_dict['키움증권']) # 1300
44 |
45 |
46 | print("\n\n========== 예제 2.32 ==========")
47 | for key in a_dict.keys():
48 | print(a_dict.get(key))
49 |
50 |
51 | print("\n\n========== 예제 2.33 ==========")
52 | for key, value in a_dict.items(): #key와 value 값 모두 가져옴
53 | print("키값 : %s , value값 : %s" % (key, value))
54 |
55 |
56 | print("\n\n========== 예제 2.34 ==========")
57 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
58 | a_dict["다음증권"] = 2500
59 | print(a_dict)
60 |
61 |
62 | print("\n\n========== 예제 2.35 ==========")
63 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
64 | a_dict.update({"다음증권":2500})
65 | print(a_dict)
66 |
67 |
68 | print("\n\n========== 예제 2.36 ==========")
69 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
70 | a_dict["다음증권"] = 2500
71 | a_dict["애플"] = 152000
72 | a_dict["삼성"] = 221500
73 | a_dict["LG"] = 25800
74 | print(a_dict)
75 |
76 |
77 | print("\n\n========== 예제 2.37 ==========")
78 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
79 | a_dict.update({"다음증권":2000, "애플":152000, "삼성":221500, "LG":25800})
80 | print(a_dict)
81 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v3_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 5 ==========")
2 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
3 | a_plus = 0
4 | for val in a_dict.keys():
5 | a_plus = a_plus + a_dict[val] # a_plus += a_dict[val] 형태와 같다
6 | print("종목 : %s, 가격: %s " % (val, a_dict[val]))
7 | print("더한값 %s " % a_plus)
8 |
9 |
10 | print("\n\n========== 문제 6 ==========")
11 | a_dict = {"키움증권": 5000, "카카오": 3000, "네이버": 2000}
12 | my_account = 111000
13 | for val in a_dict.keys():
14 | if val == "키움증권":
15 | my_account = my_account - a_dict[val] * 5
16 | elif val == "카카오":
17 | my_account -= a_dict[val] * 2
18 | elif val == "네이버":
19 | my_account -= a_dict[val] * 5
20 |
21 | print("남은 금액 : %s " % my_account)
22 |
23 |
24 | print("\n\n========== 문제 7 ==========")
25 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
26 | ee_bool = True
27 | while ee_bool:
28 | a_dict['키움증권'] = a_dict['키움증권'] + 1000
29 |
30 | if a_dict['키움증권'] == 10000:
31 | a_dict.update({"이베스트증권" : 5000})
32 | break
33 |
34 | print(a_dict)
35 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v4.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.38 ==========")
3 | def english():
4 | print("영어과입니다.")
5 | english()
6 |
7 |
8 | print("\n\n========== 예제 2.39 ==========")
9 | def math(student_name):
10 | print(student_name)
11 | math("토마스")
12 |
13 |
14 | print("\n\n========== 예제 2.40 ==========")
15 | def academy(student_name1, student_name2, student_name3):
16 | print(student_name1)
17 | print(student_name2)
18 | print(student_name3)
19 |
20 | academy("토마스", "에디슨", "빌리")
21 |
22 |
23 | print("\n\n========== 예제 2.41 ==========")
24 | def english(help):
25 | help()
26 |
27 | def help():
28 | print("도와주러 왔습니다.")
29 |
30 | english(help)
31 |
32 |
33 | print("\n\n========== 예제 2.42 ==========")
34 | def math():
35 | name = "광수"
36 | return name
37 |
38 | who = math()
39 | print(who)
40 |
41 |
42 | print("\n\n========== 예제 2.43 ==========")
43 | def multi():
44 | return "a", "b"
45 |
46 | a, b = multi()
47 | result = multi()
48 | print(result)
49 |
50 |
51 | print("\n\n========== 예제 2.44 ==========")
52 | class B_school():
53 | def __init__(self):
54 | print("b대학교 초기화")
55 |
56 | B_school()
57 |
58 |
59 | print("\n\n========== 예제 2.45 ==========")
60 | class A_school():
61 | def __init__(self):
62 | print("초기화, 생성자")
63 | self.student1_name = None
64 | self.student2_name = None
65 |
66 | print(dir(self))
67 |
68 | A_school()
69 |
70 |
71 | print("\n\n========== 예제 2.46 ==========")
72 | class A_school():
73 | def __init__(self):
74 | print("초기화, 생성자")
75 | self.student1_name = None
76 |
77 | b = self.math()
78 | print("수학과 학생 %s" % b)
79 |
80 | def math(self):
81 | self.student1_name = "영수"
82 | name = self.student1_name
83 |
84 | return name
85 |
86 |
87 | print("\n\n========== 예제 2.47 ==========")
88 | class B_school():
89 | def __init__(self):
90 | print("b대학교 초기화")
91 |
92 | self.school_name = "b학교"
93 |
94 | class A_school():
95 | def __init__(self):
96 | print("초기화, 생성자")
97 | self.student1_name = None
98 |
99 | b = self.math()
100 | print("수학과 학생 %s" % b)
101 |
102 | b_school = B_school()
103 | print(b_school.school_name)
104 |
105 | def math(self):
106 | self.student1_name = "영수"
107 | name = self.student1_name
108 |
109 | return name
110 |
111 | A_school()
112 |
113 |
114 | print("\n\n========== 예제 2.48 ==========")
115 | class Parent():
116 | def __init__(self):
117 | print("부모입니다.")
118 |
119 | self.money = 50000000
120 |
121 | def home(self):
122 | return "부모의 집"
123 |
124 | class ChildA(Parent):
125 | def __init__(self):
126 | print("자식A")
127 |
128 | print("부모의 돈을 물려받을 수 없습니다.")
129 | print("%s을 물려받았습니다." % self.home())
130 |
131 | class ChildB(Parent):
132 | def __init__(self):
133 | super().__init__()
134 | print("자식B")
135 |
136 | print("부모의 돈 %s" % self.money)
137 | print("%s을 물려받았습니다." % self.home())
138 |
139 | ChildA()
140 | ChildB()
141 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter02/basic_v4_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 8 ==========")
2 | class Condition():
3 | def sell_filtering(self, my_dict):
4 | for key in my_dict.keys():
5 | if 5000 >= my_dict[key]:
6 | print("종목 %s, 가격 %s" % (key, my_dict[key]))
7 |
8 | class Kiwoom():
9 | def __init__(self):
10 | self.my_dict = {"네이버":6000, "애플":15000, "다음":3000, "넷플릭스":5000, "구글":100000, "삼성":3000, "LG":1000, "키움":500, "호랑":8000, "셀트리온":8500, "코난":6050, "컬링":1000, "하이원":3200}
11 |
12 | condition = Condition()
13 | condition.sell_filtering(self.my_dict)
14 |
15 | Kiwoom()
16 |
17 | print("\n\n========== 문제 9 ==========")
18 | class Condition():
19 | def sell_filtering(self, my_dict):
20 | for key in my_dict.keys():
21 | if key == "넷플릭스":
22 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
23 |
24 | elif key == "애플":
25 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
26 |
27 | elif key == "구글":
28 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
29 |
30 | return my_dict
31 |
32 | class Kiwoom():
33 | def __init__(self):
34 | self.my_dict = {'네이버':{'현재가':3000, '보유량':100}, '애플':{'현재가':10000, '보유량':200}, '다음':{'현재가':4000, '보유량':50}, '넷플릭스':{'현재가':7000, '보유량':200}, '구글':{'현재가':13000, '보유량':30}}
35 |
36 | condition = Condition()
37 | result = condition.sell_filtering(self.my_dict)
38 | print(result)
39 |
40 | Kiwoom()
41 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/chapter06/dict.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 예제 6.4 ==========")
2 | sample_dict = {"1":"테스트1", "2":"테스트2", "3":"테스트3"}
3 |
4 | a_test = sample_dict
5 | a_test["1"] = "변경하기"
6 |
7 | print("할당 %s" % a_test)
8 | print("원본 %s" % sample_dict)
9 |
10 |
11 | print("\n\n========== 예제 6.5 ==========")
12 | sample_dict = {"1":"테스트1", "2":"테스트2", "3":"테스트3"}
13 |
14 | a_test = sample_dict.copy()
15 | a_test["1"] = "변경하기"
16 |
17 | print("할당 %s" % a_test)
18 | print("원본 %s" % sample_dict)
19 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/condition_sample/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path.append("C:/Users/USER/PycharmProjects/week1/")
3 |
4 | from kiwoom.kiwoom import *
5 | from PyQt5.QtWidgets import *
6 |
7 | class Main():
8 | def __init__(self):
9 | print("Main() start")
10 |
11 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
12 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
13 | self.app.exec_() # 이벤트 루프 실행
14 |
15 | if __name__ == "__main__":
16 | Main()
17 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/condition_sample/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
--------------------------------------------------------------------------------
/교재학습코드_3쇄/condition_sample/config/kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/condition_sample/config/log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | import datetime
3 |
4 | class Logging():
5 | def __init__(self):
6 | self.logger = logging.getLogger(__name__)
7 |
8 | format = logging.Formatter("%(asctime)s | %(filename)s | %(lineno)s | %(levelname)s -> %(message)s")
9 |
10 | streamHandler = logging.StreamHandler()
11 | streamHandler.setFormatter(format)
12 | self.logger.addHandler(streamHandler)
13 |
14 | d_time = datetime.datetime.now()
15 | d_str = d_time.strftime("%Y-%m-%d")
16 | fileHandler = logging.FileHandler("log/"+d_str+".log", encoding="utf-8")
17 | fileHandler.setFormatter(format)
18 | self.logger.addHandler(fileHandler)
19 |
20 | self.logger.setLevel(level=logging.DEBUG)
--------------------------------------------------------------------------------
/교재학습코드_3쇄/condition_sample/config/slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxp-572370529330-573807301142-572331691188-####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/condition_sample/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/2.49___init__.py:
--------------------------------------------------------------------------------
1 | from kiwoom.kiwoom import *
2 |
3 | class Main():
4 | def __init__(self):
5 | print("Main() start")
6 |
7 | Kiwoom()
8 |
9 | if __name__ == "__main__":
10 | Main()
11 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/3.1___init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from kiwoom.kiwoom import *
4 | from PyQt5.QtWidgets import *
5 |
6 | class Main():
7 | def __init__(self):
8 | print("Main() start")
9 |
10 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
11 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
12 | self.app.exec_() # 이벤트 루프 실행
13 |
14 | if __name__ == "__main__":
15 | Main()
16 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/8.5_kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path.append("C:/Users/USER/PycharmProjects/week1/")
3 |
4 | from kiwoom.kiwoom import *
5 | from PyQt5.QtWidgets import *
6 |
7 | class Main():
8 | def __init__(self):
9 | print("Main() start")
10 |
11 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
12 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
13 | self.app.exec_() # 이벤트 루프 실행
14 |
15 |
16 | if __name__ == "__main__":
17 | Main()
18 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/4.3_errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
38 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/7.4_kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/8.1_log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | import datetime
3 |
4 | class Logging():
5 | def __init__(self):
6 | self.logger = logging.getLogger(__name__)
7 |
8 | format = logging.Formatter("%(asctime)s | %(filename)s | %(lineno)s | %(levelname)s -> %(message)s")
9 |
10 | streamHandler = logging.StreamHandler()
11 | streamHandler.setFormatter(format)
12 | self.logger.addHandler(streamHandler)
13 |
14 | d_time = datetime.datetime.now()
15 | d_str = d_time.strftime("%Y-%m-%d")
16 | fileHandler = logging.FileHandler("log/"+d_str+".log", encoding="utf-8")
17 | fileHandler.setFormatter(format)
18 | self.logger.addHandler(fileHandler)
19 |
20 | self.logger.setLevel(level=logging.DEBUG)
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/8.3_slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxb-1126585321985-1114180369955-#####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
38 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | from datetime import datetime
3 |
4 | class Logging():
5 | def __init__(self, config_path='config/logging.conf', log_path='log'):
6 | self.config_path = config_path
7 | self.log_path = log_path
8 |
9 | logging.config.fileConfig(self.config_path)
10 | self.logger = logging.getLogger('Kiwoom')
11 | self.kiwoom_log()
12 |
13 | #로그설정
14 | def kiwoom_log(self):
15 | fh = logging.FileHandler(self.log_path+'/{:%Y-%m-%d}.log'.format(datetime.now()), encoding="utf-8")
16 | formatter = logging.Formatter('[%(asctime)s] I %(filename)s | %(name)s-%(funcName)s-%(lineno)04d I %(levelname)-8s > %(message)s')
17 |
18 | fh.setFormatter(formatter)
19 | self.logger.addHandler(fh)
20 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/config/slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxb-1126585321985-1114180369955-#####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/2.50_kiwoom.py:
--------------------------------------------------------------------------------
1 | class Kiwoom():
2 | def __init__(self):
3 | print("Kiwoom() class start.")
4 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/3.2_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 |
3 | class Kiwoom(QAxWidget):
4 | def __init__(self):
5 | super().__init__()
6 | print("Kiwoom() class start.")
7 |
8 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
9 |
10 | def get_ocx_instance(self):
11 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
12 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.10_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 | self.OnReceiveTrData.connect(self.trdata_slot) # 트랜잭션 요청 관련 이벤트
41 |
42 | def signal_login_commConnect(self):
43 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
44 |
45 | self.login_event_loop.exec_() # 이벤트 루프 실행
46 |
47 | def login_slot(self, err_code):
48 | print(errors(err_code)[1])
49 |
50 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
51 | self.login_event_loop.exit()
52 |
53 | def get_account_info(self):
54 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
55 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
56 |
57 | self.account_num = account_num
58 |
59 | print("계좌번호 : %s" % account_num)
60 |
61 | def detail_account_info(self, sPrevNext="0"):
62 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
64 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
65 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
66 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
67 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.11_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 | self.OnReceiveTrData.connect(self.trdata_slot) # 트랜잭션 요청 관련 이벤트
41 |
42 | def signal_login_commConnect(self):
43 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
44 |
45 | self.login_event_loop.exec_() # 이벤트 루프 실행
46 |
47 | def login_slot(self, err_code):
48 | print(errors(err_code)[1])
49 |
50 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
51 | self.login_event_loop.exit()
52 |
53 | def get_account_info(self):
54 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
55 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
56 |
57 | self.account_num = account_num
58 |
59 | print("계좌번호 : %s" % account_num)
60 |
61 | def detail_account_info(self, sPrevNext="0"):
62 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
64 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
65 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
66 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
67 |
68 |
69 | def trdata_slot(self, sScrNo, sRQName, sTrCode, sRecordName, sPrevNext):
70 |
71 | if sRQName == "예수금상세현황요청":
72 | deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "예수금")
73 | self.deposit = int(deposit)
74 |
75 | use_money = float(self.deposit) * self.use_money_percent
76 | self.use_money = int(use_money)
77 | self.use_money = self.use_money / 4
78 |
79 | output_deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "출금가능금액")
80 | self.output_deposit = int(output_deposit)
81 |
82 | print("예수금 : %s" % self.output_deposit)
83 |
84 | self.stop_screen_cancel(self.screen_my_info)
85 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.1_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 |
4 | class Kiwoom(QAxWidget):
5 | def __init__(self):
6 | super().__init__()
7 | print("Kiwoom() class start.")
8 |
9 | ######### 초기 셋팅 함수들 바로 실행
10 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
11 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
12 | self.signal_login_commConnect() # 로그인 요청 함수 포함
13 | #########################################
14 |
15 | def get_ocx_instance(self):
16 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
17 |
18 | def event_slots(self):
19 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
20 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.2_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 |
4 | class Kiwoom(QAxWidget):
5 | def __init__(self):
6 | super().__init__()
7 | print("Kiwoom() class start.")
8 |
9 | ####### event loop를 실행하기 위한 변수 모음
10 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
11 | #########################################
12 |
13 | ######### 초기 셋팅 함수들 바로 실행
14 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
15 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
16 | self.signal_login_commConnect() # 로그인 요청 함수 포함
17 | #########################################
18 |
19 | def get_ocx_instance(self):
20 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
21 |
22 | def event_slots(self):
23 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
24 |
25 | def login_slot(self, err_code):
26 | print(errors(err_code)[1])
27 |
28 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
29 | self.login_event_loop.exit()
30 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.4_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def login_slot(self, err_code):
27 | print(errors(err_code)[1])
28 |
29 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
30 | self.login_event_loop.exit()
31 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.5_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.6_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.7_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
37 | def get_account_info(self):
38 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
39 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
40 |
41 | self.account_num = account_num
42 |
43 | print("계좌번호 : %s" % account_num)
44 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.8_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | self.get_account_info() #계좌번호 가져오기
19 | #########################################
20 |
21 | def get_ocx_instance(self):
22 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
23 |
24 | def event_slots(self):
25 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
26 |
27 | def signal_login_commConnect(self):
28 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
29 |
30 | self.login_event_loop.exec_() # 이벤트 루프 실행
31 |
32 | def login_slot(self, err_code):
33 | print(errors(err_code)[1])
34 |
35 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
36 | self.login_event_loop.exit()
37 |
38 | def get_account_info(self):
39 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
40 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
41 |
42 | self.account_num = account_num
43 |
44 | print("계좌번호 : %s" % account_num)
45 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoom/4.9_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 |
41 | def signal_login_commConnect(self):
42 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
43 |
44 | self.login_event_loop.exec_() # 이벤트 루프 실행
45 |
46 | def login_slot(self, err_code):
47 | print(errors(err_code)[1])
48 |
49 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
50 | self.login_event_loop.exit()
51 |
52 | def get_account_info(self):
53 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
54 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
55 |
56 | self.account_num = account_num
57 |
58 | print("계좌번호 : %s" % account_num)
59 |
60 | def detail_account_info(self, sPrevNext="0"):
61 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
62 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
64 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
65 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
66 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_3쇄/example/log/2020-01-21.log:
--------------------------------------------------------------------------------
1 | [2020-01-21 11:27:21,183] I kiwoom.py | Kiwoom-__init__-0019 I DEBUG > Kiwoom() class start.
2 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v1.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.1 ==========")
2 | print("Hello world")
3 |
4 |
5 | print("\n\n========== 예제 2.2 ==========")
6 | print("Hello world")
7 | #Hello world
8 |
9 |
10 | print("\n\n========== 예제 2.3 ==========")
11 | print("Hello world" + " Thank you")
12 | #Hello world Thank you
13 |
14 |
15 | print("\n\n========== 예제 2.4 ==========")
16 | print(900629)
17 | #900629
18 |
19 |
20 | print("\n\n========== 예제 2.5 ==========")
21 | print("%s 입니다." % "홍길동")
22 | #홍길동 입니다.
23 | print("%s 입니다." % "이순신")
24 | #이순신 입니다.
25 | print("%s원 입니다." % 5000)
26 | #5000원 입니다.
27 |
28 |
29 | print("\n\n========== 예제 2.6 ==========")
30 | print("이름은 %s 이고 %s에 삽니다." % ("홍길동", "서울"))
31 | #이름은 홍길동 이고 서울에 삽니다.
32 |
33 |
34 | print("\n\n========== 예제 2.7 ==========")
35 | #int 변수, 최대값 : 9223372036854775807
36 | stock_price = 3900
37 | print(stock_price)
38 | stock_price = 4500
39 | print(stock_price)
40 | stock_price_type = type(stock_price) #
41 | print(stock_price_type)
42 |
43 |
44 | print("\n\n========== 예제 2.8 ==========")
45 | #float 변수
46 | stock_percent = 3.8 # 3.8
47 | print(stock_percent)
48 | stock_percent_type = type(stock_percent) #
49 | print(stock_percent_type)
50 |
51 |
52 | print("\n\n========== 예제 2.9 ==========")
53 | #string 변수
54 | stock_name = "홀딩스" # 홀딩스
55 | print(stock_name)
56 | stock_name_type = type(stock_name) #
57 | print(stock_name_type)
58 | stock_name = "3900" # 3900
59 | print(stock_name)
60 | stock_name_type = type(stock_name) #
61 | print(stock_name_type)
62 |
63 |
64 | print("\n\n========== 예제 2.10 ==========")
65 | #bool 변수
66 | stock_buy = False
67 | print(stock_buy)
68 | stock_buy_type = type(stock_buy) #
69 | print(stock_buy_type)
70 |
71 |
72 | print("\n\n========== 예제 2.11 ==========")
73 | stock_price = 2000
74 | stock_price2 = 2500
75 | stock_result = stock_price + stock_price2
76 | print(stock_result) # 4500
77 |
78 |
79 | print("\n\n========== 예제 2.12 ==========")
80 | stock_price = 2000
81 | stock_price2 = 1000
82 | stock_result= stock_price - stock_price2
83 | print(stock_result) # 1000
84 |
85 |
86 | print("\n\n========== 예제 2.13 ==========")
87 | stock_price = 1000
88 | stock_price2 = 1200
89 | stock_result = stock_price * stock_price2
90 | print(stock_result) # 1200000
91 |
92 |
93 | print("\n\n========== 예제 2.14 ==========")
94 | stock_price = 2000
95 | stock_price2 = 2200
96 | stock_result = stock_price / stock_price2
97 | print(stock_result) # 0.9090909090909091
98 | stock_result = stock_price // stock_price2
99 | print(stock_result) # 0
100 |
101 |
102 | print("\n\n========== 예제 2.15 ==========")
103 | stock_price = 1000
104 | stock_price2 = 900
105 | stock_result = stock_price % stock_price2
106 | print(stock_result) # 100
107 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v1_problem.py:
--------------------------------------------------------------------------------
1 | print("========== 문제 1 ==========")
2 | stock_name = "키움증권"
3 | stock_price = 3900
4 | stock_percent = 3.8
5 | print("주식이름 : %s, 가격 : %s원, 등락율 : %s" % (stock_name, stock_price, stock_percent))
6 |
7 |
8 | print("\n\n========== 문제 2 ==========")
9 | print("등락율 : %s %%" % stock_percent)
10 | print("등락율 : %s %s" % (stock_percent, "%"))
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v2.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.16 ==========")
2 | stock_name = "키움증권"
3 | if stock_name == "키움증권":
4 | print("통과!")
5 |
6 |
7 | print("\n\n========== 예제 2.17 ==========")
8 | stock_price = 3000
9 | if stock_price > 3000:
10 | print("통과!1")
11 | elif stock_price >= 3000:
12 | print("통과!2")
13 | elif stock_price <= 3000:
14 | print("통과!3")
15 | else:
16 | print("조건에 해당하는 게 없음!")
17 |
18 |
19 | print("\n\n========== 예제 2.18 ==========")
20 | stock_price = 3000
21 | if stock_price < 3000 or stock_price >= 3000:
22 | print("둘 중 아무거나 맞으면 출력")
23 |
24 | print("\n\n========== 예제 2.19 ==========")
25 | stock_price = 3000
26 | if stock_price > 2000 or stock_price < 2500:
27 | print("2000~2500 사이")
28 | elif stock_price >= 2500 and stock_price <= 3000:
29 | print("2500~3000 사이")
30 |
31 | stock_price = 3000
32 | if stock_price > 2000 and stock_price <= 3000:
33 | print("2001~3000 사이")
34 | elif stock_price > 3000 and stock_price <= 4000:
35 | print("3001~4000 사이")
36 |
37 |
38 | print("\n\n========== 예제 2.20 ==========")
39 | for i in range(5, 100):
40 | print(i)
41 |
42 |
43 | print("\n\n========== 예제 2.21 ==========")
44 | for i in range(5, 100):
45 | print(i)
46 |
47 | if i == 50:
48 | break
49 |
50 | print("\n\n========== 예제 2.22 ==========")
51 | for i in range(0, 10):
52 | for k in range(0, 5):
53 | print("for 문 안에 for 문 %s" % k)
54 |
55 |
56 | print("\n\n========== 예제 2.23 ==========")
57 | stock_buy = True
58 | count = 0
59 | while stock_buy:
60 | count = count + 1
61 |
62 | if count == 10:
63 | break
64 |
65 | print(count)
66 |
67 |
68 | print("\n\n========== 예제 2.24 ==========")
69 | stock_buy = True
70 | count = 0
71 | while stock_buy:
72 | count = count + 1
73 |
74 | if count == 10:
75 | # break
76 | stock_buy = False
77 |
78 | print(count)
79 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v2_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 3 ==========")
2 | kakao_price = 1000
3 | kiwoom_price = 500
4 |
5 | for i in range(0, 3):
6 | kakao_price += 500
7 | kiwoom_price += 1000
8 |
9 | if kakao_price > kiwoom_price:
10 | print("카카오가 더 높다")
11 | elif kakao_price < kiwoom_price:
12 | print("키움이 더 높다")
13 | elif kakao_price == kiwoom_price:
14 | print("키움과 카카오가 같다")
15 |
16 |
17 | print("\n\n========== 문제 4 ==========")
18 | for i in range(1, 10):
19 | for j in range(1, 10):
20 | result = i * j
21 | print("%s x %s = %s" % (i, j, result))
22 |
23 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v3.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.25 ==========")
3 | a_list = ("키움", "카카오", "대신")
4 | for val in a_list:
5 | print(val)
6 |
7 |
8 | print("\n\n========== 예제 2.26 ==========")
9 | a_list = ["키움", "카카오", "네이버"]
10 | for val in a_list:
11 | print(val)
12 |
13 |
14 | print("\n\n========== 예제 2.27 ==========")
15 | a_list = ["키움", "카카오", "네이버"]
16 | a_list.append("대신증권")
17 | for val in a_list:
18 | print(val)
19 |
20 |
21 | print("\n\n========== 예제 2.28 ==========")
22 | print(a_list[0])
23 |
24 |
25 | print("\n\n========== 예제 2.29 ==========")
26 | a_list = ["키움", "카카오", "네이버"] #list
27 | print(a_list)
28 | a_list[2] = "다음" #수정하기
29 | print(a_list)
30 | del a_list[1] #삭제하기
31 | print(a_list)
32 |
33 |
34 | print("\n\n========== 예제 2.30 ==========")
35 | a_list = ["키움", "카카오", "네이버"]
36 | for idx, val in enumerate(a_list):
37 | print("인덱스: %s, 값: %s" % (idx, val))
38 |
39 |
40 | print("\n\n========== 예제 2.31 ==========")
41 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
42 | print(a_dict.get("키움증권")) # 1300
43 | print(a_dict['키움증권']) # 1300
44 |
45 |
46 | print("\n\n========== 예제 2.32 ==========")
47 | for key in a_dict.keys():
48 | print(a_dict.get(key))
49 |
50 |
51 | print("\n\n========== 예제 2.33 ==========")
52 | for key, value in a_dict.items(): #key와 value 값 모두 가져옴
53 | print("키값 : %s , value값 : %s" % (key, value))
54 |
55 |
56 | print("\n\n========== 예제 2.34 ==========")
57 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
58 | a_dict["다음증권"] = 2500
59 | print(a_dict)
60 |
61 |
62 | print("\n\n========== 예제 2.35 ==========")
63 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
64 | a_dict.update({"다음증권":2500})
65 | print(a_dict)
66 |
67 |
68 | print("\n\n========== 예제 2.36 ==========")
69 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
70 | a_dict["다음증권"] = 2500
71 | a_dict["애플"] = 152000
72 | a_dict["삼성"] = 221500
73 | a_dict["LG"] = 25800
74 | print(a_dict)
75 |
76 |
77 | print("\n\n========== 예제 2.37 ==========")
78 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
79 | a_dict.update({"다음증권":2000, "애플":152000, "삼성":221500, "LG":25800})
80 | print(a_dict)
81 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v3_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 5 ==========")
2 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
3 | a_plus = 0
4 | for val in a_dict.keys():
5 | a_plus = a_plus + a_dict[val] # a_plus += a_dict[val] 형태와 같다
6 | print("종목 : %s, 가격: %s " % (val, a_dict[val]))
7 | print("더한값 %s " % a_plus)
8 |
9 |
10 | print("\n\n========== 문제 6 ==========")
11 | a_dict = {"키움증권": 5000, "카카오": 3000, "네이버": 2000}
12 | my_account = 111000
13 | for val in a_dict.keys():
14 | if val == "키움증권":
15 | my_account = my_account - a_dict[val] * 5
16 | elif val == "카카오":
17 | my_account -= a_dict[val] * 2
18 | elif val == "네이버":
19 | my_account -= a_dict[val] * 5
20 |
21 | print("남은 금액 : %s " % my_account)
22 |
23 |
24 | print("\n\n========== 문제 7 ==========")
25 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
26 | ee_bool = True
27 | while ee_bool:
28 | a_dict['키움증권'] = a_dict['키움증권'] + 1000
29 |
30 | if a_dict['키움증권'] == 10000:
31 | a_dict.update({"이베스트증권" : 5000})
32 | break
33 |
34 | print(a_dict)
35 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v4.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.38 ==========")
3 | def english():
4 | print("영어과입니다.")
5 | english()
6 |
7 |
8 | print("\n\n========== 예제 2.39 ==========")
9 | def math(student_name):
10 | print(student_name)
11 | math("토마스")
12 |
13 |
14 | print("\n\n========== 예제 2.40 ==========")
15 | def academy(student_name1, student_name2, student_name3):
16 | print(student_name1)
17 | print(student_name2)
18 | print(student_name3)
19 |
20 | academy("토마스", "에디슨", "빌리")
21 |
22 |
23 | print("\n\n========== 예제 2.41 ==========")
24 | def english(help):
25 | help()
26 |
27 | def help():
28 | print("도와주러 왔습니다.")
29 |
30 | english(help)
31 |
32 |
33 | print("\n\n========== 예제 2.42 ==========")
34 | def math():
35 | name = "광수"
36 | return name
37 |
38 | who = math()
39 | print(who)
40 |
41 |
42 | print("\n\n========== 예제 2.43 ==========")
43 | def multi():
44 | return "a", "b"
45 |
46 | a, b = multi()
47 | result = multi()
48 | print(result)
49 |
50 |
51 | print("\n\n========== 예제 2.44 ==========")
52 | class B_school():
53 | def __init__(self):
54 | print("b대학교 초기화")
55 |
56 | B_school()
57 |
58 |
59 | print("\n\n========== 예제 2.45 ==========")
60 | class A_school():
61 | def __init__(self):
62 | print("초기화, 생성자")
63 | self.student1_name = None
64 | self.student2_name = None
65 |
66 | print(dir(self))
67 |
68 | A_school()
69 |
70 |
71 | print("\n\n========== 예제 2.46 ==========")
72 | class A_school():
73 | def __init__(self):
74 | print("초기화, 생성자")
75 | self.student1_name = None
76 |
77 | b = self.math()
78 | print("수학과 학생 %s" % b)
79 |
80 | def math(self):
81 | self.student1_name = "영수"
82 | name = self.student1_name
83 |
84 | return name
85 |
86 |
87 | print("\n\n========== 예제 2.47 ==========")
88 | class B_school():
89 | def __init__(self):
90 | print("b대학교 초기화")
91 |
92 | self.school_name = "b학교"
93 |
94 | class A_school():
95 | def __init__(self):
96 | print("초기화, 생성자")
97 | self.student1_name = None
98 |
99 | b = self.math()
100 | print("수학과 학생 %s" % b)
101 |
102 | b_school = B_school()
103 | print(b_school.school_name)
104 |
105 | def math(self):
106 | self.student1_name = "영수"
107 | name = self.student1_name
108 |
109 | return name
110 |
111 | A_school()
112 |
113 |
114 | print("\n\n========== 예제 2.48 ==========")
115 | class Parent():
116 | def __init__(self):
117 | print("부모입니다.")
118 |
119 | self.money = 50000000
120 |
121 | def home(self):
122 | return "부모의 집"
123 |
124 | class ChildA(Parent):
125 | def __init__(self):
126 | print("자식A")
127 |
128 | print("부모의 돈을 물려받을 수 없습니다.")
129 | print("%s을 물려받았습니다." % self.home())
130 |
131 | class ChildB(Parent):
132 | def __init__(self):
133 | super().__init__()
134 | print("자식B")
135 |
136 | print("부모의 돈 %s" % self.money)
137 | print("%s을 물려받았습니다." % self.home())
138 |
139 | ChildA()
140 | ChildB()
141 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter02/basic_v4_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 8 ==========")
2 | class Condition():
3 | def sell_filtering(self, my_dict):
4 | for key in my_dict.keys():
5 | if 5000 >= my_dict[key]:
6 | print("종목 %s, 가격 %s" % (key, my_dict[key]))
7 |
8 | class Kiwoom():
9 | def __init__(self):
10 | self.my_dict = {"네이버":6000, "애플":15000, "다음":3000, "넷플릭스":5000, "구글":100000, "삼성":3000, "LG":1000, "키움":500, "호랑":8000, "셀트리온":8500, "코난":6050, "컬링":1000, "하이원":3200}
11 |
12 | condition = Condition()
13 | condition.sell_filtering(self.my_dict)
14 |
15 | Kiwoom()
16 |
17 | print("\n\n========== 문제 9 ==========")
18 | class Condition():
19 | def sell_filtering(self, my_dict):
20 | for key in my_dict.keys():
21 | if key == "넷플릭스":
22 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
23 |
24 | elif key == "애플":
25 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
26 |
27 | elif key == "구글":
28 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
29 |
30 | return my_dict
31 |
32 | class Kiwoom():
33 | def __init__(self):
34 | self.my_dict = {'네이버':{'현재가':3000, '보유량':100}, '애플':{'현재가':10000, '보유량':200}, '다음':{'현재가':4000, '보유량':50}, '넷플릭스':{'현재가':7000, '보유량':200}, '구글':{'현재가':13000, '보유량':30}}
35 |
36 | condition = Condition()
37 | result = condition.sell_filtering(self.my_dict)
38 | print(result)
39 |
40 | Kiwoom()
41 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/chapter06/dict.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 예제 6.4 ==========")
2 | sample_dict = {"1":"테스트1", "2":"테스트2", "3":"테스트3"}
3 |
4 | a_test = sample_dict
5 | a_test["1"] = "변경하기"
6 |
7 | print("할당 %s" % a_test)
8 | print("원본 %s" % sample_dict)
9 |
10 |
11 | print("\n\n========== 예제 6.5 ==========")
12 | sample_dict = {"1":"테스트1", "2":"테스트2", "3":"테스트3"}
13 |
14 | a_test = sample_dict.copy()
15 | a_test["1"] = "변경하기"
16 |
17 | print("할당 %s" % a_test)
18 | print("원본 %s" % sample_dict)
19 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/condition_sample/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path.append("C:/Users/USER/PycharmProjects/week1/")
3 |
4 | from kiwoom.kiwoom import *
5 | from PyQt5.QtWidgets import *
6 |
7 | class Main():
8 | def __init__(self):
9 | print("Main() start")
10 |
11 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
12 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
13 | self.app.exec_() # 이벤트 루프 실행
14 |
15 | if __name__ == "__main__":
16 | Main()
17 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/condition_sample/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
--------------------------------------------------------------------------------
/교재학습코드_4쇄/condition_sample/config/kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/condition_sample/config/log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | import datetime
3 |
4 | class Logging():
5 | def __init__(self):
6 | self.logger = logging.getLogger(__name__)
7 |
8 | format = logging.Formatter("%(asctime)s | %(filename)s | %(lineno)s | %(levelname)s -> %(message)s")
9 |
10 | streamHandler = logging.StreamHandler()
11 | streamHandler.setFormatter(format)
12 | self.logger.addHandler(streamHandler)
13 |
14 | d_time = datetime.datetime.now()
15 | d_str = d_time.strftime("%Y-%m-%d")
16 | fileHandler = logging.FileHandler("log/"+d_str+".log", encoding="utf-8")
17 | fileHandler.setFormatter(format)
18 | self.logger.addHandler(fileHandler)
19 |
20 | self.logger.setLevel(level=logging.DEBUG)
--------------------------------------------------------------------------------
/교재학습코드_4쇄/condition_sample/config/slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxp-572370529330-573807301142-572331691188-####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/condition_sample/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/2.49___init__.py:
--------------------------------------------------------------------------------
1 | from kiwoom.kiwoom import *
2 |
3 | class Main():
4 | def __init__(self):
5 | print("Main() start")
6 |
7 | Kiwoom()
8 |
9 | if __name__ == "__main__":
10 | Main()
11 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/3.1___init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | from kiwoom.kiwoom import *
4 | from PyQt5.QtWidgets import *
5 |
6 | class Main():
7 | def __init__(self):
8 | print("Main() start")
9 |
10 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
11 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
12 | self.app.exec_() # 이벤트 루프 실행
13 |
14 | if __name__ == "__main__":
15 | Main()
16 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/8.5_kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path.append("C:/Users/USER/PycharmProjects/week1/")
3 |
4 | from kiwoom.kiwoom import *
5 | from PyQt5.QtWidgets import *
6 |
7 | class Main():
8 | def __init__(self):
9 | print("Main() start")
10 |
11 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
12 | self.kiwoom = Kiwoom() # 키움 클래스 객체화
13 | self.app.exec_() # 이벤트 루프 실행
14 |
15 |
16 | if __name__ == "__main__":
17 | Main()
18 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/4.3_errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
38 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/7.4_kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/8.1_log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | import datetime
3 |
4 | class Logging():
5 | def __init__(self):
6 | self.logger = logging.getLogger(__name__)
7 |
8 | format = logging.Formatter("%(asctime)s | %(filename)s | %(lineno)s | %(levelname)s -> %(message)s")
9 |
10 | streamHandler = logging.StreamHandler()
11 | streamHandler.setFormatter(format)
12 | self.logger.addHandler(streamHandler)
13 |
14 | d_time = datetime.datetime.now()
15 | d_str = d_time.strftime("%Y-%m-%d")
16 | fileHandler = logging.FileHandler("log/"+d_str+".log", encoding="utf-8")
17 | fileHandler.setFormatter(format)
18 | self.logger.addHandler(fileHandler)
19 |
20 | self.logger.setLevel(level=logging.DEBUG)
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/8.3_slack.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | class MyMsg():
4 | def send_msg(self, msg=""):
5 | response = requests.post(
6 | 'https://slack.com/api/chat.postMessage',
7 | headers={
8 | 'Authorization': 'Bearer '+'토큰 복사하기'
9 | },
10 | data={
11 | 'channel':'#realmessage',
12 | 'text':msg
13 | }
14 | )
15 | print(response)
16 |
17 | MyMsg().send_msg(msg="슬랙으로 전송하기")
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
38 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
114 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/log_class.py:
--------------------------------------------------------------------------------
1 | import logging.config
2 | from datetime import datetime
3 |
4 | class Logging():
5 | def __init__(self, config_path='config/logging.conf', log_path='log'):
6 | self.config_path = config_path
7 | self.log_path = log_path
8 |
9 | logging.config.fileConfig(self.config_path)
10 | self.logger = logging.getLogger('Kiwoom')
11 | self.kiwoom_log()
12 |
13 | #로그설정
14 | def kiwoom_log(self):
15 | fh = logging.FileHandler(self.log_path+'/{:%Y-%m-%d}.log'.format(datetime.now()), encoding="utf-8")
16 | formatter = logging.Formatter('[%(asctime)s] I %(filename)s | %(name)s-%(funcName)s-%(lineno)04d I %(levelname)-8s > %(message)s')
17 |
18 | fh.setFormatter(formatter)
19 | self.logger.addHandler(fh)
20 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/config/slack.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | class MyMsg():
4 | def send_msg(self, msg=""):
5 | response = requests.post(
6 | 'https://slack.com/api/chat.postMessage',
7 | headers={
8 | 'Authorization': 'Bearer '+'토큰 복사하기'
9 | },
10 | data={
11 | 'channel':'#realmessage',
12 | 'text':msg
13 | }
14 | )
15 | print(response)
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/2.50_kiwoom.py:
--------------------------------------------------------------------------------
1 | class Kiwoom():
2 | def __init__(self):
3 | print("Kiwoom() class start.")
4 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/3.2_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 |
3 | class Kiwoom(QAxWidget):
4 | def __init__(self):
5 | super().__init__()
6 | print("Kiwoom() class start.")
7 |
8 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
9 |
10 | def get_ocx_instance(self):
11 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
12 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.10_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 | self.OnReceiveTrData.connect(self.trdata_slot) # 트랜잭션 요청 관련 이벤트
41 |
42 | def signal_login_commConnect(self):
43 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
44 |
45 | self.login_event_loop.exec_() # 이벤트 루프 실행
46 |
47 | def login_slot(self, err_code):
48 | print(errors(err_code)[1])
49 |
50 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
51 | self.login_event_loop.exit()
52 |
53 | def get_account_info(self):
54 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
55 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
56 |
57 | self.account_num = account_num
58 |
59 | print("계좌번호 : %s" % account_num)
60 |
61 | def detail_account_info(self, sPrevNext="0"):
62 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
64 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
65 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
66 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
67 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.11_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 | self.OnReceiveTrData.connect(self.trdata_slot) # 트랜잭션 요청 관련 이벤트
41 |
42 | def signal_login_commConnect(self):
43 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
44 |
45 | self.login_event_loop.exec_() # 이벤트 루프 실행
46 |
47 | def login_slot(self, err_code):
48 | print(errors(err_code)[1])
49 |
50 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
51 | self.login_event_loop.exit()
52 |
53 | def get_account_info(self):
54 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
55 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
56 |
57 | self.account_num = account_num
58 |
59 | print("계좌번호 : %s" % account_num)
60 |
61 | def detail_account_info(self, sPrevNext="0"):
62 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
64 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
65 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
66 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
67 |
68 |
69 | def trdata_slot(self, sScrNo, sRQName, sTrCode, sRecordName, sPrevNext):
70 |
71 | if sRQName == "예수금상세현황요청":
72 | deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "예수금")
73 | self.deposit = int(deposit)
74 |
75 | use_money = float(self.deposit) * self.use_money_percent
76 | self.use_money = int(use_money)
77 | self.use_money = self.use_money / 4
78 |
79 | output_deposit = self.dynamicCall("GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "출금가능금액")
80 | self.output_deposit = int(output_deposit)
81 |
82 | print("예수금 : %s" % self.output_deposit)
83 |
84 | self.stop_screen_cancel(self.screen_my_info)
85 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.1_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 |
4 | class Kiwoom(QAxWidget):
5 | def __init__(self):
6 | super().__init__()
7 | print("Kiwoom() class start.")
8 |
9 | ######### 초기 셋팅 함수들 바로 실행
10 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
11 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
12 | self.signal_login_commConnect() # 로그인 요청 함수 포함
13 | #########################################
14 |
15 | def get_ocx_instance(self):
16 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
17 |
18 | def event_slots(self):
19 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
20 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.2_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 |
4 | class Kiwoom(QAxWidget):
5 | def __init__(self):
6 | super().__init__()
7 | print("Kiwoom() class start.")
8 |
9 | ####### event loop를 실행하기 위한 변수 모음
10 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
11 | #########################################
12 |
13 | ######### 초기 셋팅 함수들 바로 실행
14 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
15 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
16 | self.signal_login_commConnect() # 로그인 요청 함수 포함
17 | #########################################
18 |
19 | def get_ocx_instance(self):
20 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
21 |
22 | def event_slots(self):
23 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
24 |
25 | def login_slot(self, err_code):
26 | print(errors(err_code)[1])
27 |
28 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
29 | self.login_event_loop.exit()
30 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.4_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def login_slot(self, err_code):
27 | print(errors(err_code)[1])
28 |
29 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
30 | self.login_event_loop.exit()
31 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.5_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.6_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.7_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | #########################################
19 |
20 | def get_ocx_instance(self):
21 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
22 |
23 | def event_slots(self):
24 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
25 |
26 | def signal_login_commConnect(self):
27 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
28 |
29 | self.login_event_loop.exec_() # 이벤트 루프 실행
30 |
31 | def login_slot(self, err_code):
32 | print(errors(err_code)[1])
33 |
34 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
35 | self.login_event_loop.exit()
36 |
37 | def get_account_info(self):
38 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
39 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
40 |
41 | self.account_num = account_num
42 |
43 | print("계좌번호 : %s" % account_num)
44 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.8_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ######### 초기 셋팅 함수들 바로 실행
15 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
16 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
17 | self.signal_login_commConnect() # 로그인 요청 함수 포함
18 | self.get_account_info() #계좌번호 가져오기
19 | #########################################
20 |
21 | def get_ocx_instance(self):
22 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
23 |
24 | def event_slots(self):
25 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
26 |
27 | def signal_login_commConnect(self):
28 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
29 |
30 | self.login_event_loop.exec_() # 이벤트 루프 실행
31 |
32 | def login_slot(self, err_code):
33 | print(errors(err_code)[1])
34 |
35 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
36 | self.login_event_loop.exit()
37 |
38 | def get_account_info(self):
39 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
40 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
41 |
42 | self.account_num = account_num
43 |
44 | print("계좌번호 : %s" % account_num)
45 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoom/4.9_kiwoom.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QAxContainer import *
2 | from PyQt5.QtCore import *
3 | from config.errorCode import *
4 |
5 | class Kiwoom(QAxWidget):
6 | def __init__(self):
7 | super().__init__()
8 | print("Kiwoom() class start.")
9 |
10 | ####### event loop를 실행하기 위한 변수 모음
11 | self.login_event_loop = QEventLoop() # 로그인 요청용 이벤트 루프
12 | #########################################
13 |
14 | ####### 계좌 관련된 변수
15 | self.account_num = None #계좌번호 담아줄 변수
16 | self.deposit = 0 #예수금
17 | self.use_money = 0 #실제 투자에 사용할 금액
18 | self.use_money_percent = 0.5 #예수금에서 실제 사용할 비율
19 | self.output_deposit = 0 #출력가능 금액
20 | ########################################
21 |
22 | ####### 요청 스크린 번호
23 | self.screen_my_info = "2000" #계좌 관련한 스크린 번호
24 | ########################################
25 |
26 | ######### 초기 셋팅 함수들 바로 실행
27 | self.get_ocx_instance() # OCX 방식을 파이썬에 사용할 수 있게 반환해 주는 함수 실행
28 | self.event_slots() # 키움과 연결하기 위한 시그널 / 슬롯 모음
29 | self.signal_login_commConnect() # 로그인 요청 함수 포함
30 | self.get_account_info() #계좌번호 가져오기
31 |
32 | self.detail_account_info() # 예수금 요청 시그널 포함
33 | #########################################
34 |
35 | def get_ocx_instance(self):
36 | self.setControl("KHOPENAPI.KHOpenAPICtrl.1") # 레지스트리에 저장된 API 모듈 불러오기
37 |
38 | def event_slots(self):
39 | self.OnEventConnect.connect(self.login_slot) # 로그인 관련 이벤트
40 |
41 | def signal_login_commConnect(self):
42 | self.dynamicCall("CommConnect()") # 로그인 요청 시그널
43 |
44 | self.login_event_loop.exec_() # 이벤트 루프 실행
45 |
46 | def login_slot(self, err_code):
47 | print(errors(err_code)[1])
48 |
49 | #로그인 처리가 완료됐으면 이벤트 루프를 종료한다.
50 | self.login_event_loop.exit()
51 |
52 | def get_account_info(self):
53 | account_list = self.dynamicCall("GetLoginInfo(QString)", "ACCNO") # 계좌번호 반환
54 | account_num = account_list.split(';')[0] # a;b;c [a, b, c]
55 |
56 | self.account_num = account_num
57 |
58 | print("계좌번호 : %s" % account_num)
59 |
60 | def detail_account_info(self, sPrevNext="0"):
61 | self.dynamicCall("SetInputValue(QString, QString)", "계좌번호", self.account_num)
62 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호", "0000")
63 | self.dynamicCall("SetInputValue(QString, QString)", "비밀번호입력매체구분", "00")
64 | self.dynamicCall("SetInputValue(QString, QString)", "조회구분", "1")
65 | self.dynamicCall("CommRqData(QString, QString, int, QString)", "예수금상세현황요청", "opw00001", sPrevNext, self.screen_my_info)
66 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/교재학습코드_4쇄/example/log/2020-01-21.log:
--------------------------------------------------------------------------------
1 | [2020-01-21 11:27:21,183] I kiwoom.py | Kiwoom-__init__-0019 I DEBUG > Kiwoom() class start.
2 |
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | sys.path.append("C:/Users/USER/PycharmProjects/week1/")
3 |
4 | from kiwoom.kiwoom import *
5 | from PyQt5.QtWidgets import *
6 |
7 | class Main():
8 | def __init__(self):
9 | print("Main() start")
10 |
11 | self.app = QApplication(sys.argv) # PyQt5로 실행할 파일명을 자동 설정
12 | self.kiwoom = Kiwoom() # 키움 클래스 실행
13 | self.app.exec_() # 이벤트 루프 실행
14 |
15 |
16 | if __name__ == "__main__":
17 | Main()
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/config/kiwoomType.py:
--------------------------------------------------------------------------------
1 | class RealType(object):
2 | SENDTYPE = {
3 | '거래구분': {
4 | '지정가': '00',
5 | '시장가': '03',
6 | '조건부지정가': '05',
7 | '최유리지정가': '06',
8 | '최우선지정가': '07',
9 | '지정가IOC': '10',
10 | '시장가IOC': '13',
11 | '최유리IOC': '16',
12 | '지정가FOK': '20',
13 | '시장가FOK': '23',
14 | '최유리FOK': '26',
15 | '장전시간외종가': '61',
16 | '시간외단일가매매': '62',
17 | '장후시간외종가': '81'
18 | }
19 | }
20 |
21 | REALTYPE = {
22 |
23 | '주식체결': {
24 | '체결시간': 20,
25 | '현재가': 10, #체결가
26 | '전일대비': 11,
27 | '등락율': 12,
28 | '(최우선)매도호가': 27,
29 | '(최우선)매수호가': 28,
30 | '거래량': 15,
31 | '누적거래량': 13,
32 | '누적거래대금': 14,
33 | '시가': 16,
34 | '고가': 17,
35 | '저가': 18,
36 | '전일대비기호': 25,
37 | '전일거래량대비': 26,
38 | '거래대금증감': 29,
39 | '전일거래량대비': 30,
40 | '거래회전율': 31,
41 | '거래비용': 32,
42 | '체결강도': 228,
43 | '시가총액(억)': 311,
44 | '장구분': 290,
45 | 'KO접근도': 691,
46 | '상한가발생시간': 567,
47 | '하한가발생시간': 568
48 | },
49 |
50 | '장시작시간': {
51 | '장운영구분': 215,
52 | '시간': 20, #(HHMMSS)
53 | '장시작예상잔여시간':214
54 | },
55 |
56 | '주문체결': {
57 | '계좌번호': 9201,
58 | '주문번호': 9203,
59 | '관리자사번': 9205,
60 | '종목코드': 9001,
61 | '주문업무분류': 912, #(jj:주식주문)
62 | '주문상태': 913, #(접수, 확인, 체결) (10:원주문, 11:정정주문, 12:취소주문, 20:주문확인, 21:정정확인, 22:취소확인, 90,92:주문거부) #https://bbn.kiwoom.com/bbn.openAPIQnaBbsDetail.do
63 | '종목명': 302,
64 | '주문수량': 900,
65 | '주문가격': 901,
66 | '미체결수량': 902,
67 | '체결누계금액': 903,
68 | '원주문번호': 904,
69 | '주문구분': 905, #(+매수, -매도, -매도정정, +매수정정, 매수취소, 매도취소)
70 | '매매구분': 906, #(보통, 시장가등)
71 | '매도수구분': 907, # 매도(매도정정, 매도취도 포함)인 경우 1, 매수(매수정정, 매수취소 포함)인 경우 2
72 | '주문/체결시간': 908, #(HHMMSS)
73 | '체결번호': 909,
74 | '체결가': 910,
75 | '체결량': 911,
76 | '현재가': 10,
77 | '(최우선)매도호가': 27,
78 | '(최우선)매수호가': 28,
79 | '단위체결가': 914,
80 | '단위체결량': 915,
81 | '당일매매수수료': 938,
82 | '당일매매세금': 939,
83 | '거부사유': 919,
84 | '화면번호': 920,
85 | '터미널번호': 921,
86 | '신용구분(실시간 체결용)': 922,
87 | '대출일(실시간 체결용)': 923,
88 | },
89 |
90 | '매도수구분': {
91 | '1': '매도',
92 | '2': '매수'
93 | },
94 |
95 | '잔고': {
96 | '계좌번호': 9201,
97 | '종목코드': 9001,
98 | '종목명': 302,
99 | '현재가': 10,
100 | '보유수량': 930,
101 | '매입단가': 931,
102 | '총매입가': 932,
103 | '주문가능수량': 933,
104 | '당일순매수량': 945,
105 | '매도매수구분': 946,
106 | '당일총매도손익': 950,
107 | '예수금': 951,
108 | '(최우선)매도호가': 27,
109 | '(최우선)매수호가': 28,
110 | '기준가': 307,
111 | '손익율': 8019
112 | },
113 | }
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/config/log_class.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | import logging.config
4 | from datetime import datetime
5 |
6 | class Logging():
7 | def __init__(self, config_path='config/logging.conf', log_path='log'):
8 | self.config_path = config_path
9 | self.log_path = log_path
10 |
11 | logging.config.fileConfig(self.config_path)
12 | self.logger = logging.getLogger('Kiwoom')
13 | self.kiwoom_log()
14 |
15 | #로그설정
16 | def kiwoom_log(self):
17 | fh = logging.FileHandler(self.log_path+'/{:%Y-%m-%d}.log'.format(datetime.now()), encoding="utf-8")
18 | formatter = logging.Formatter('[%(asctime)s] I %(filename)s | %(name)s-%(funcName)s-%(lineno)04d I %(levelname)-8s > %(message)s')
19 |
20 | fh.setFormatter(formatter)
21 | self.logger.addHandler(fh)
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/config/slack.py:
--------------------------------------------------------------------------------
1 | from slacker import Slacker
2 |
3 | class Slack():
4 | def __init__(self):
5 | self.token = 'xoxb-1126585321985-1114180369955-#####################'
6 |
7 | def notification(self, pretext=None, title=None, fallback=None, text=None):
8 | attachments_dict = dict()
9 | attachments_dict['pretext'] = pretext #test1
10 | attachments_dict['title'] = title #test2
11 | attachments_dict['fallback'] = fallback #test3
12 | attachments_dict['text'] = text #test4
13 |
14 | attachments = [attachments_dict]
15 |
16 | slack = Slacker(self.token)
17 | slack.chat.post_message(channel='#realmessage', text=None, attachments=attachments, as_user=None)
18 |
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/files/condition_stock.txt:
--------------------------------------------------------------------------------
1 | 094360 칩스앤미디어 9610
2 | 089010 켐트로닉스 17750
3 | 078070 유비쿼스홀딩스 30550
4 | 024060 흥구석유 6540
5 | 170030 현대공업 4010
6 | 196300 애니젠 12000
7 | 001340 백광산업 3540
8 | 060720 KH바텍 21650
9 |
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/license.txt:
--------------------------------------------------------------------------------
1 | Library name: programgarden_coding
2 | Copyright (C) 2019-05-01, Yong-Joon Jang
3 | Contact: stockisgame@gmail.com
4 |
5 | 본 교육용 코드, 영상자료, 이미지자료는 Free software license 기준을 따르지 않습니다.
6 | 그러므로 무단배포 및 상업적 이용을 금지합니다.
7 | 그리고 수정배포 및 상업적 이용으로는 저작권자의 허가가 필요합니다.
8 |
9 | 라이브러리를 제공받으면 위 라이선스에 동의됩니다.
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/log/2020-01-21.log:
--------------------------------------------------------------------------------
1 | [2020-01-21 11:27:21,183] I kiwoom.py | Kiwoom-__init__-0019 I DEBUG > Kiwoom() class start.
2 |
--------------------------------------------------------------------------------
/사용하지않는 코드/완성된코드/week1/log/2020-12-20.log:
--------------------------------------------------------------------------------
1 | 2020-12-20 00:33:24,939 | kiwoom.py | 20 | DEBUG -> Kiwoom() class start.
--------------------------------------------------------------------------------
/사용하지않는 코드/조건검색코드/condition_sample/__init__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from kiwoom.kiwoom import *
3 | from PyQt5.QtWidgets import *
4 |
5 | class Main():
6 | def __init__(self):
7 | print("Main() start")
8 |
9 | self.app = QApplication(sys.argv)
10 | self.kiwoom = Kiwoom()
11 | self.app.exec_()
12 |
13 | if __name__ == "__main__":
14 | Main()
--------------------------------------------------------------------------------
/사용하지않는 코드/조건검색코드/condition_sample/config/errorCode.py:
--------------------------------------------------------------------------------
1 | def errors(err_code):
2 |
3 | err_dic = {0:('OP_ERR_NONE', '정상처리'),
4 | -10:('OP_ERR_FAIL', '실패'),
5 | -100:('OP_ERR_LOGIN', '사용자정보교환실패'),
6 | -101:('OP_ERR_CONNECT', '서버접속실패'),
7 | -102:('OP_ERR_VERSION', '버전처리실패'),
8 | -103:('OP_ERR_FIREWALL', '개인방화벽실패'),
9 | -104:('OP_ERR_MEMORY', '메모리보호실패'),
10 | -105:('OP_ERR_INPUT', '함수입력값오류'),
11 | -106:('OP_ERR_SOCKET_CLOSED', '통신연결종료'),
12 | -200:('OP_ERR_SISE_OVERFLOW', '시세조회과부하'),
13 | -201:('OP_ERR_RQ_STRUCT_FAIL', '전문작성초기화실패'),
14 | -202:('OP_ERR_RQ_STRING_FAIL', '전문작성입력값오류'),
15 | -203:('OP_ERR_NO_DATA', '데이터없음'),
16 | -204:('OP_ERR_OVER_MAX_DATA', '조회가능한종목수초과'),
17 | -205:('OP_ERR_DATA_RCV_FAIL', '데이터수신실패'),
18 | -206:('OP_ERR_OVER_MAX_FID', '조회가능한FID수초과'),
19 | -207:('OP_ERR_REAL_CANCEL', '실시간해제오류'),
20 | -300:('OP_ERR_ORD_WRONG_INPUT', '입력값오류'),
21 | -301:('OP_ERR_ORD_WRONG_ACCTNO', '계좌비밀번호없음'),
22 | -302:('OP_ERR_OTHER_ACC_USE', '타인계좌사용오류'),
23 | -303:('OP_ERR_MIS_2BILL_EXC', '주문가격이20억원을초과'),
24 | -304:('OP_ERR_MIS_5BILL_EXC', '주문가격이50억원을초과'),
25 | -305:('OP_ERR_MIS_1PER_EXC', '주문수량이총발행주수의1 % 초과오류'),
26 | -306:('OP_ERR_MIS_3PER_EXC', '주문수량은총발행주수의3 % 초과오류'),
27 | -307:('OP_ERR_SEND_FAIL', '주문전송실패'),
28 | -308:('OP_ERR_ORD_OVERFLOW', '주문전송과부하'),
29 | -309:('OP_ERR_MIS_300CNT_EXC', '주문수량300계약초과'),
30 | -310:('OP_ERR_MIS_500CNT_EXC', '주문수량500계약초과'),
31 | -340:('OP_ERR_ORD_WRONG_ACCTINFO', '계좌정보없음'),
32 | -500:('OP_ERR_ORD_SYMCODE_EMPTY', '종목코드없음')
33 | }
34 |
35 | result = err_dic[err_code]
36 |
37 | return result
--------------------------------------------------------------------------------
/사용하지않는 코드/조건검색코드/condition_sample/config/log_class.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | import logging.config
4 | from datetime import datetime
5 |
6 | class Logging():
7 | def __init__(self, config_path='config/logging.conf', log_path='log'):
8 | self.config_path = config_path
9 | self.log_path = log_path
10 |
11 | logging.config.fileConfig(self.config_path)
12 | self.logger = logging.getLogger('Kiwoom')
13 | self.kiwoom_log()
14 |
15 | #로그설정
16 | def kiwoom_log(self):
17 | fh = logging.FileHandler(self.log_path+'/{:%Y-%m-%d}.log'.format(datetime.now()), encoding="utf-8")
18 | formatter = logging.Formatter('[%(asctime)s] I %(filename)s | %(name)s-%(funcName)s-%(lineno)04d I %(levelname)-8s > %(message)s')
19 |
20 | fh.setFormatter(formatter)
21 | self.logger.addHandler(fh)
--------------------------------------------------------------------------------
/사용하지않는 코드/조건검색코드/condition_sample/config/logging.conf:
--------------------------------------------------------------------------------
1 | [loggers]
2 | keys=root, Kiwoom
3 |
4 | [handlers]
5 | keys=consoleHandler
6 |
7 | [formatters]
8 | keys=consoleFormatter
9 |
10 | [logger_root]
11 | level=DEBUG
12 | handlers=consoleHandler
13 |
14 | [logger_Kiwoom]
15 | level=DEBUG
16 | handlers=consoleHandler
17 | qualname=Kiwoom
18 | propagate=0
19 |
20 | [handler_consoleHandler]
21 | class=StreamHandler
22 | level=DEBUG
23 | formatter=consoleFormatter
24 | args=(sys.stdout,)
25 |
26 | [formatter_consoleFormatter]
27 | format=%(asctime)s | %(levelname)-8s | %(filename)s-%(funcName)s-%(lineno)04d | %(message)s
28 | datefmt=
--------------------------------------------------------------------------------
/사용하지않는 코드/조건검색코드/condition_sample/files/condition_stock.txt:
--------------------------------------------------------------------------------
1 | 094360 칩스앤미디어 9610
2 |
--------------------------------------------------------------------------------
/사용하지않는 코드/조건검색코드/condition_sample/kiwoomStart.bat:
--------------------------------------------------------------------------------
1 | @ECHO ON
2 | title Kiwoom Start
3 |
4 | cd C:\Users\USER\PycharmProjects\week1
5 |
6 | call activate py37_32
7 | python __init__.py
8 |
9 | cmd.exe
10 |
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_1week/basic_v1.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.1 ==========")
2 | print("Hello world")
3 |
4 |
5 | print("\n\n========== 예제 2.2 ==========")
6 | print("Hello world")
7 | #Hello world
8 |
9 |
10 | print("\n\n========== 예제 2.3 ==========")
11 | print("Hello world" + " Thank you")
12 | #Hello world Thank you
13 |
14 |
15 | print("\n\n========== 예제 2.4 ==========")
16 | print(900629)
17 | #900629
18 |
19 |
20 | print("\n\n========== 예제 2.5 ==========")
21 | print("%s 입니다." % "홍길동")
22 | #홍길동 입니다.
23 | print("%s 입니다." % "이순신")
24 | #이순신 입니다.
25 | print("%s원 입니다." % 5000)
26 | #5000원 입니다.
27 |
28 |
29 | print("\n\n========== 예제 2.6 ==========")
30 | print("이름은 %s 이고 %s에 삽니다." % ("홍길동", "서울"))
31 | #이름은 홍길동 이고 서울에 삽니다.
32 |
33 |
34 | print("\n\n========== 예제 2.7 ==========")
35 | #int 변수, 최대값 : 9223372036854775807
36 | stock_price = 3900
37 | print(stock_price)
38 | stock_price = 4500
39 | print(stock_price)
40 | stock_price_type = type(stock_price) #
41 | print(stock_price_type)
42 |
43 |
44 | print("\n\n========== 예제 2.8 ==========")
45 | #float 변수
46 | stock_percent = 3.8 # 3.8
47 | print(stock_percent)
48 | stock_percent_type = type(stock_percent) #
49 | print(stock_percent_type)
50 |
51 |
52 | print("\n\n========== 예제 2.9 ==========")
53 | #string 변수
54 | stock_name = "홀딩스" # 홀딩스
55 | print(stock_name)
56 | stock_name_type = type(stock_name) #
57 | print(stock_name_type)
58 | stock_name = "3900" # 3900
59 | print(stock_name)
60 | stock_name_type = type(stock_name) #
61 | print(stock_name_type)
62 |
63 |
64 | print("\n\n========== 예제 2.10 ==========")
65 | #bool 변수
66 | stock_buy = False
67 | print(stock_buy)
68 | stock_buy_type = type(stock_buy) #
69 | print(stock_buy_type)
70 |
71 |
72 | print("\n\n========== 예제 2.11 ==========")
73 | stock_price = 2000
74 | stock_price2 = 2500
75 | stock_result = stock_price + stock_price2
76 | print(stock_result) # 4500
77 |
78 |
79 | print("\n\n========== 예제 2.12 ==========")
80 | stock_price = 2000
81 | stock_price2 = 1000
82 | stock_result= stock_price - stock_price2
83 | print(stock_result) # 1000
84 |
85 |
86 | print("\n\n========== 예제 2.13 ==========")
87 | stock_price = 1000
88 | stock_price2 = 1200
89 | stock_result = stock_price * stock_price2
90 | print(stock_result) # 1200000
91 |
92 |
93 | print("\n\n========== 예제 2.14 ==========")
94 | stock_price = 2000
95 | stock_price2 = 2200
96 | stock_result = stock_price / stock_price2
97 | print(stock_result) # 0.9090909090909091
98 | stock_result = stock_price // stock_price2
99 | print(stock_result) # 0
100 |
101 |
102 | print("\n\n========== 예제 2.15 ==========")
103 | stock_price = 1000
104 | stock_price2 = 900
105 | stock_result = stock_price % stock_price2
106 | print(stock_result) # 100
107 |
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_1week/basic_v1_problem.py:
--------------------------------------------------------------------------------
1 | print("========== 문제 1 ==========")
2 | stock_name = "키움증권"
3 | stock_price = 3900
4 | stock_percent = 3.8
5 | print("주식이름 : %s, 가격 : %s원, 등락율 : %s" % (stock_name, stock_price, stock_percent))
6 |
7 |
8 | print("\n\n========== 문제 2 ==========")
9 | print("등락율 : %s %%" % stock_percent)
10 | print("등락율 : %s %s" % (stock_percent, "%"))
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_2week/basic_v2.py:
--------------------------------------------------------------------------------
1 | print("========== 예제 2.16 ==========")
2 | stock_name = "키움증권"
3 | if stock_name == "키움증권":
4 | print("통과!")
5 |
6 |
7 | print("\n\n========== 예제 2.17 ==========")
8 | stock_price = 3000
9 | if stock_price > 3000:
10 | print("통과!1")
11 | elif stock_price >= 3000:
12 | print("통과!2")
13 | elif stock_price <= 3000:
14 | print("통과!3")
15 | else:
16 | print("조건에 해당하는 게 없음!")
17 |
18 |
19 | print("\n\n========== 예제 2.18 ==========")
20 | stock_price = 3000
21 | if stock_price < 3000 or stock_price >= 3000:
22 | print("둘 중 아무거나 맞으면 출력")
23 |
24 | print("\n\n========== 예제 2.19 ==========")
25 | stock_price = 3000
26 | if stock_price > 2000 or stock_price < 2500:
27 | print("2000~2500 사이")
28 | elif stock_price >= 2500 and stock_price <= 3000:
29 | print("2500~3000 사이")
30 |
31 | stock_price = 3000
32 | if stock_price > 2000 and stock_price <= 3000:
33 | print("2001~3000 사이")
34 | elif stock_price > 3000 and stock_price <= 4000:
35 | print("3001~4000 사이")
36 |
37 |
38 | print("\n\n========== 예제 2.20 ==========")
39 | for i in range(5, 100):
40 | print(i)
41 |
42 |
43 | print("\n\n========== 예제 2.21 ==========")
44 | for i in range(5, 100):
45 | print(i)
46 |
47 | if i == 50:
48 | break
49 |
50 | print("\n\n========== 예제 2.22 ==========")
51 | for i in range(0, 10):
52 | for k in range(0, 5):
53 | print("for 문 안에 for 문 %s" % k)
54 |
55 |
56 | print("\n\n========== 예제 2.23 ==========")
57 | stock_buy = True
58 | count = 0
59 | while stock_buy:
60 | count = count + 1
61 |
62 | if count == 10:
63 | break
64 |
65 | print(count)
66 |
67 |
68 | print("\n\n========== 예제 2.24 ==========")
69 | stock_buy = True
70 | count = 0
71 | while stock_buy:
72 | count = count + 1
73 |
74 | if count == 10:
75 | # break
76 | stock_buy = False
77 |
78 | print(count)
79 |
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_2week/basic_v2_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 3 ==========")
2 | kakao_price = 1000
3 | kiwoom_price = 500
4 |
5 | for i in range(0, 3):
6 | kakao_price += 500
7 | kiwoom_price += 1000
8 |
9 | if kakao_price > kiwoom_price:
10 | print("카카오가 더 높다")
11 | elif kakao_price < kiwoom_price:
12 | print("키움이 더 높다")
13 | elif kakao_price == kiwoom_price:
14 | print("키움과 카카오가 같다")
15 |
16 |
17 | print("\n\n========== 문제 4 ==========")
18 | for i in range(1, 10):
19 | for j in range(1, 10):
20 | result = i * j
21 | print("%s x %s = %s" % (i, j, result))
22 |
23 |
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_3week/basic_v3.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.25 ==========")
3 | a_list = ("키움", "카카오", "대신")
4 | for val in a_list:
5 | print(val)
6 |
7 |
8 | print("\n\n========== 예제 2.26 ==========")
9 | a_list = ["키움", "카카오", "네이버"]
10 | for val in a_list:
11 | print(val)
12 |
13 |
14 | print("\n\n========== 예제 2.27 ==========")
15 | a_list = ["키움", "카카오", "네이버"]
16 | a_list.append("대신증권")
17 | for val in a_list:
18 | print(val)
19 |
20 |
21 | print("\n\n========== 예제 2.28 ==========")
22 | print(a_list[0])
23 |
24 |
25 | print("\n\n========== 예제 2.29 ==========")
26 | a_list = ["키움", "카카오", "네이버"] #list
27 | print(a_list)
28 | a_list[2] = "다음" #수정하기
29 | print(a_list)
30 | del a_list[1] #삭제하기
31 | print(a_list)
32 |
33 |
34 | print("\n\n========== 예제 2.30 ==========")
35 | a_list = ["키움", "카카오", "네이버"]
36 | for idx, val in enumerate(a_list):
37 | print("인덱스: %s, 값: %s" % (idx, val))
38 |
39 |
40 | print("\n\n========== 예제 2.31 ==========")
41 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
42 | print(a_dict.get("키움증권")) # 1300
43 | print(a_dict['키움증권']) # 1300
44 |
45 |
46 | print("\n\n========== 예제 2.32 ==========")
47 | for key in a_dict.keys():
48 | print(a_dict.get(key))
49 |
50 |
51 | print("\n\n========== 예제 2.33 ==========")
52 | for key, value in a_dict.items(): #key와 value 값 모두 가져옴
53 | print("키값 : %s , value값 : %s" % (key, value))
54 |
55 |
56 | print("\n\n========== 예제 2.34 ==========")
57 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
58 | a_dict["다음증권"] = 2500
59 | print(a_dict)
60 |
61 |
62 | print("\n\n========== 예제 2.35 ==========")
63 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
64 | a_dict.update({"다음증권":2500})
65 | print(a_dict)
66 |
67 |
68 | print("\n\n========== 예제 2.36 ==========")
69 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
70 | a_dict["다음증권"] = 2500
71 | a_dict["애플"] = 152000
72 | a_dict["삼성"] = 221500
73 | a_dict["LG"] = 25800
74 | print(a_dict)
75 |
76 |
77 | print("\n\n========== 예제 2.37 ==========")
78 | a_dict = {"키움증권":1300, "카카오증권":1500, "네이버증권":1000}
79 | a_dict.update({"다음증권":2000, "애플":152000, "삼성":221500, "LG":25800})
80 | print(a_dict)
81 |
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_3week/basic_v3_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 5 ==========")
2 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
3 | a_plus = 0
4 | for val in a_dict.keys():
5 | a_plus = a_plus + a_dict[val] # a_plus += a_dict[val] 형태와 같다
6 | print("종목 : %s, 가격: %s " % (val, a_dict[val]))
7 | print("더한값 %s " % a_plus)
8 |
9 |
10 | print("\n\n========== 문제 6 ==========")
11 | a_dict = {"키움증권": 5000, "카카오": 3000, "네이버": 2000}
12 | my_account = 111000
13 | for val in a_dict.keys():
14 | if val == "키움증권":
15 | my_account = my_account - a_dict[val] * 5
16 | elif val == "카카오":
17 | my_account -= a_dict[val] * 2
18 | elif val == "네이버":
19 | my_account -= a_dict[val] * 5
20 |
21 | print("남은 금액 : %s " % my_account)
22 |
23 |
24 | print("\n\n========== 문제 7 ==========")
25 | a_dict = {"키움증권" : 5000, "카카오" : 3000, "네이버" : 2000}
26 | ee_bool = True
27 | while ee_bool:
28 | a_dict['키움증권'] = a_dict['키움증권'] + 1000
29 |
30 | if a_dict['키움증권'] == 10000:
31 | a_dict.update({"이베스트증권" : 5000})
32 | break
33 |
34 | print(a_dict)
35 |
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_4week/basic_v4.py:
--------------------------------------------------------------------------------
1 |
2 | print("\n\n========== 예제 2.38 ==========")
3 | def english():
4 | print("영어과입니다.")
5 | english()
6 |
7 |
8 | print("\n\n========== 예제 2.39 ==========")
9 | def math(student_name):
10 | print(student_name)
11 | math("토마스")
12 |
13 |
14 | print("\n\n========== 예제 2.40 ==========")
15 | def academy(student_name1, student_name2, student_name3):
16 | print(student_name1)
17 | print(student_name2)
18 | print(student_name3)
19 |
20 | academy("토마스", "에디슨", "빌리")
21 |
22 |
23 | print("\n\n========== 예제 2.41 ==========")
24 | def english(help):
25 | help()
26 |
27 | def help():
28 | print("도와주러 왔습니다.")
29 |
30 | english(help)
31 |
32 |
33 | print("\n\n========== 예제 2.42 ==========")
34 | def math():
35 | name = "광수"
36 | return name
37 |
38 | who = math()
39 | print(who)
40 |
41 |
42 | print("\n\n========== 예제 2.43 ==========")
43 | def multi():
44 | return "a", "b"
45 |
46 | a, b = multi()
47 | result = multi()
48 | print(result)
49 |
50 |
51 | print("\n\n========== 예제 2.44 ==========")
52 | class B_school():
53 | def __init__(self):
54 | print("b대학교 초기화")
55 |
56 | B_school()
57 |
58 |
59 | print("\n\n========== 예제 2.45 ==========")
60 | class A_school():
61 | def __init__(self):
62 | print("초기화, 생성자")
63 | self.student1_name = None
64 | self.student2_name = None
65 |
66 | print(dir(self))
67 |
68 | A_school()
69 |
70 |
71 | print("\n\n========== 예제 2.46 ==========")
72 | class A_school():
73 | def __init__(self):
74 | print("초기화, 생성자")
75 | self.student1_name = None
76 |
77 | b = self.math()
78 | print("수학과 학생 %s" % b)
79 |
80 | def math(self):
81 | self.student1_name = "영수"
82 | name = self.student1_name
83 |
84 | return name
85 |
86 |
87 | print("\n\n========== 예제 2.47 ==========")
88 | class B_school():
89 | def __init__(self):
90 | print("b대학교 초기화")
91 |
92 | self.school_name = "b학교"
93 |
94 | class A_school():
95 | def __init__(self):
96 | print("초기화, 생성자")
97 | self.student1_name = None
98 |
99 | b = self.math()
100 | print("수학과 학생 %s" % b)
101 |
102 | b_school = B_school()
103 | print(b_school.school_name)
104 |
105 | def math(self):
106 | self.student1_name = "영수"
107 | name = self.student1_name
108 |
109 | return name
110 |
111 | A_school()
112 |
113 |
114 | print("\n\n========== 예제 2.48 ==========")
115 | class Parent():
116 | def __init__(self):
117 | print("부모입니다.")
118 |
119 | self.money = 50000000
120 |
121 | def home(self):
122 | return "부모의 집"
123 |
124 | class ChildA(Parent):
125 | def __init__(self):
126 | print("자식A")
127 |
128 | print("부모의 돈을 물려받을 수 없습니다.")
129 | print("%s을 물려받았습니다." % self.home())
130 |
131 | class ChildB(Parent):
132 | def __init__(self):
133 | super().__init__()
134 | print("자식B")
135 |
136 | print("부모의 돈 %s" % self.money)
137 | print("%s을 물려받았습니다." % self.home())
138 |
139 | ChildA()
140 | ChildB()
141 |
--------------------------------------------------------------------------------
/사용하지않는 코드/파이썬기초/week1/basic_4week/basic_v4_problem.py:
--------------------------------------------------------------------------------
1 | print("\n\n========== 문제 8 ==========")
2 | class Condition():
3 | def sell_filtering(self, my_dict):
4 | for key in my_dict.keys():
5 | if 5000 >= my_dict[key]:
6 | print("종목 %s, 가격 %s" % (key, my_dict[key]))
7 |
8 | class Kiwoom():
9 | def __init__(self):
10 | self.my_dict = {"네이버":6000, "애플":15000, "다음":3000, "넷플릭스":5000, "구글":100000, "삼성":3000, "LG":1000, "키움":500, "호랑":8000, "셀트리온":8500, "코난":6050, "컬링":1000, "하이원":3200}
11 |
12 | condition = Condition()
13 | condition.sell_filtering(self.my_dict)
14 |
15 | Kiwoom()
16 |
17 | print("\n\n========== 문제 9 ==========")
18 | class Condition():
19 | def sell_filtering(self, my_dict):
20 | for key in my_dict.keys():
21 | if key == "넷플릭스":
22 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
23 |
24 | elif key == "애플":
25 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
26 |
27 | elif key == "구글":
28 | my_dict[key].update({'보유량':int(my_dict[key]['보유량']/2)})
29 |
30 | return my_dict
31 |
32 | class Kiwoom():
33 | def __init__(self):
34 | self.my_dict = {'네이버':{'현재가':3000, '보유량':100}, '애플':{'현재가':10000, '보유량':200}, '다음':{'현재가':4000, '보유량':50}, '넷플릭스':{'현재가':7000, '보유량':200}, '구글':{'현재가':13000, '보유량':30}}
35 |
36 | condition = Condition()
37 | result = condition.sell_filtering(self.my_dict)
38 | print(result)
39 |
40 | Kiwoom()
41 |
--------------------------------------------------------------------------------
/키움API 주문접수_확인_체결 참고자료/매도후 매도취소.txt:
--------------------------------------------------------------------------------
1 | 2019-07-12 14:14:12,011 | DEBUG | kiwoom.py-chejan_slot-0094 |
2 | ========== 주문체결 0번 ====== 057880
3 | 계좌번호: 8117558311
4 | 주문번호: 0098984
5 | 관리자사번:
6 | 종목코드: A057880
7 | 주문업무분류: JJ
8 | 주문상태: 접수
9 | 종목명: 필로시스헬스케어
10 | 주문수량: 20
11 | 주문가격: 2130
12 | 미체결수량: 20
13 | 체결누계금액: 0
14 | 원주문번호: 0000000
15 | 주문구분: -매도
16 | 매매구분: 보통
17 | 매도수구분: 1
18 | 주문/체결시간: 141407
19 | 체결번호:
20 | 체결가:
21 | 체결량:
22 | 현재가: +2115
23 | (최우선)매도호가: +2115
24 | (최우선)매수호가: +2100
25 | 단위체결가:
26 | 단위체결량:
27 | 당일매매수수료: 0
28 | 당일매매세금: 0
29 | 거부사유: 0
30 | 화면번호: 4989
31 | 터미널번호: 0707047
32 | 신용구분(실시간 체결용): 00
33 | 대출일(실시간 체결용): 00000000
34 |
35 | 1
36 | 2019-07-12 14:14:12,012 | DEBUG | kiwoom.py-chejan_slot-0119 |
37 | ========== 잔고 1번 ======
38 | 계좌번호: 8117558311
39 | 종목코드: A057880
40 | 종목명: 필로시스헬스케어
41 | 현재가: +2115
42 | 보유수량: 20
43 | 매입단가: 2335
44 | 총매입가: 46700
45 | 주문가능수량: 0
46 | 당일순매수량: 0
47 | 매도매수구분: 1
48 | 당일총매도손익: -33599
49 | 예수금: 0
50 | (최우선)매도호가: +2115
51 | (최우선)매수호가: +2100
52 | 기준가: 2080
53 | 손익율: -4.18
54 |
55 | 0
56 | 2019-07-12 14:14:19,419 | DEBUG | kiwoom.py-chejan_slot-0094 |
57 | ========== 주문체결 0번 ====== 057880
58 | 계좌번호: 8117558311
59 | 주문번호: 0099039
60 | 관리자사번:
61 | 종목코드: A057880
62 | 주문업무분류: JJ
63 | 주문상태: 접수
64 | 종목명: 필로시스헬스케어
65 | 주문수량: 20
66 | 주문가격: 0
67 | 미체결수량: 20
68 | 체결누계금액: 0
69 | 원주문번호: 0098984
70 | 주문구분: 매도취소
71 | 매매구분: 보통
72 | 매도수구분: 1
73 | 주문/체결시간: 141415
74 | 체결번호:
75 | 체결가:
76 | 체결량:
77 | 현재가: +2115
78 | (최우선)매도호가: +2115
79 | (최우선)매수호가: +2100
80 | 단위체결가:
81 | 단위체결량:
82 | 당일매매수수료: 0
83 | 당일매매세금: 0
84 | 거부사유: 0
85 | 화면번호: 0341
86 | 터미널번호: 0707047
87 | 신용구분(실시간 체결용): 00
88 | 대출일(실시간 체결용): 00000000
89 |
90 | 0
91 | 2019-07-12 14:14:19,420 | DEBUG | kiwoom.py-chejan_slot-0094 |
92 | ========== 주문체결 0번 ====== 057880
93 | 계좌번호: 8117558311
94 | 주문번호: 0099039
95 | 관리자사번:
96 | 종목코드: A057880
97 | 주문업무분류: JJ
98 | 주문상태: 확인
99 | 종목명: 필로시스헬스케어
100 | 주문수량: 20
101 | 주문가격: 0
102 | 미체결수량: 0
103 | 체결누계금액: 0
104 | 원주문번호: 0098984
105 | 주문구분: 매도취소
106 | 매매구분: 보통
107 | 매도수구분: 1
108 | 주문/체결시간: 141415
109 | 체결번호:
110 | 체결가:
111 | 체결량:
112 | 현재가: +2115
113 | (최우선)매도호가: +2115
114 | (최우선)매수호가: +2100
115 | 단위체결가:
116 | 단위체결량:
117 | 당일매매수수료: 0
118 | 당일매매세금: 0
119 | 거부사유: 0
120 | 화면번호: 0341
121 | 터미널번호: 0707047
122 | 신용구분(실시간 체결용): 00
123 | 대출일(실시간 체결용): 00000000
124 |
125 | 0
126 | 2019-07-12 14:14:19,421 | DEBUG | kiwoom.py-chejan_slot-0094 |
127 | ========== 주문체결 0번 ====== 057880
128 | 계좌번호: 8117558311
129 | 주문번호: 0098984
130 | 관리자사번:
131 | 종목코드: A057880
132 | 주문업무분류: JJ
133 | 주문상태: 접수
134 | 종목명: 필로시스헬스케어
135 | 주문수량: 20
136 | 주문가격: 2130
137 | 미체결수량: 0
138 | 체결누계금액: 0
139 | 원주문번호: 0000000
140 | 주문구분: -매도
141 | 매매구분: 보통
142 | 매도수구분: 1
143 | 주문/체결시간: 141407
144 | 체결번호:
145 | 체결가:
146 | 체결량:
147 | 현재가: +2115
148 | (최우선)매도호가: +2115
149 | (최우선)매수호가: +2100
150 | 단위체결가:
151 | 단위체결량:
152 | 당일매매수수료: 0
153 | 당일매매세금: 0
154 | 거부사유: 0
155 | 화면번호: 0341
156 | 터미널번호: 0707047
157 | 신용구분(실시간 체결용): 00
158 | 대출일(실시간 체결용): 00000000
159 |
160 | 1
161 | 2019-07-12 14:14:19,421 | DEBUG | kiwoom.py-chejan_slot-0119 |
162 | ========== 잔고 1번 ======
163 | 계좌번호: 8117558311
164 | 종목코드: A057880
165 | 종목명: 필로시스헬스케어
166 | 현재가: +2115
167 | 보유수량: 20
168 | 매입단가: 2335
169 | 총매입가: 46700
170 | 주문가능수량: 20
171 | 당일순매수량: 0
172 | 매도매수구분: 1
173 | 당일총매도손익: -33599
174 | 예수금: 0
175 | (최우선)매도호가: +2115
176 | (최우선)매수호가: +2100
177 | 기준가: 2080
178 | 손익율: -4.18
179 |
--------------------------------------------------------------------------------
/키움API 주문접수_확인_체결 참고자료/매수후 매수정정.txt:
--------------------------------------------------------------------------------
1 | 2019-07-12 14:31:18,891 | DEBUG | kiwoom.py-chejan_slot-0094 |
2 | ========== 주문체결 0번 ====== 064550
3 | 계좌번호: 8117558311
4 | 주문번호: 0104305
5 | 관리자사번:
6 | 종목코드: A064550
7 | 주문업무분류: JJ
8 | 주문상태: 접수
9 | 종목명: 바이오니아
10 | 주문수량: 10
11 | 주문가격: 8990
12 | 미체결수량: 10
13 | 체결누계금액: 0
14 | 원주문번호: 0000000
15 | 주문구분: +매수
16 | 매매구분: 보통
17 | 매도수구분: 2
18 | 주문/체결시간: 143114
19 | 체결번호:
20 | 체결가:
21 | 체결량:
22 | 현재가: 9020
23 | (최우선)매도호가: +9030
24 | (최우선)매수호가: 9020
25 | 단위체결가:
26 | 단위체결량:
27 | 당일매매수수료: 0
28 | 당일매매세금: 0
29 | 거부사유: 0
30 | 화면번호: 4989
31 | 터미널번호: 0707047
32 | 신용구분(실시간 체결용): 00
33 | 대출일(실시간 체결용): 00000000
34 |
35 | 0
36 | 2019-07-12 14:31:43,790 | DEBUG | kiwoom.py-chejan_slot-0094 |
37 | ========== 주문체결 0번 ====== 064550
38 | 계좌번호: 8117558311
39 | 주문번호: 0104511
40 | 관리자사번:
41 | 종목코드: A064550
42 | 주문업무분류: JJ
43 | 주문상태: 접수
44 | 종목명: 바이오니아
45 | 주문수량: 10
46 | 주문가격: 9000
47 | 미체결수량: 10
48 | 체결누계금액: 0
49 | 원주문번호: 0104305
50 | 주문구분: +매수정정
51 | 매매구분: 보통
52 | 매도수구분: 2
53 | 주문/체결시간: 143139
54 | 체결번호:
55 | 체결가:
56 | 체결량:
57 | 현재가: 9020
58 | (최우선)매도호가: +9030
59 | (최우선)매수호가: 9020
60 | 단위체결가:
61 | 단위체결량:
62 | 당일매매수수료: 0
63 | 당일매매세금: 0
64 | 거부사유: 0
65 | 화면번호: 4989
66 | 터미널번호: 0707047
67 | 신용구분(실시간 체결용): 00
68 | 대출일(실시간 체결용): 00000000
69 |
70 | 0
71 | 2019-07-12 14:31:43,791 | DEBUG | kiwoom.py-chejan_slot-0094 |
72 | ========== 주문체결 0번 ====== 064550
73 | 계좌번호: 8117558311
74 | 주문번호: 0104511
75 | 관리자사번:
76 | 종목코드: A064550
77 | 주문업무분류: JJ
78 | 주문상태: 확인
79 | 종목명: 바이오니아
80 | 주문수량: 10
81 | 주문가격: 9000
82 | 미체결수량: 10
83 | 체결누계금액: 0
84 | 원주문번호: 0104305
85 | 주문구분: +매수정정
86 | 매매구분: 보통
87 | 매도수구분: 2
88 | 주문/체결시간: 143139
89 | 체결번호:
90 | 체결가:
91 | 체결량:
92 | 현재가: 9020
93 | (최우선)매도호가: +9030
94 | (최우선)매수호가: 9020
95 | 단위체결가:
96 | 단위체결량:
97 | 당일매매수수료: 0
98 | 당일매매세금: 0
99 | 거부사유: 0
100 | 화면번호: 4989
101 | 터미널번호: 0707047
102 | 신용구분(실시간 체결용): 00
103 | 대출일(실시간 체결용): 00000000
104 |
105 | 0
106 | 2019-07-12 14:31:43,791 | DEBUG | kiwoom.py-chejan_slot-0094 |
107 | ========== 주문체결 0번 ====== 064550
108 | 계좌번호: 8117558311
109 | 주문번호: 0104305
110 | 관리자사번:
111 | 종목코드: A064550
112 | 주문업무분류: JJ
113 | 주문상태: 접수
114 | 종목명: 바이오니아
115 | 주문수량: 10
116 | 주문가격: 8990
117 | 미체결수량: 0
118 | 체결누계금액: 0
119 | 원주문번호: 0000000
120 | 주문구분: +매수
121 | 매매구분: 보통
122 | 매도수구분: 2
123 | 주문/체결시간: 143114
124 | 체결번호:
125 | 체결가:
126 | 체결량:
127 | 현재가: 9020
128 | (최우선)매도호가: +9030
129 | (최우선)매수호가: 9020
130 | 단위체결가:
131 | 단위체결량:
132 | 당일매매수수료: 0
133 | 당일매매세금: 0
134 | 거부사유: 0
135 | 화면번호: 4989
136 | 터미널번호: 0707047
137 | 신용구분(실시간 체결용): 00
138 | 대출일(실시간 체결용): 00000000
139 |
140 |
--------------------------------------------------------------------------------
/키움API 주문접수_확인_체결 참고자료/매수후 매수취소.txt:
--------------------------------------------------------------------------------
1 | 2019-07-12 15:10:32,481 | DEBUG | kiwoom.py-chejan_slot-0094 |
2 | ========== 주문체결 0번 ====== 238490
3 | 계좌번호: 8117558311
4 | 주문번호: 0115061
5 | 관리자사번:
6 | 종목코드: A238490
7 | 주문업무분류: JJ
8 | 주문상태: 접수
9 | 종목명: 힘스
10 | 주문수량: 8
11 | 주문가격: 21000
12 | 미체결수량: 8
13 | 체결누계금액: 0
14 | 원주문번호: 0000000
15 | 주문구분: +매수
16 | 매매구분: 보통
17 | 매도수구분: 2
18 | 주문/체결시간: 151028
19 | 체결번호:
20 | 체결가:
21 | 체결량:
22 | 현재가: -21200
23 | (최우선)매도호가: -21200
24 | (최우선)매수호가: -21100
25 | 단위체결가:
26 | 단위체결량:
27 | 당일매매수수료: 0
28 | 당일매매세금: 0
29 | 거부사유: 0
30 | 화면번호: 4989
31 | 터미널번호: 0707047
32 | 신용구분(실시간 체결용): 00
33 | 대출일(실시간 체결용): 00000000
34 |
35 | 0
36 | 2019-07-12 15:10:39,081 | DEBUG | kiwoom.py-chejan_slot-0094 |
37 | ========== 주문체결 0번 ====== 238490
38 | 계좌번호: 8117558311
39 | 주문번호: 0115100
40 | 관리자사번:
41 | 종목코드: A238490
42 | 주문업무분류: JJ
43 | 주문상태: 접수
44 | 종목명: 힘스
45 | 주문수량: 8
46 | 주문가격: 0
47 | 미체결수량: 8
48 | 체결누계금액: 0
49 | 원주문번호: 0115061
50 | 주문구분: 매수취소
51 | 매매구분: 보통
52 | 매도수구분: 2
53 | 주문/체결시간: 151034
54 | 체결번호:
55 | 체결가:
56 | 체결량:
57 | 현재가: -21200
58 | (최우선)매도호가: -21200
59 | (최우선)매수호가: -21100
60 | 단위체결가:
61 | 단위체결량:
62 | 당일매매수수료: 0
63 | 당일매매세금: 0
64 | 거부사유: 0
65 | 화면번호: 4989
66 | 터미널번호: 0707047
67 | 신용구분(실시간 체결용): 00
68 | 대출일(실시간 체결용): 00000000
69 |
70 | 0
71 | 2019-07-12 15:10:39,082 | DEBUG | kiwoom.py-chejan_slot-0094 |
72 | ========== 주문체결 0번 ====== 238490
73 | 계좌번호: 8117558311
74 | 주문번호: 0115100
75 | 관리자사번:
76 | 종목코드: A238490
77 | 주문업무분류: JJ
78 | 주문상태: 확인
79 | 종목명: 힘스
80 | 주문수량: 8
81 | 주문가격: 0
82 | 미체결수량: 0
83 | 체결누계금액: 0
84 | 원주문번호: 0115061
85 | 주문구분: 매수취소
86 | 매매구분: 보통
87 | 매도수구분: 2
88 | 주문/체결시간: 151034
89 | 체결번호:
90 | 체결가:
91 | 체결량:
92 | 현재가: -21200
93 | (최우선)매도호가: -21200
94 | (최우선)매수호가: -21100
95 | 단위체결가:
96 | 단위체결량:
97 | 당일매매수수료: 0
98 | 당일매매세금: 0
99 | 거부사유: 0
100 | 화면번호: 4989
101 | 터미널번호: 0707047
102 | 신용구분(실시간 체결용): 00
103 | 대출일(실시간 체결용): 00000000
104 |
105 | 0
106 | 2019-07-12 15:10:39,083 | DEBUG | kiwoom.py-chejan_slot-0094 |
107 | ========== 주문체결 0번 ====== 238490
108 | 계좌번호: 8117558311
109 | 주문번호: 0115061
110 | 관리자사번:
111 | 종목코드: A238490
112 | 주문업무분류: JJ
113 | 주문상태: 접수
114 | 종목명: 힘스
115 | 주문수량: 8
116 | 주문가격: 21000
117 | 미체결수량: 0
118 | 체결누계금액: 0
119 | 원주문번호: 0000000
120 | 주문구분: +매수
121 | 매매구분: 보통
122 | 매도수구분: 2
123 | 주문/체결시간: 151028
124 | 체결번호:
125 | 체결가:
126 | 체결량:
127 | 현재가: -21200
128 | (최우선)매도호가: -21200
129 | (최우선)매수호가: -21100
130 | 단위체결가:
131 | 단위체결량:
132 | 당일매매수수료: 0
133 | 당일매매세금: 0
134 | 거부사유: 0
135 | 화면번호: 4989
136 | 터미널번호: 0707047
137 | 신용구분(실시간 체결용): 00
138 | 대출일(실시간 체결용): 00000000
139 |
--------------------------------------------------------------------------------