股票实时数据api(Python 获取沪深A股票资金流向数据)
时间:2023/12/04 13:55:35 编辑:
"""Python 获取沪深A股票资金流向数据小单:5万以下中单:5万~20万大单:20万~100万特大单:成交额>=100万数据内容:代码,交易日期,小单、中单、大单、特大单的买入量,金额,卖出量,卖出金额净流入量(手),净流入额(万元)"""import timeimport datetimeimport tushare as ts#注册获取tokents.set_token('your token')pro = ts.pro_api()def get_data_moneyflow(trade_date='', retry_count=3, pause=2): for m in range(retry_count): try: df = pro.moneyflow(trade_date=trade_date, fields='ts_code,trade_date,buy_sm_vol,buy_sm_amount,sell_sm_vol,sell_sm_amount,' 'buy_md_vol,buy_md_amount,sell_md_vol,sell_md_amount,buy_lg_vol,buy_lg_amount,' 'sell_lg_vol,sell_lg_amount,buy_elg_vol,buy_elg_amount,sell_elg_vol,' 'sell_elg_amount,net_mf_vol,net_mf_amount') except Exception as err: print(err) time.sleep(pause) else: return dfdef get_data_moneyflow_a(ts_code='', start_date='', end_date='', retry_count=3, pause=2): for m in range(retry_count): try: df = pro.moneyflow(ts_code=ts_code, start_date=start_date, end_date=end_date, fields='ts_code,trade_date,buy_sm_vol,buy_sm_amount,sell_sm_vol,sell_sm_amount,' 'buy_md_vol,buy_md_amount,sell_md_vol,sell_md_amount,buy_lg_vol,buy_lg_amount,' 'sell_lg_vol,sell_lg_amount,buy_elg_vol,buy_elg_amount,sell_elg_vol,' 'sell_elg_amount,net_mf_vol,net_mf_amount') except Exception as err: print(err) time.sleep(pause) else: return dfdef date_func(days=0): try: time_temp = datetime.datetime.now() - datetime.timedelta(days=days) dt = time_temp.strftime('%Y%m%d') return dt except Exception as err: print('end_dt is err', err)if __name__ == '__main__': # 日期格式为 YYYYMMDD 如 20221116 # 行情终止日期 end_dt = date_func(days=0) start_dt = date_func(days=365) print('start_dt,end_dt:', start_dt, end_dt) # 以南岭民爆为例 code_wm = '002096.SZ' # 获取全部股票20221118资金流向数据 df_wm = get_data_moneyflow(trade_date=end_dt, retry_count=3, pause=2) print(df_wm.head(8)) # 获取南岭民爆一年的资金流向数据 df_wm = get_data_moneyflow_a(ts_code=code_wm, start_date=start_dt, end_date=end_dt, retry_count=3, pause=2) print(df_wm.head(8)) """运行结果 start_dt,end_dt: 20211118 20221118 ts_code trade_date buy_sm_vol ... sell_elg_amount net_mf_vol net_mf_amount 0 002581.SZ 20221118 31906 ... 551.08 11505 2039.12 1 000978.SZ 20221118 93692 ... 773.55 -12086 -854.13 2 600685.SH 20221118 44848 ... 3092.84 -7268 -1836.35 3 300317.SZ 20221118 33050 ... 0.00 -13751 -732.78 4 601995.SH 20221118 22314 ... 1288.41 -7037 -2666.79 5 002908.SZ 20221118 141874 ... 2897.70 44426 8110.69 6 000925.SZ 20221118 35944 ... 149.63 3719 303.11 7 300068.SZ 20221118 124241 ... 7497.99 -45149 -8517.49 [8 rows x 20 columns] ts_code trade_date buy_sm_vol ... sell_elg_amount net_mf_vol net_mf_amount 0 002096.SZ 20221118 16154 ... 548.69 -10859 -1240.70 1 002096.SZ 20221117 20958 ... 0.00 6980 807.20 2 002096.SZ 20221116 13252 ... 0.00 -3940 -447.01 3 002096.SZ 20221115 14093 ... 175.40 3712 419.92 4 002096.SZ 20221114 18685 ... 164.74 -7163 -813.36 5 002096.SZ 20221111 16561 ... 0.00 -872 -97.92 6 002096.SZ 20221110 19362 ... 0.00 -1252 -141.40 7 002096.SZ 20221109 17096 ... 161.10 740 86.27 [8 rows x 20 columns] Process finished with exit code 0 """""" www.pgabc.cn www.wmdbsoft.com Pgabc 2022000036 更多函数,安装工具包 pip install pgabc pgabc@sohu.com """
相关资讯
-
-
路程假(婚假太短没空结婚?话题冲上热搜,官方回应了)
浏览:25 2024-05-09
-
-
中国人从此站立起来了(别再讹传,史实当确,毛主席:没说过“中国人民从此站立起来了”)
浏览:21 2024-05-09
-
-
临渭区(临渭区司法局“军人军属法律服务联络点”挂牌(图))
浏览:21 2024-05-09
-
-
名侦探柯南剧场版贝克街的亡灵(贝克街的亡灵最经典最受欢迎《柯南》剧场版TOP10)
浏览:20 2024-05-09
-
-
玖玖色网(沿着高速看中国丨久久不见久久见)
浏览:18 2024-05-09
-
-
劳莱斯(镜报专家团预测英超前四:多数看好利物浦夺冠)
浏览:21 2024-05-09