裝pytdx 簡單示范 from pytdx.hq import TdxHq_API
api = TdxHq_API()
# 數(shù)據(jù)獲取接口一般返回list結(jié)構(gòu),
with api.connect('119.147.212.81', 7709):
# 返回普通list
data = api.get_security_bars(9, 0, '000001', 0, 10)
print(data)1.2.3.4.5.6.7. 輸出結(jié)果[OrderedDict([('open', 14.75), ('close', 14.8), ('high', 14.88), ('low', 14.52), ('vol', 1057659.0), ('amount', 1561368448.0), ('year', 2023), ('month', 1), ('day', 9), ('hour', 15), ('minute', 0), ('datetime', '2023-01-09 15:00')]), OrderedDict([('open', 14.76), ('close', 14.44), ('high', 14.89), ('low', 14.39), ('vol', 1269423.0), ('amount', 1851093760.0), ('year', 2023), ('month', 1), ('day', 10), ('hour', 15), ('minute', 0), ('datetime', '2023-01-10 15:00')]), OrderedDict([('open', 14.45), ('close', 14.67), ('high', 14.78), ('low', 14.39), ('vol', 830566.0), ('amount', 1217450752.0), ('year', 2023), ('month', 1), ('day', 11), ('hour', 15), ('minute', 0), ('datetime', '2023-01-11 15:00')]), OrderedDict([('open', 14.77), ('close', 14.67), ('high', 14.77), ('low', 14.53), ('vol', 625694.0), ('amount', 914367680.0), ('year', 2023), ('month', 1), ('day', 12), ('hour', 15), ('minute', 0), ('datetime', '2023-01-12 15:00')]), OrderedDict([('open', 14.67), ('close', 14.95), ('high', 14.95), ('low', 14.55), ('vol', 949085.0), ('amount', 1407181056.0), ('year', 2023), ('month', 1), ('day', 13), ('hour', 15), ('minute', 0), ('datetime', '2023-01-13 15:00')]), OrderedDict([('open', 14.95), ('close', 15.08), ('high', 15.28), ('low', 14.85), ('vol', 1560039.0), ('amount', 2356399872.0), ('year', 2023), ('month', 1), ('day', 16), ('hour', 15), ('minute', 0), ('datetime', '2023-01-16 15:00')]), OrderedDict([('open', 15.13), ('close', 14.97), ('high', 15.18), ('low', 14.77), ('vol', 935834.0), ('amount', 1396151552.0), ('year', 2023), ('month', 1), ('day', 17), ('hour', 15), ('minute', 0), ('datetime', '2023-01-17 15:00')]), OrderedDict([('open', 14.95), ('close', 15.11), ('high', 15.18), ('low', 14.91), ('vol', 718434.0), ('amount', 1083362944.0), ('year', 2023), ('month', 1), ('day', 18), ('hour', 15), ('minute', 0), ('datetime', '2023-01-18 15:00')]), OrderedDict([('open', 15.13), ('close', 15.09), ('high', 15.25), ('low', 14.87), ('vol', 641875.0), ('amount', 963744640.0), ('year', 2023), ('month', 1), ('day', 19), ('hour', 15), ('minute', 0), ('datetime', '2023-01-19 15:00')]), OrderedDict([('open', 15.16), ('close', 15.13), ('high', 15.24), ('low', 15.0), ('vol', 608590.0), ('amount', 920144832.0), ('year', 2023), ('month', 1), ('day', 20), ('hour', 15), ('minute', 0), ('datetime', '2023-01-20 15:00')])]1. 一、基本行情接口索引1 : 獲取股票行情可以獲取多只股票的行情信息 需要傳入一個列表,每個列表由一個市場代碼, 一個股票代碼構(gòu)成的元祖構(gòu)成 [ (市場代碼1, 股票代碼1),(市場代碼2, 股票代碼2) … (市場代碼n, 股票代碼n) ] 如:api.get_security_quotes([(0, '000001'), (1, '600300')]) 2 : 獲取k線K線種類: 0 5分鐘K線 1 15分鐘K線 2 30分鐘K線 3 1小時K線 4 日K線 5 周K線 6 月K線 7 1分鐘 81分鐘K線 9 日K線 10 季K線 11 年K線 api.get_security_bars(9,0, '000001', 4, 3) 3 : 獲取市場股票數(shù)量api.get_security_count(0) 4 : 獲取股票列表api.get_security_list(1, 0) 5 : 獲取指數(shù)k線api.get_index_bars(9,1, '000001', 1, 2) 6 : 查詢分時行情api.get_minute_time_data(1, '600300') 7 : 查詢歷史分時行情api.get_history_minute_time_data(TDXParams.MARKET_SH, '600300', 20161209) 8 : 查詢分筆成交api.get_transaction_data(TDXParams.MARKET_SZ, '000001', 0, 30) 9 : 查詢歷史分筆成交api.get_history_transaction_data(TDXParams.MARKET_SZ, '000001', 0, 10, 20170209) 10 : 查詢公司信息目錄api.get_company_info_category(TDXParams.MARKET_SZ, '000001') 11 : 讀取公司信息詳情api.get_company_info_content(0, '000001', '000001.txt', 0, 100) 12 : 讀取除權(quán)除息信息api.get_xdxr_info(1, '600300') 13 : 讀取財務信息api.get_finance_info(0, '000001') 14 : 讀取k線信息get_k_data('000001','2017-07-03','2017-07-10') 15 :讀取板塊信息api.get_and_parse_block_info(TDXParams.BLOCK_SZ) 二、擴展行情接口APIfrom pytdx.exhq import * 1: 獲取市場代碼api.get_markets() 2: 查詢代碼列表api.get_instrument_info(0, 100) 3: 查詢市場中商品數(shù)量api.get_instrument_count() 4: 查詢五檔行情api.get_instrument_quote(47, "IF1709") 5: 查詢分時行情api.get_minute_time_data(47, "IF1709") 6: 查詢歷史分時行情api.get_history_minute_time_data(31, "00020", 20170811) 7: 查詢k線數(shù)據(jù)api.get_instrument_bars(TDXParams.KLINE_TYPE_DAILY, 8, "10000843", 0, 100) 8: 查詢分筆成交api.get_transaction_data(31, "00020") api.get_history_transaction_data(47, "IFL0", 20170810, start=1800) 9: 查詢歷史分筆成交api.get_history_transaction_data(31, "00020", 20170810)
|