pip install pytdx
from pytdx.hq import TdxHq_API
api = TdxHq_API()
# 数据获取接口一般返回list结构,
with api.connect('119.147.212.81', 7709):
# 返回普通list
data = api.get_security_bars(9, 0, '000001', 0, 10)
print(data)
[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),(市场代码2, 股票代码2) … (市场代码n, 股票代码n) ]
如:api.get_security_quotes([(0, '000001'), (1, '600300')])
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)
api.get_security_count(0)
api.get_security_list(1, 0)
api.get_index_bars(9,1, '000001', 1, 2)
api.get_minute_time_data(1, '600300')
api.get_history_minute_time_data(TDXParams.MARKET_SH, '600300', 20161209)
api.get_transaction_data(TDXParams.MARKET_SZ, '000001', 0, 30)
api.get_history_transaction_data(TDXParams.MARKET_SZ, '000001', 0, 10, 20170209)
api.get_company_info_category(TDXParams.MARKET_SZ, '000001')
api.get_company_info_content(0, '000001', '000001.txt', 0, 100)
api.get_xdxr_info(1, '600300')
api.get_finance_info(0, '000001')
get_k_data('000001','2017-07-03','2017-07-10')
api.get_and_parse_block_info(TDXParams.BLOCK_SZ)
from pytdx.exhq import *
api.get_markets()
api.get_instrument_info(0, 100)
api.get_instrument_count()
api.get_instrument_quote(47, "IF1709")
api.get_minute_time_data(47, "IF1709")
api.get_history_minute_time_data(31, "00020", 20170811)
api.get_instrument_bars(TDXParams.KLINE_TYPE_DAILY, 8, "10000843", 0, 100)
api.get_transaction_data(31, "00020")
api.get_history_transaction_data(47, "IFL0", 20170810, start=1800)
api.get_history_transaction_data(31, "00020", 20170810)