示例#1
0
def get_hk_hold(trade_date):
    try:
        db = dbm.open(os.getcwd() + '/dbms/hk_hold.dbm', 'c')
        ds = ds_ts.Datasource()
        df = ds.get_hk_hold(trade_date=trade_date)
        print(df)
        for index in df.index:
            if df.loc[index, 'exchange'] != 'SH' and df.loc[index, 'exchange'] != 'SZ':
                continue
            code = df.loc[index, 'ts_code']
            trade_date = df.loc[index, 'trade_date']
            vol = int(df.loc[index, 'vol'])
            ratio = df.loc[index, 'ratio']

            data = None
            hold = {}
            try:
                data = db[code]
            except KeyError:
                pass
            if data is not None:
                hold = pickle.loads(data)

            hold[trade_date] = {'vol': vol, 'ratio': ratio}
            print(hold)
            db[code] = pickle.dumps(hold)

    except Exception as err:
        print(err)
    finally:
        db.close()
示例#2
0
def write_codetable2dbm():
    try:
        db = dbm.open(os.getcwd() + '/dbms/codetable.dbm', 'c')
        ds = dsts.Datasource()
        df = ds.get_code_list()
        for row in df.itertuples():
            db[row.ts_code] = row.name
        db.close()
    except Exception as err:
        print(err)
示例#3
0
def write_codetable2db():
    try:
        mysql = mh.Mysql_Helper()
        ds = dsts.Datasource()
        df = ds.get_code_list()
        for index in df.index:
            sql = "replace into code (obj,name,updatetime) values ('%s','%s',now())" % (
                df.loc[index, 'ts_code'], df.loc[index, 'name'])
            print(sql)
            mysql.runsql(sql)
    except Exception as err:
        print(err)
        mysql.close()
示例#4
0
def write_codetable2db():
    try:
        mysql = mh.Mysql_Helper()
        ds = dsts.Datasource()
        df = ds.get_code_list()
        for row in df.itertuples():
            sql = "replace into code (obj,name,updatetime) values ('%s','%s',now())" \
                  % (row.ts_code, row.name)
            print(sql)
            mysql.runsql(sql)
    except Exception as err:
        print(err)
        mysql.close()
示例#5
0
def get_stock_name(code):
    global code_table
    try:
        if code_table is None:
            code_table = {}
            ds = dsts.Datasource()
            df = ds.get_code_list()
            for index in df.index:
                code_table[df.loc[index, 'ts_code']] = df.loc[index, 'name']
        if code not in code_table:
            return ''
        else:
            return code_table[code]
    except Exception as err:
        print(err)
        return ''
示例#6
0
from datasource_tushare import datasource_ts as ds_ts
from datasource_tushare import mysql_helper as mh
import math

if __name__ == '__main__':
    try:
        mysql = mh.Mysql_Helper()
        ds = ds_ts.Datasource()
        df = ds.get_code_list()
        for row in df.itertuples():
            # print(row) print(row.Index, row.ts_code, row.symbol, row.name, row.area, row.industry, row.list_date)
            df2 = ds.get_month_line(row.ts_code, '19800101')
            if df2 is None:
                continue
            for row2 in df2.itertuples():
                print(row2)
                if math.isnan(row2.close):
                    continue
                sql = "replace into monthline2_qfq (obj,date,open,high,low,close,vol,amout,updatetime) values " \
                      "('%s','%s','%s','%s','%s','%s','%s','%s',now())"\
                    % (row2.ts_code, row2.trade_date, row2.open, row2.high, row2.low, row2.close, row2.vol, row2.amount)
                print(sql)
                mysql.runsql(sql)
    except Exception as err:
        print(err)
    finally:
        mysql.close()
示例#7
0
                code = result[1][0:6]
                date = result[0]
                d[code] = date
                #print(date, code)
            return d
    except Exception as err:
        print(err)
    finally:
        mysql.close()


if __name__ == '__main__':
    #print(getlastdayline())
    try:
        mysql = mh.Mysql_Helper()
        ds = dsts.Datasource()
        df = ds.get_todayline()
        if df is None:
            print("get code list error")
        count = 0
        for row in df.itertuples():
            print(row)
            ts_code = cctc.change_code2tscode(row.code)
            if ts_code is None:
                print(ts_code)
                continue
            count += 1
            #sql = "replace into dayline (obj,date,open,high,low,close,preclose,vol,amount,updatetime) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s',now())" \
            #      % (ts_code, row.trade_date, row.open, row.high, row.low, row.close, row.pre_close, row.vol,
            #         row.amount)
            #print(sql)