This commit is contained in:
dosangyoon
2022-02-07 03:38:15 +09:00
parent 3db4f6e72d
commit 93966cea1e
8 changed files with 76 additions and 38 deletions

View File

@@ -1019,7 +1019,7 @@ class HTS:
sell_price = int(jangoDic[code]['장부가'] / 10) * 10 sell_price = int(jangoDic[code]['장부가'] / 10) * 10
# 만약 오후 1시 이전이라면 한 호가 (5원) 더 올려서 매도한다. # 만약 오후 1시 이전이라면 한 호가 (5원) 더 올려서 매도한다.
if datetime.now() < datetime.strptime(given_day + " 104000", '%Y%m%d %H%M%S'): if datetime.now() < datetime.strptime(given_day + " 104000", '%Y%m%d %H%M%S'):
if lower != None: if lower is not None:
if lower[len(lower)-2] < lower[len(lower)-1]: if lower[len(lower)-2] < lower[len(lower)-1]:
sell_price += 5 sell_price += 5

View File

@@ -63,7 +63,7 @@ class Analyzer:
rowid = 1 rowid = 1
cursor.execute('SELECT * FROM fnguide WHERE rowid=?', (rowid,)) cursor.execute('SELECT * FROM fnguide WHERE rowid=?', (rowid,))
result = cursor.fetchone() result = cursor.fetchone()
while result != None: while result is not None:
if result[2] == "227950": if result[2] == "227950":
print (1) print (1)
data = json.loads(result[2]) data = json.loads(result[2])
@@ -144,7 +144,7 @@ class Analyzer:
rowid = 1 rowid = 1
cursor.execute('SELECT * FROM ' + self.tableName + ' WHERE rowid=?', (rowid,)) cursor.execute('SELECT * FROM ' + self.tableName + ' WHERE rowid=?', (rowid,))
result = cursor.fetchone() result = cursor.fetchone()
while result != None: while result is not None:
stock = {"CODE": result[0], "NAME": result[1], "PRICE": json.loads(result[2])} stock = {"CODE": result[0], "NAME": result[1], "PRICE": json.loads(result[2])}
results = self.stochastic.analyze(stock) results = self.stochastic.analyze(stock)
text = json.dumps(results, ensure_ascii=False) text = json.dumps(results, ensure_ascii=False)
@@ -466,7 +466,7 @@ class Analyzer:
for check_index in range(365): for check_index in range(365):
inde_check.append([0,0]) inde_check.append([0,0])
while result != None: while result is not None:
item_code = result[0] item_code = result[0]
item_name = result[1] item_name = result[1]
print("#html", rowid, item_name) print("#html", rowid, item_name)
@@ -589,7 +589,7 @@ class Analyzer:
rowid = 1 rowid = 1
cursor.execute('SELECT * FROM ' + self.tableName + ' WHERE rowid=?', (rowid,)) cursor.execute('SELECT * FROM ' + self.tableName + ' WHERE rowid=?', (rowid,))
result = cursor.fetchone() result = cursor.fetchone()
while result != None: while result is not None:
stock = {"CODE": result[0], "NAME": result[1], "PRICE": json.loads(result[2])} stock = {"CODE": result[0], "NAME": result[1], "PRICE": json.loads(result[2])}
try: try:

View File

