Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-2-capstone-design2
/
2015104491
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이하영
2020-12-02 06:04:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
587f652a20352f472e360a1d56bf6ef8cf6bfb89
587f652a
1 parent
d00a16a4
날짜별 데이터(daily_buy_list) 데이터베이스
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
7 deletions
proj/library/cf.py
proj/library/daily_buy_list.py
proj/library/open_api.py
proj/library/cf.py
View file @
587f652
...
...
@@ -7,9 +7,6 @@ db_ip="localhost"
# 모의투자 계좌번호
test_account_no
=
"8147766711"
# 시뮬레이션을 돌리기 시작할 날짜
start_buying
=
'20190101'
test_num
=
1
test_bot_name
=
"AutoBot"
+
str
(
test_num
)
+
"_Test"
...
...
@@ -20,7 +17,17 @@ real_num=1
# 데이터베이스 이름
real_bot_name
=
"AutoBot"
+
str
(
real_num
)
real_stockInfo_name
=
"stock_info"
real_dailyInfo_name
=
"daily_info"
real_daily_craw_db_name
=
"daily_craw"
real_daily_buy_list_db_name
=
"daily_buy_list"
# 시뮬레이션을 돌리기 시작할 날짜
start_daily_buy_list
=
'20190102'
# api를 최대 몇 번까지 호출 하고 봇을 끌지 설정 하는 옵션
max_api_call
=
98
# openapi 1회 조회 시 대기 시간(0.2 보다-> 0.3이 안정적)
TR_REQ_TIME_INTERVAL
=
0.3
max_api_call
=
98
\ No newline at end of file
# n회 조회를 1번 발생시킨 경우 대기 시간
TR_REQ_TIME_INTERVAL_LONG
=
1
\ No newline at end of file
...
...
proj/library/daily_buy_list.py
0 → 100644
View file @
587f652
from
sqlalchemy
import
*
from
pandas
import
DataFrame
import
datetime
from
daily_crawler
import
*
import
cf
# -* daily_buy_list *-
# 일자별로 주식종목에 대한 데이터를 저장하는 데이터베이스
class
daily_buy_list
():
def
__init__
(
self
):
self
.
variable_setting
()
# 변수 설정
def
variable_setting
(
self
):
self
.
today
=
datetime
.
datetime
.
today
()
.
strftime
(
"
%
Y
%
m
%
d"
)
self
.
today_detail
=
datetime
.
datetime
.
today
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M"
)
self
.
start_date
=
cf
.
start_daily_buy_list
self
.
engine_daily_craw
=
create_engine
(
"mysql+pymysql://"
+
cf
.
db_id
+
":"
+
cf
.
db_pw
+
"@"
+
cf
.
db_ip
+
":"
+
cf
.
db_port
+
"/daily_craw"
,
encoding
=
'utf-8'
)
self
.
engine_daily_buy_list
=
create_engine
(
"mysql+pymysql://"
+
cf
.
db_id
+
":"
+
cf
.
db_pw
+
"@"
+
cf
.
db_ip
+
":"
+
cf
.
db_port
+
"/daily_buy_list"
,
encoding
=
'utf-8'
)
# 설정한 날짜부터 현재까지 날짜 리스트를 저장하는 함수
def
date_rows_setting
(
self
):
query
=
"select date from `gs글로벌` where date >= '
%
s' group by date"
self
.
date_rows
=
self
.
engine_daily_craw
.
execute
(
query
%
self
.
start_date
)
.
fetchall
()
# daily_buy_list 데이터베이스에 특정 이름(date)을 가진 테이블이 존재하는지 확인하는 함수
def
is_table_exist_daily_buy_list
(
self
,
date
):
query
=
"select 1 from information_schema.tables where table_schema ='daily_buy_list' and table_name = '
%
s'"
rows
=
self
.
engine_daily_buy_list
.
execute
(
query
%
(
date
))
.
fetchall
()
if
len
(
rows
)
==
1
:
return
True
elif
len
(
rows
)
==
0
:
return
False
# daily_buy_list 데이터베이스 안에 테이블을 생성하는 함수
def
daily_buy_list
(
self
):
self
.
date_rows_setting
()
self
.
get_stock_item_all
()
for
k
in
range
(
len
(
self
.
date_rows
)):
print
(
str
(
k
)
+
" 번째 : "
+
datetime
.
datetime
.
today
()
.
strftime
(
" *******
%
H :
%
M :
%
S *******"
))
# 특정 날짜의 이름을 가진 테이블 존재하는지 확인
# 테이블이 존재하면 다음 날짜를 확인
if
self
.
is_table_exist_daily_buy_list
(
self
.
date_rows
[
k
][
0
]):
continue
# 테이블이 존재하지 않으면 생성
else
:
multi_list
=
list
()
for
i
in
range
(
len
(
self
.
stock_item_all
)):
code
=
self
.
stock_item_all
[
i
][
1
]
# 종목코드
code_name
=
self
.
stock_item_all
[
i
][
0
]
# 종목명
# daily_craw 데이터베이스에 종목명을 가진 테이블이 존재하지 않는 경우 다음 데이터 처리
# daily_craw에 저장한 종목에 대해서만 daily_buy_list에 날짜별 데이터를 저장한다
if
not
self
.
is_table_exist_daily_craw
(
code
,
code_name
):
continue
query
=
f
"select * from '{self.stock_item_all[i][0]}' where date = '{self.date_rows[k][0]}' "
\
f
"group by date"
rows
=
self
.
engine_daily_craw
.
execute
(
query
)
.
fetchall
()
multi_list
+=
rows
if
len
(
multi_list
)
!=
0
:
df_temp
=
DataFrame
(
multi_list
,
columns
=
[
'index'
,
'date'
,
'check_item'
,
'code'
,
'code_name'
,
'd1_diff_rate'
,
'close'
,
'open'
,
'high'
,
'low'
,
'volume'
,
'clo5'
,
'clo10'
,
'clo20'
,
'clo60'
,
'clo120'
,
"clo5_diff_rate"
,
"clo10_diff_rate"
,
"clo20_diff_rate"
,
"clo60_diff_rate"
,
"clo120_diff_rate"
,
'yes_clo5'
,
'yes_clo10'
,
'yes_clo20'
,
'yes_clo60'
,
'yes_clo120'
,
'vol5'
,
'vol10'
,
'vol20'
,
'vol60'
,
'vol120'
])
df_temp
.
to_sql
(
name
=
self
.
date_rows
[
k
][
0
],
con
=
self
.
engine_daily_buy_list
,
if_exists
=
'replace'
)
# stock_item_all(거래할 종목 리스트)에서 모든 항목을 가져오는 함수
def
get_stock_item_all
(
self
):
print
(
"get_stock_item_all!!!!!!"
)
sql
=
"select code_name,code from stock_item_all"
self
.
stock_item_all
=
self
.
engine_daily_buy_list
.
execute
(
sql
)
.
fetchall
()
# daily_craw 데이터베이스에 특정 이름(code_name)을 가진 테이블이 존재하는지 확인하는 함수
def
is_table_exist_daily_craw
(
self
,
code
,
code_name
):
sql
=
"select 1 from information_schema.tables where table_schema ='daily_craw' and table_name = '
%
s'"
rows
=
self
.
engine_daily_craw
.
execute
(
sql
%
(
code_name
))
.
fetchall
()
if
len
(
rows
)
==
1
:
return
True
elif
len
(
rows
)
==
0
:
return
False
if
__name__
==
"__main__"
:
daily_buy_list
=
daily_buy_list
()
daily_buy_list
.
date_rows_setting
()
proj/library/open_api.py
View file @
587f652
...
...
@@ -751,7 +751,7 @@ class Open_Api(QAxWidget):
def
is_stock_table_exist
(
self
,
code_name
):
query
=
"select 1 from information_schema.tables where table_schema ='stock_info' and table_name = '{}'"
result
=
self
.
engine_stock
.
execute
(
query
.
format
(
code_name
))
.
fetchall
()
if
result
:
ㄴ
if
result
:
return
True
else
:
return
False
...
...
Please
register
or
login
to post a comment