Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def getExistingStocks():
    sql = "select distinct exchange, code from day_k"
    conn = mdb.connectAShare()

    rs = mdb.query(conn, sql)
    mdb.close(conn)

    return rs
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def getIndex(type):
    conn = mdb.connectAShare()
    data = mdb.query(conn, f"select * from idx where type = '{type}'")

    mdb.close(conn)
    return data