Python調(diào)用pytdx的代碼示例
安裝pytdx
pip install 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)
輸出結(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 : 獲取股票行情
可以獲取多只股票的行情信息
需要傳入一個列表,每個列表由一個市場代碼, 一個股票代碼構(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 : 讀取財務(wù)信息
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)
二、擴(kuò)展行情接口API
from 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)
到此這篇關(guān)于Python調(diào)用pytdx的代碼示例的文章就介紹到這了,更多相關(guān)Python調(diào)用pytdx內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python接口自動化淺析登錄接口測試實(shí)戰(zhàn)
本文主要接好了python接口自動化的接口概念、接口用例設(shè)計及登錄,跟隨本文章來進(jìn)行一個接口用例設(shè)計及登錄接口測試實(shí)戰(zhàn),有需要的朋友可以參考下2021-08-08基于Python實(shí)現(xiàn)自動用小寫字母替換文件后綴的大寫字母
本文介紹基于Python語言,基于一個大文件夾,遍歷其中的多個子文件夾,對于每一個子文件夾中的大量文件,批量將其文件的名稱或后綴名中的字母由大寫修改為小寫的方法,文中有相關(guān)的代碼示例供大家參考,需要的朋友可以參考下2024-04-04Python實(shí)現(xiàn).gif圖片拆分為.png圖片的簡單示例
有時候需要把GIF圖片分解成一張一張的靜態(tài)圖,jpg或者png格式,下面這篇文章主要給大家介紹了關(guān)于Python實(shí)現(xiàn).gif圖片拆分為.png圖片的相關(guān)資料,需要的朋友可以參考下2023-01-01