@@ -389,7 +389,10 @@ class AnalyzerSqlite:
self.makeDir("0_240일선 아래") self.makeDir("0_240일선 아래")
self.makeDir("1_기준선 위 전환선 올라옴") self.makeDir("1_기준선 위 전환선 올라옴")
self.makeDir("1_기준선 위 120일선 올라옴") self.makeDir("1_기준선 위 120일선 올라옴")
self.makeDir("1_기준선 위 200일선 올라옴")
self.makeDir("1_기준선 위 240일선 올라옴")
self.makeDir("1_240일선 돌파") self.makeDir("1_240일선 돌파")
self.makeDir("1_200일선 돌파")
self.makeDir("1_20일선 돌파") self.makeDir("1_20일선 돌파")
self.makeDir("1_60일선 돌파") self.makeDir("1_60일선 돌파")
self.makeDir("1_거래량 5배 이상") self.makeDir("1_거래량 5배 이상")
@@ -503,36 +506,38 @@ class AnalyzerSqlite:
# 종목 상태 체크 분석 # 종목 상태 체크 분석
state = self.analyzeFinalScore(stock) state = self.analyzeFinalScore(stock)
# 스토케스틱이 10 미만 # 0_스토케스틱이 10 미만
if len(close) > 5 and stochastic_score is not None and stochastic_score < 10: if len(close) > 5 and stochastic_score is not None and stochastic_score < 10:
type = "0_스토케스틱이 10 미만" type = "0_스토케스틱이 10 미만"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# bolingerband 하단 # 0_bolingerband 하단
if len(close) > 60 and bolingerband_lower[0] is not None and close[0] < bolingerband_lower[0]: if len(close) > 60 and bolingerband_lower[0] is not None and close[0] < bolingerband_lower[0]:
type = "0_bolingerband 하단" type = "0_bolingerband 하단"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 260일 위치 에너지가 10% 미만 # 0_260일 위치 에너지가 10% 미만
if len(close) > 5 and positionalEnergy1 is not None and positionalEnergy1 < 0.1: if len(close) > 5 and positionalEnergy1 is not None and positionalEnergy1 < 0.1:
type = "0_260일 위치 에너지가 10% 미만" type = "0_260일 위치 에너지가 10% 미만"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 260일 가격 반토막 이상 # 0_260일 가격 반토막 이상
if len(close) > 5 and positionalEnergy2 is not None and positionalEnergy2 < 0.5: if len(close) > 5 and positionalEnergy2 is not None and positionalEnergy2 < 0.5:
type = "0_260일 가격 반토막 이상" type = "0_260일 가격 반토막 이상"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 종가가 240일선 아래라면 매수한다. # 0_종가가 240일선 아래라면 매수한다.
if close[0] < avg240[0]: if close[0] < avg240[0]:
type = "0_240일선 아래" type = "0_240일선 아래"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 기준선 위 전환선 올라옴 # 1_기준선 위 전환선 올라옴
if len(close) > 50: if len(close) > 50:
if ((ichimokucloud_changeLine[0] > ichimokucloud_baseLine[0] and if ((ichimokucloud_changeLine[0] > ichimokucloud_baseLine[0] and
ichimokucloud_changeLine[1] < ichimokucloud_baseLine[1] and ichimokucloud_changeLine[1] < ichimokucloud_baseLine[1] and
ichimokucloud_changeLine[2] < ichimokucloud_baseLine[2]) and ichimokucloud_changeLine[2] < ichimokucloud_baseLine[2] and
ichimokucloud_changeLine[3] < ichimokucloud_baseLine[3] and
ichimokucloud_changeLine[4] < ichimokucloud_baseLine[4]) and
volume[0] > volume[1]): volume[0] > volume[1]):
type = "1_기준선 위 전환선 올라옴" type = "1_기준선 위 전환선 올라옴"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
@@ -541,52 +546,81 @@ class AnalyzerSqlite:
if len(close) > 50: if len(close) > 50:
if ((avg120[0] > ichimokucloud_baseLine[0] and if ((avg120[0] > ichimokucloud_baseLine[0] and
avg120[1] < ichimokucloud_baseLine[1] and avg120[1] < ichimokucloud_baseLine[1] and
avg120[2] < ichimokucloud_baseLine[2]) and avg120[2] < ichimokucloud_baseLine[2] and
avg120[3] < ichimokucloud_baseLine[3] and
avg120[4] < ichimokucloud_baseLine[4]) and
volume[0] > volume[1]): volume[0] > volume[1]):
type = "1_기준선 위 120일선 올라옴" type = "1_기준선 위 120일선 올라옴"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 종가가 240일선 돌파 # "1_기준선 위 200일선 올라옴"
if close[0] > avg240[0] and close[1] < avg240[1]: if len(close) > 50:
if ((avg200[0] > ichimokucloud_baseLine[0] and
avg200[1] < ichimokucloud_baseLine[1] and
avg200[2] < ichimokucloud_baseLine[2] and
avg200[3] < ichimokucloud_baseLine[3] and
avg200[4] < ichimokucloud_baseLine[4]) and
volume[0] > volume[1]):
type = "1_기준선 위 200일선 올라옴"
self.writeFile(type, CODE, NAME, stock, state)
# "1_기준선 위 240일선 올라옴"
if len(close) > 50:
if ((avg240[0] > ichimokucloud_baseLine[0] and
avg240[1] < ichimokucloud_baseLine[1] and
avg240[2] < ichimokucloud_baseLine[2] and
avg240[3] < ichimokucloud_baseLine[3] and
avg240[4] < ichimokucloud_baseLine[4]) and
volume[0] > volume[1]):
type = "1_기준선 위 240일선 올라옴"
self.writeFile(type, CODE, NAME, stock, state)
# 1_종가가 200일선 돌파
if close[0] > avg200[0] and close[1] < avg200[1] and close[2] < avg200[2] and close[3] < avg200[3] and close[4] < avg200[4]:
type = "1_200일선 돌파"
self.writeFile(type, CODE, NAME, stock, state)
# 1_종가가 240일선 돌파
if close[0] > avg240[0] and close[1] < avg240[1] and close[2] < avg240[2] and close[3] < avg240[3] and close[4] < avg240[4]:
type = "1_240일선 돌파" type = "1_240일선 돌파"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 20일선 돌파 # 1_20일선 돌파
temp_status = self.common.check_Dolpa_Jiji(stock, '20') temp_status = self.common.check_Dolpa_Jiji(stock, '20')
if temp_status != "": if temp_status != "":
type = "1_20일선 돌파" type = "1_20일선 돌파"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 60일선 돌파 # 1_60일선 돌파
temp_status = self.common.check_Dolpa_Jiji(stock, '60') temp_status = self.common.check_Dolpa_Jiji(stock, '60')
if temp_status != "": if temp_status != "":
type = "1_60일선 돌파" type = "1_60일선 돌파"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 골든크로스 # 1_골든크로스
golden_cross_status = self.common.check_golded_cross(stock) golden_cross_status = self.common.check_golded_cross(stock)
if golden_cross_status != "": if golden_cross_status != "":
type = "1_GoldenCross" type = "1_GoldenCross"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 거래량 5배 이상 # 1_거래량 5배 이상
if volume[0] > volume[1]*5: if len(volume)>2 and volume[0] > volume[1]*5:
type = "1_거래량 5배 이상" type = "1_거래량 5배 이상"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# bolingerband 하단 돌파 상승 # 1_bolingerband 하단 돌파 상승
if (len(close) > 60 and (bolingerband_lower[0] is not None and bolingerband_lower[1] is not None) and if (len(close) > 60 and (bolingerband_lower[0] is not None and bolingerband_lower[1] is not None) and
close[0] > bolingerband_lower[0] and close[1] < bolingerband_lower[1]): close[0] > bolingerband_lower[0] and close[1] < bolingerband_lower[1]):
type = "1_bolingerband 하단 돌파 상승" type = "1_bolingerband 하단 돌파 상승"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 정배열 # 1_정배열
right_arrange = self.common.check_RightArrange(stock) right_arrange = self.common.check_RightArrange(stock)
if right_arrange != "": if right_arrange != "":
type = "1_정배열" type = "1_정배열"
self.writeFile(type, CODE, NAME, stock, state) self.writeFile(type, CODE, NAME, stock, state)
# 모든 라인 돌파 # 1_모든 라인 돌파
if (len(close) > 50 and if (len(close) > 50 and
close[0] > max(open[0], avg5[0], avg20[0], avg60[0], avg120[0], avg240[0], bolingerband_upper[0], ichimokucloud_changeLine[0], ichimokucloud_baseLine[0]) and close[0] > max(open[0], avg5[0], avg20[0], avg60[0], avg120[0], avg240[0], bolingerband_upper[0], ichimokucloud_changeLine[0], ichimokucloud_baseLine[0]) and
open[0] < max(open[0], avg5[0], avg20[0], avg60[0], avg120[0], avg240[0], bolingerband_upper[0], ichimokucloud_changeLine[0], ichimokucloud_baseLine[0])): open[0] < max(open[0], avg5[0], avg20[0], avg60[0], avg120[0], avg240[0], bolingerband_upper[0], ichimokucloud_changeLine[0], ichimokucloud_baseLine[0])):

