이하영

tr관련 함수 추가

import logging.handlers
import sys
# formmater 생성
formatter = logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s > %(message)s')
# logger 인스턴스를 생성 및 로그 레벨 설정
logger = logging.getLogger("crumbs")
logger.setLevel(logging.DEBUG)
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)
\ No newline at end of file
import datetime
from sqlalchemy import *
import pymysql
from pandas import DataFrame
import config
class Simulator_Api:
def __init__(self,simul_num,op,db_name):
self.simul_num=int(simul_num)
if op=="real":
self.op='real'
self.simul_reset=False
self.db_name=db_name
self.set_variable()
def set_date(self):
self.today=datetime.datetime.today().strftime("%Y%m%d")
def set_variable(self):
self.set_date()
self.set_database()
# 매수/매도 알고리즘 선택 -> 차후 알고리즘 별로 구현 및 재설정
self.buy_algorithm=1
self.sell_algorithm=1
# 특정 데이터베이스 내에 특정 테이블이 존재하는지 확인하는 함수
def is_table_exist(self,db_name,table_name):
query="select 1 from information_schema.tables where table_schema='%s' and table_name='%s'"
result=self.engine_simul.execute(query%(db_name,table_name)).fetchall()
if len(result)==1:
return True
else:
return False
# 데이터베이스 연결 설정
def set_database(self):
if self.op=="real":
self.engine_simul=create_engine("mysql+pymysql://"+config.db_id+":"+config.db_pw+"@"+config.db_ip+
":"+config.db_port+"/"+str(self.db_name),encoding='utf-8')
else:
self.db_name='simulator'+str(self.simul_num)
self.engine_simul=create_engine("mysql+pymysql://"+config.db_id+":"+config.db_pw+"@"+config.db_ip+
":"+config.db_port+"/"+str(self.db_name),encoding='utf-8')
self.engine_daily = create_engine("mysql+pymysql://" + config.db_id + ":" + config.db_pw + "@" + config.db_ip +
":" + config.db_port + "/daily_info" , encoding='utf-8')
self.engine_stock = create_engine("mysql+pymysql://" + config.db_id + ":" + config.db_pw + "@" + config.db_ip +
":" + config.db_port + "/stock_info", encoding='utf-8')
self.engine_minute = create_engine("mysql+pymysql://" + config.db_id + ":" + config.db_pw + "@" + config.db_ip +
":" + config.db_port + "/minute_info", encoding='utf-8')
self.conn=pymysql.connect(
host=config.db_ip,
port=int(config.db_port),
user=config.db_id,
password=config.db_pw,
charset='utf8'
)
# 날짜별 주식 데이터를 저장해 놓은 데이터베이스에서 가장 최근 날짜를 가져오는 함수
def get_latest_date(self):
query="select table_name from information_schema.tables where table_schema='daily_info' and " \
"table_name like '%s' order by table_name desc limit 1"
result=self.engine_daily.execute(query%("20%%")).fetchall()
if len(result)==0:
return False
else:
return result[0][0]
# transaction_history 테이블의 Dataframe 생성
def df_transaction_history(self):
df_temp={'id':[]}
self.df_th=DataFrame(df_temp,
columns=['id','order_num','code','code_name','rate','purchase_rate',
'purchase_price','present_price','valuation_price','valuation_profit',
'holding_amount','buy_date','total_purchase_price','contract_check','per_invest',
'sell_date','sell_price','sell_rate'
])
# daily_info 데이터베이스에서 특정 날짜에서 특정 코드에 해당하는 정보만 가져오는 함수수
def get_daily_info_by_code(self,code,date):
query="select * from {} where code='{}' group by code"
daily_info=self.engine_daily.execute(query.format(date,code)).fetchall()
df_daily_info=DataFrame(daily_info,
columns=['index','index2','date','check_item','code',
'code_name','dff_rate',
'close','open','high','low','volume',
'avg5','avg10','avg20','avg60','avg120',
'prev_avg5','prev_avg10','prev_avg20','prev_avg60','prev_avg120',
'avg5_diff_rate','avg10_diff_rate','avg20_diff_rate','avg60_diff_rate',
'avg120_diff_rate',
'vol5','vol10','vol20','vol60','vol120'])
return df_daily_info
\ No newline at end of file
No preview for this file type
from sqlalchemy import *
from open_api import *
from daily_info import *
from stock_info import *
import config
class CollectorApi():
def __init__(self):
self.open_api=OpenApi()
self.engine_bot=self.open_api.engine_bot
def set_variable(self):
self.open_api.sort="collector"
self.stock_info=StockInfo(config.real_bot,config.real_stockInfo,config.real_dailyInofo)
self.daily_info=DailyInfo()
def update_code(self):
print("update code")
query = "select code_update,jango_data_db_check, possessed_item, today_profit, final_chegyul_check, " \
"db_to_buy_list,today_buy_list, daily_crawler , min_crawler, daily_buy_list " \
"from setting_data limit 1"
result=self.engine_bot.execute(query).fetchall()
print(result)
if result[0][0]!=self.open_api.today():
self.open_api.check_balance()
self.get_code_list()
def set_db_minute_info(self):
print("Make Minute Info Database")
query="select code,code_name from stock_all"
target=self.open_api.engine_dInfo.execute(query).fetchall()
print(target)
app = QApplication(sys.argv)
c=CollectorApi()
c.update_code()
\ No newline at end of file
......
......@@ -9,5 +9,16 @@ test_account_no="8147766711"
# 시뮬레이션을 돌리기 시작할 날짜
start_buying='20190101'
simul_num1=1
simul_name1="AutoBot"+str(simul_num1)+"_Test"
test_num=1
test_bot_name="AutoBot"+str(test_num)+"_Test"
# 실전투자 정보
real_account_no=""
real_num=1
# 데이터베이스 이름
real_bot_name="AutoBot"+str(real_num)
real_stockInfo_name="stock_info"
real_dailyInfo_name="daily_info"
\ No newline at end of file
......
This diff is collapsed. Click to expand it.
from sqlalchemy import *
from PyQt5.QtCore import *
import datetime
import config
class StockInfo():
def __init__(self):
def __init__(self,db_name,stock_info_name,daily_info_name):
if db_name!=0:
self.db_name=db_name
self.stockInfo_name=stock_info_name
self.dailyInfo_name=daily_info_name
self.engine=create_engine(
"mysql+pymysql://" + config.db_id + ":" + config.db_pw + "@" + config.db_ip + ":" + config.db_port +
"/stock_info", encoding='utf-8')
self.conn=self.engine.connect()
self.set_variable()
# 변수 설정
def set_variable(self):
self.mkt_start_time=QTime(9,0,0)
self.mkt_end_time=QTime(15,31,0)
self.today=datetime.datetime.today().strftime("%Y%m%d")
# 현재 시간이 주식장이 열린 시간인지 확인하는 함수
def time_check(self):
self.current_time=QTime.currentTime()
if (self.current_time>self.mkt_start_time and self.current_time<self.mkt_end_time):
return True
else:
return False
\ No newline at end of file
......