def getAllStock(): mysqlDBSession = MySqlDBConnection().getMysqlDBSession() result = mysqlDBSession.execute( text( "select ts_code, name from stock_basic" ) ) datas = [] for res in result: datas.append( { "tsCode": res[ 0 ], "name": res[ 1 ] } ) result.close() mysqlDBSession.close() return datas
def getIndexDatas(self, SQL): StatisticsLog().getLog().info("开始获取指数基础数据") mySqlDBSession = MySqlDBConnection().getMysqlDBSession() result = mySqlDBSession.execute(text(SQL)) datas = [] for row in result: datas.append([row[0], row[1], row[2], row[3], row[4]]) result.close() mySqlDBSession.close() StatisticsLog().getLog().info("获取指数数据完毕") return datas
def getStockDatas(self, SQL, tsCode): StatisticsLog().getLog().info("开始获取股票基础数据") mySqlDBSession = MySqlDBConnection().getMysqlDBSession() result = mySqlDBSession.execute(text(SQL), {"tsCode": tsCode}) datas = [] for row in result: datas.append([row[0], row[1], row[2], row[3], row[4]]) result.close() mySqlDBSession.close() StatisticsLog().getLog().info("获取股票基础数据完毕") return datas
def getTsCodes(self): StatisticsLog().getLog().info("开始获取股票基础数据") mySqlDBSession = MySqlDBConnection().getMysqlDBSession() result = mySqlDBSession.execute( text("select ts_code from stock_basic")) mySqlDBSession.close() datas = [] for row in result: datas.append(row[0]) result.close() mySqlDBSession.close() StatisticsLog().getLog().info("获取股票基础数据完毕") return datas
def getAllSZSEIndex(): mysqlDBSession = MySqlDBConnection().getMysqlDBSession() result = mysqlDBSession.execute( text( "select trade_date, `open`, high, low, `close`, `vol` from index_line_day_szse where ts_code=:tsCode order by trade_date" ) ) datas = [] index = 0 for row in result: tradeDate = row[ 0 ] open1 = row[ 1 ] # 不知为啥,open会有警告,所以改成open1 high = row[ 2 ] low = row[ 3 ] close = row[ 4 ] volume = row[ 5 ] datas.insert( index, [ tradeDate, open1, close, low, high, volume ] ) index += 1 result.close() mysqlDBSession.close() return datas
def getAllNameChangeDatas(self): StatisticsLog().getLog().info("开始加载股票曾用名数据") mySqlDBSession = MySqlDBConnection().getMysqlDBSession() # result = mySqlDBSession.execute( text( "select ts_code, name, start_date, end_date, change_reason from name_change where ts_code='600539.SH' order by ts_code, start_date asc" ) ) result = mySqlDBSession.execute( text( "select ts_code, name, start_date, end_date, change_reason from name_change order by ts_code, start_date asc" )) datas = [] for row in result: datas.append([row[0], row[1], row[2], row[3], row[4]]) result.close() mySqlDBSession.close() StatisticsLog().getLog().info("股票曾用名数据加载完毕") return datas