View File

@@ -4,7 +4,7 @@ class Common:
# 상향 # 상향
def checkUpward(self, type, data): def checkUpward(self, type, data):
check = True check = True
if type != None: if type is not None:
for i in range(len(data)-1): for i in range(len(data)-1):
# 만약 이전이 이후보다 크다면, 상승이 아님 # 만약 이전이 이후보다 크다면, 상승이 아님
if data[i][type] > data[i+1][type]: if data[i][type] > data[i+1][type]:

View File

@@ -4,7 +4,7 @@ class Common:
# 상향 # 상향
def checkUpward(self, type, data): def checkUpward(self, type, data):
check = True check = True
if type != None: if type is not None:
for i in range(len(data)-1): for i in range(len(data)-1):
# 만약 이전이 이후보다 크다면, 상승이 아님 # 만약 이전이 이후보다 크다면, 상승이 아님
if data[i][type] > data[i+1][type]: if data[i][type] > data[i+1][type]:

View File

@@ -5,7 +5,7 @@ import re
import json import json
import sqlite3 import sqlite3
import requests import requests
import math from time import sleep
import time import time
# 닐짜 형식으로 바뀐 this_date값을 확인 가능 # 닐짜 형식으로 바뀐 this_date값을 확인 가능
@@ -126,7 +126,7 @@ class StockCrawler:
cursor.execute('SELECT ymd FROM ' + tableName + ' WHERE CODE=? order by ymd desc', (stock["CODE"],)) cursor.execute('SELECT ymd FROM ' + tableName + ' WHERE CODE=? order by ymd desc', (stock["CODE"],))
result = cursor.fetchone() result = cursor.fetchone()
ymd = "2019.01.01" ymd = "2019.01.01"
if result != None: if result is not None:
ymd = result[0] ymd = result[0]
stock_data = self.crawl_specific_stock(stock["CODE"], ymd) stock_data = self.crawl_specific_stock(stock["CODE"], ymd)
@@ -139,6 +139,7 @@ class StockCrawler:
#else: #else:
# cursor.execute("UPDATE " + tableName + " SET close=?, diff=?, open=?, high=?, low=?, volume=? WHERE CODE=? and ymd=?", (item['close'], item['diff'], item['open'], item['high'], item['low'], item['volume'], stock["CODE"], item['ymd'])) # cursor.execute("UPDATE " + tableName + " SET close=?, diff=?, open=?, high=?, low=?, volume=? WHERE CODE=? and ymd=?", (item['close'], item['diff'], item['open'], item['high'], item['low'], item['volume'], stock["CODE"], item['ymd']))
sleep(0.05)
conn.commit() conn.commit()
cursor.close() cursor.close()
conn.close() conn.close()
@@ -166,19 +167,20 @@ class StockCrawler:
start_time = time.time() start_time = time.time()
idx = 0 idx = 0
for item in items: for item in items:
idx += 1
conn = sqlite3.connect(inFileName) conn = sqlite3.connect(inFileName)
cursor = conn.cursor() cursor = conn.cursor()
idx += 1
item_name = item[0] item_name = item[0]
item_code = item[1] item_code = item[1]
cursor.execute('SELECT ymd FROM ' + tableName + ' WHERE CODE=? order by ymd desc', (item_code,)) cursor.execute('SELECT ymd FROM ' + tableName + ' WHERE CODE=? order by ymd desc', (item_code,))
result = cursor.fetchone() result = cursor.fetchone()
stock = {"CODE": item_code, "NAME": item_name} stock = {"CODE": item_code, "NAME": item_name}
ymd = "2020.01.01" ymd = "2020.01.01"
if result != None: if result is not None:
ymd = result[0] ymd = result[0]
stock_data = self.crawl_specific_stock(item_code, ymd) stock_data = self.crawl_specific_stock(item_code, ymd)
@@ -197,6 +199,7 @@ class StockCrawler:
print(idx, item_name, item_code, (time.time() - start_time), "s") print(idx, item_name, item_code, (time.time() - start_time), "s")
start_time = time.time() start_time = time.time()
sleep(0.05)
return return
@@ -228,7 +231,8 @@ class StockCrawler:
df = df.append(html[0], ignore_index=True) df = df.append(html[0], ignore_index=True)
break break
df = df.append(html[0], ignore_index=True) df = df.append(html[0], ignore_index=True)
if lastPage: df = df.dropna()
if lastPage or len(df) < 1 or df.날짜[0]=='':
print("\t- lastpage:", page) print("\t- lastpage:", page)
break break
@@ -319,7 +323,7 @@ class StockCrawler:
lastDay = "" lastDay = ""
cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (stock["CODE"],)) cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (stock["CODE"],))
result = cursor.fetchone() result = cursor.fetchone()
if result != None: if result is not None:
stock["PRICE"] = json.loads(result[2]) stock["PRICE"] = json.loads(result[2])
lastDay = stock["PRICE"][len(stock["PRICE"]) - 1]["DATE"] lastDay = stock["PRICE"][len(stock["PRICE"]) - 1]["DATE"]

