用pytdx写一个导出某一只股票的十天明细数据。
时间: 2024-06-11 17:06:57 浏览: 155
以下是使用pytdx导出某一只股票的十天明细数据的示例代码:
``` python
from pytdx.hq import TdxHq_API
import pandas as pd
api = TdxHq_API()
# 连接TDX行情服务器
api.connect('119.147.212.81', 7709)
# 获取股票代码
stock_code = '000001'
# 获取股票行情数据
quotes = api.get_security_quotes([(1, stock_code)])
# 获取股票市场信息
market_code = quotes[0]['market']
# 获取股票K线数据
klines = api.get_security_bars(9, market_code, stock_code, 0, 10)
# 将K线数据转换为DataFrame
df = pd.DataFrame(klines, columns=['datetime', 'open', 'high', 'low', 'close', 'amount', 'volume'])
# 将时间戳转换为日期格式
df['datetime'] = pd.to_datetime(df['datetime'])
# 输出DataFrame
print(df)
```
在上面的代码中,我们首先使用`TdxHq_API`类连接到TDX行情服务器。然后,我们获取股票代码和市场信息,以便从服务器上获取股票行情数据。接着,我们使用`get_security_bars`方法获取股票的K线数据,并将其转换为DataFrame。最后,我们将时间戳转换为日期格式,并输出结果。
阅读全文
相关推荐

















