def getInfoFromDb(exchange, code): sql = f"select * from info where exchange = '{exchange}' and code = '{code}'" conn = mdb.connectAShare() data = mdb.query(conn, sql) mdb.close(conn) return data
def getExistingStocks(): sql = "select distinct exchange, code from day_k" conn = mdb.connectAShare() rs = mdb.query(conn, sql) mdb.close(conn) return rs
def getDailyK(exchange, code, startDate=None, endDate=None): sql = f"select date, open, close, high, low, volume from day_k where exchange = '{exchange}' and code = '{code}'" if startDate != None: sql = sql + f" and date >= '{startDate}'" if endDate != None: sql = sql + f" and date <= '{endDate}'" sql = sql + " order by date" conn = mdb.connectAShare() data = mdb.query(conn, sql) mdb.close(conn) data.index = pd.to_datetime(data['date']) return data
def getStartDate(exchange, code): maxDateSql = "select max(date) as max_date from day_k where exchange = '{exchange}' and code = '{code}'" conn = mdb.connectAShare() rs = mdb.query(conn, maxDateSql.format(exchange = exchange, code = code)) conn.close() maxDate = rs.loc[0, 'max_date'] if maxDate != None: startDate = maxDate + timedelta(days=1) else: startDate = info.getIpoDate(exchange, code) if startDate == None: startDate = date(1980, 1, 1) return startDate
def getIndex(type): conn = mdb.connectAShare() data = mdb.query(conn, f"select * from idx where type = '{type}'") mdb.close(conn) return data