View File

@@ -152,7 +152,7 @@ class StockCrawler:
start_time = time.time() start_time = time.time()
cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (stock["CODE"],)) cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (stock["CODE"],))
result = cursor.fetchone() result = cursor.fetchone()
if result != None: if result is not None:
stock["PRICE"] = json.loads(result[2]) stock["PRICE"] = json.loads(result[2])
self.crawl_specific_stock(stock) self.crawl_specific_stock(stock)
text = json.dumps(stock['PRICE'], ensure_ascii=False) text = json.dumps(stock['PRICE'], ensure_ascii=False)
@@ -189,7 +189,7 @@ class StockCrawler:
cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (item_code,)) cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (item_code,))
result = cursor.fetchone() result = cursor.fetchone()
stock = {"CODE": item_code, "NAME": item_name, "PRICE": []} stock = {"CODE": item_code, "NAME": item_name, "PRICE": []}
if result != None: if result is not None:
stock["PRICE"] = json.loads(result[2]) stock["PRICE"] = json.loads(result[2])
self.crawl_specific_stock(stock) self.crawl_specific_stock(stock)
@@ -403,7 +403,7 @@ class StockCrawler:
lastDay = "" lastDay = ""
cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (stock["CODE"],)) cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (stock["CODE"],))
result = cursor.fetchone() result = cursor.fetchone()
if result != None: if result is not None:
stock["PRICE"] = json.loads(result[2]) stock["PRICE"] = json.loads(result[2])
lastDay = stock["PRICE"][len(stock["PRICE"]) - 1]["DATE"] lastDay = stock["PRICE"][len(stock["PRICE"]) - 1]["DATE"]

View File

@@ -34,7 +34,7 @@ class PricePredictor:
rowid = 1 rowid = 1
cursor.execute('SELECT * FROM stock WHERE rowid=?', (rowid,)) cursor.execute('SELECT * FROM stock WHERE rowid=?', (rowid,))
result = cursor.fetchone() result = cursor.fetchone()
while result != None: while result is not None:
prices = json.loads(result[2]) prices = json.loads(result[2])
stock = [] stock = []
for price in prices: for price in prices: