Exemplo n.º 1
0
import datetime
import tushare_mysql

mysqlEngine = tushare_mysql.toggleMysql()
cursor = mysqlEngine.cursor(buffered = True)
cursor.execute("use {};".format(tushare_mysql.DB_NAME))

stmts = '''
	SELECT CODE, TIMETOMARKET FROM `CHINASTOCK`.`STOCK_BASICS`;
	'''
cursor.execute(stmts)
for pair in cursor:
	# print "symbol: {}\tIPO: {}".format(*pair)
	symbol = pair[0]
	date_int = pair[1]
	date_str = str(date_int)
	date_tuple = (int(date_str[0:4]), int(date_str[4:6]), int(date_str[6:]))
	ipo = datetime.date(*date_tuple)
	ipo = str(ipo)
	
	symbol_df = tushare_mysql.getHistKlineDf(symbol = symbol
									   		beginDate = ipo,
									   		endDate = '2012-8-15',
									   		ktype = 'D'
									   		retry_count = 5,
									  	 	pause = .01)
	df = symbol_df[1]
	df['volume'] = df['volume'] * 100
	tushare_mysql.insertDatabase(symbol, df, mysqlEngine)

	
symbols = tushare_mysql.symbolList(Engine)

cursor = Engine.cursor(buffered=True)
cursor.execute("use {};".format(tushare_mysql.DB_NAME))

sql = "SELECT DATE FROM `{}`.`{}` ORDER BY DATE DESC LIMIT 1;".format(tushare_mysql.DB_NAME, model_table)
cursor.execute(sql)

date = cursor.fetchall()[0][0]
date_str = str(date)
date_tuple = date_str.split('-')
date_tuple = [int(part) for part in date_tuple]
date_tuple[2] += 1

next_date = datetime.date(*date_tuple)
next_date = str(next_date)
today = datetime.date.today()
today = str(today)

for each in symbols:
	symbol_df = tushare_mysql.getHistKlineDf(symbol=each,
									  beginDate=next_date,
									  endDate=today,
									  retry_count=5)

	symbol_df[1]['volume']=symbol_df[1]['volume']*100
	df = symbol_df[1]

	tushare_mysql.insertDatabase(each, df, Engine)

tushare_mysql.togglemysql()
Exemplo n.º 3
0
cursor = Engine.cursor(buffered=True)
cursor.execute("use {};".format(tushare_mysql.DB_NAME))

sql = "SELECT DATE FROM `{}`.`{}` ORDER BY DATE DESC LIMIT 1;".format(
    tushare_mysql.DB_NAME, model_table)
cursor.execute(sql)

date = cursor.fetchall()[0][0]
date_str = str(date)
date_tuple = date_str.split('-')
date_tuple = [int(part) for part in date_tuple]
date_tuple[2] += 1

next_date = datetime.date(*date_tuple)
next_date = str(next_date)
today = datetime.date.today()
today = str(today)

for each in symbols:
    symbol_df = tushare_mysql.getHistKlineDf(symbol=each,
                                             beginDate=next_date,
                                             endDate=today,
                                             retry_count=5)

    symbol_df[1]['volume'] = symbol_df[1]['volume'] * 100
    df = symbol_df[1]

    tushare_mysql.insertDatabase(each, df, Engine)

tushare_mysql.togglemysql()