"""

Python 獲取滬深A股票資金流曏數據

小單:5萬以下

中單:5萬~20萬

大單:20萬~100萬

特大單:成交額>=100萬

數據內容:代碼,交易日期,

小單、中單、大單、特大單的

買入量,金額,賣出量,賣出金額

淨流入量(手),淨流入額(萬元)

"""

import time

import datetime

import tushare as ts

#注冊獲取token

ts.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 df

def 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 df

def 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

"""

ogp光學影像測量機

影像三次元

ogp光學影像測量機

ogp