def get_income_sheet(code, end_date): connect("mongodb://localhost:27017/stock?", alias="income_sheet") df = pro.income(ts_code=code, start_date='20050101', end_date=end_date) df = add_key_(df) arr = df.values if len(arr) == 0: print('非交易日:' + time.strftime("%Y%m%d", time.localtime(time.time()))) pass else: for i in tqdm(range(len(arr))): IncomeSheet( arr[i, 0], arr[i, 1], arr[i, 2], arr[i, 3], arr[i, 4], arr[i, 5], arr[i, 6], arr[i, 7], arr[i, 8], arr[i, 9], arr[i, 10], arr[i, 11], arr[i, 12], arr[i, 13], arr[i, 14], arr[i, 15], arr[i, 16], arr[i, 17], arr[i, 18], arr[i, 19], arr[i, 20], arr[i, 21], arr[i, 22], arr[i, 23], arr[i, 24], arr[i, 25], arr[i, 26], arr[i, 27], arr[i, 28], arr[i, 29], arr[i, 30], arr[i, 31], arr[i, 32], arr[i, 33], arr[i, 34], arr[i, 35], arr[i, 36], arr[i, 37], arr[i, 38], arr[i, 39], arr[i, 40], arr[i, 41], arr[i, 42], arr[i, 43], arr[i, 44], arr[i, 45], arr[i, 46], arr[i, 47], arr[i, 48], arr[i, 49], arr[i, 50], arr[i, 51], arr[i, 52], arr[i, 53], arr[i, 54], arr[i, 55], arr[i, 56], arr[i, 57], arr[i, 58], arr[i, 59], arr[i, 60], arr[i, 61], arr[i, 62], arr[i, 63], arr[i, 64], arr[i, 65]).save() print('利润表数据导入完成:', end_date)
def get_adjfactor(date): connect("mongodb://localhost:27017/stock?", alias="adjust_factor") df = pro.adj_factor(ts_code='', trade_date=date) # 复权因子无论从任何时间去下载都是一样的 df = add_key_(df) arr = df.values if len(arr) == 0: print('非交易日:' + time.strftime("%Y%m%d", time.localtime(time.time()))) pass else: for i in tqdm(range(len(arr))): AdjustFactor(arr[i, 0], arr[i, 1], arr[i, 2], arr[i, 3]).save() print('复权因子数据导入完成:', date)
def get_suspend_list(date): connect("mongodb://localhost:27017/stock?", alias="suspend_list") df = pro.suspend(suspend_date=date) df = add_key_(df) arr = df.values if len(arr) == 0: print('非交易日:' + time.strftime("%Y%m%d", time.localtime(time.time()))) pass else: for i in tqdm(range(len(arr))): SuspendList(arr[i, 0], arr[i, 1], arr[i, 2], arr[i, 3], arr[i, 4]).save() print('停牌数据导入完成:', date)
def get_index_bar(code): connect("mongodb://localhost:27017/stock?", alias="index_bar") df = pro.index_daily(ts_code=code) df = add_key_(df) arr = df.values if len(arr) == 0: print('非交易日:' + time.strftime("%Y%m%d", time.localtime(time.time()))) pass else: for i in tqdm(range(len(arr))): IndexBar(arr[i, 0], arr[i, 1], arr[i, 2], arr[i, 3], arr[i, 4], arr[i, 5], arr[i, 6], arr[i, 7], arr[i, 8], arr[i, 9], arr[i, 10], arr[i, 11]).save() print('指数行情数据导入完成:', code)
def get_dailybar(date): connect("mongodb://localhost:27017/stock?", alias="origin_daily_bar") df = pro.daily(trade_date=date) df = add_key_(df) arr = df.values if len(arr) == 0: print('非交易日:' + time.strftime("%Y%m%d", time.localtime(time.time()))) pass else: for i in tqdm(range(len(arr))): OriginDailyBar(arr[i, 0], arr[i, 1], arr[i, 2], arr[i, 3], arr[i, 4], arr[i, 5], arr[i, 6], arr[i, 7], arr[i, 8], arr[i, 9], arr[i, 10], arr[i, 11]).save() print('行情数据导入完成:', date)
def get_index_weight(code, date): connect("mongodb://localhost:27017/stock?", alias="index_weight") if code == '000300.SH': code = '399300.SZ' elif code == '000905.SH': code = '399905.SZ' print('已将上交所指数代码改为深交所指数代码.') df = pro.index_weight(index_code=code, trade_date=date) df = add_key_(df) arr = df.values if len(arr) == 0: print('非交易日:' + time.strftime("%Y%m%d", time.localtime(time.time()))) pass else: for i in tqdm(range(len(arr))): IndexWeight(arr[i, 0], arr[i, 1], arr[i, 2], arr[i, 3], arr[i, 4]).save() print('指数权重数据导入完成:', code)
def get_balance_sheet(code, end_date): connect("mongodb://localhost:27017/stock?", alias="balance_sheet") df = pro.balancesheet(ts_code=code, start_date='20050101', end_date=end_date) df = add_key_(df) arr = df.values if len(arr) == 0: print('非交易日:' + time.strftime("%Y%m%d", time.localtime(time.time()))) pass else: for i in tqdm(range(len(arr))): BalanceSheet(arr[i, 0], arr[i, 1], arr[i, 2], arr[i, 3], arr[i, 4], arr[i, 5], arr[i, 6], arr[i, 7], arr[i, 8], arr[i, 9], arr[i, 10], arr[i, 11], arr[i, 12], arr[i, 13], arr[i, 14], arr[i, 15], arr[i, 16], arr[i, 17], arr[i, 18], arr[i, 19], arr[i, 20], arr[i, 21], arr[i, 22], arr[i, 23], arr[i, 24], arr[i, 25], arr[i, 26], arr[i, 27], arr[i, 28], arr[i, 29], arr[i, 30], arr[i, 31], arr[i, 32], arr[i, 33], arr[i, 34], arr[i, 35], arr[i, 36], arr[i, 37], arr[i, 38], arr[i, 39], arr[i, 40], arr[i, 41], arr[i, 42], arr[i, 43], arr[i, 44], arr[i, 45], arr[i, 46], arr[i, 47], arr[i, 48], arr[i, 49], arr[i, 50], arr[i, 51], arr[i, 52], arr[i, 53], arr[i, 54], arr[i, 55], arr[i, 56], arr[i, 57], arr[i, 58], arr[i, 59], arr[i, 60], arr[i, 61], arr[i, 62], arr[i, 63], arr[i, 64], arr[i, 65], arr[i, 66], arr[i, 67], arr[i, 68], arr[i, 69], arr[i, 70], arr[i, 71], arr[i, 72], arr[i, 73], arr[i, 74], arr[i, 75], arr[i, 76], arr[i, 77], arr[i, 78], arr[i, 79], arr[i, 80], arr[i, 81], arr[i, 82], arr[i, 83], arr[i, 84], arr[i, 85], arr[i, 86], arr[i, 87], arr[i, 88], arr[i, 89], arr[i, 90], arr[i, 91], arr[i, 92], arr[i, 93], arr[i, 94], arr[i, 95], arr[i, 96], arr[i, 97], arr[i, 98], arr[i, 99], arr[i, 100], arr[i, 101], arr[i, 102], arr[i, 103], arr[i, 104], arr[i, 105], arr[i, 106], arr[i, 107], arr[i, 108], arr[i, 109], arr[i, 110], arr[i, 111], arr[i, 112], arr[i, 113], arr[i, 114], arr[i, 115], arr[i, 116], arr[i, 117], arr[i, 118], arr[i, 119], arr[i, 120], arr[i, 121], arr[i, 122], arr[i, 123], arr[i, 124], arr[i, 125], arr[i, 126], arr[i, 127], arr[i, 128], arr[i, 129], arr[i, 130], arr[i, 131], arr[i, 132], arr[i, 133], arr[i, 134], arr[i, 135], arr[i, 136], arr[i, 137]).save() print('资产负债表数据导入完成:', end_date)