Comments (12)
通过内置一个交易日历,就可以把通达信的模式改进成常用的 起始日期-结束日期的模式获取数据 @rainx
from pytdx.
要不我把你的改一下发个pr给你?
from pytdx.
这里还有个改进点,就是如果那个日期不交易,自动往前/往后回溯,把区间调整到交易的区间内
我写在quantaxis里面了...
def QA_util_get_real_date(date, trade_list, towards):
#print(date in trade_list)
if towards == 1:
while date not in trade_list:
date = str(datetime.datetime.strptime(
date, '%Y-%m-%d') + datetime.timedelta(days=1))[0:10]
else:
return date
elif towards == -1:
while date not in trade_list:
date = str(datetime.datetime.strptime(
date, '%Y-%m-%d') - datetime.timedelta(days=1))[0:10]
else:
return date
其中,towards负责向前/向后
比如 起始日期如果不交易,只能向后推交易日期,而结束日期如果不交易,就需要向前回溯
from pytdx.
def QA_fetch_get_stock_day(code, start_date,end_date,ip='119.147.212.81',port=7709):
start_date=QA_util_get_real_date(start_date,trade_date_sse,1)
end_date=QA_util_get_real_date(end_date,trade_date_sse,-1)
with api.connect(ip, port):
# 判断end_date在哪个位置
index_0=str(datetime.date.today())
index_of_index_0=trade_date_sse.index(index_0)
index_of_index_end=trade_date_sse.index(end_date)
index_of_index_start=trade_date_sse.index(start_date)
index_of_end=index_of_index_0-index_of_index_end
index_length=index_of_index_end+1-index_of_index_start
data = api.get_security_bars(9, 0, code,index_of_end, index_length) # 返回普通list
data = api.to_df(api.get_security_bars(9, 0, code,index_of_end, index_length)) # 返回DataFrame
return data
print(QA_fetch_get_stock_day('000001','2017-07-03','2017-07-10'))
print(QA_fetch_get_stock_day('000001','2017-07-01','2017-07-09'))
open close high low vol amount year month day hour \
0 9.40 9.40 9.43 9.34 388349.0 3.644659e+08 2017 7 3 15
1 9.40 9.34 9.41 9.30 488362.0 4.565770e+08 2017 7 4 15
2 9.29 9.37 9.38 9.27 567720.0 5.292941e+08 2017 7 5 15
3 9.36 9.40 9.41 9.31 738911.0 6.913872e+08 2017 7 6 15
4 9.37 9.47 9.48 9.34 760369.0 7.170844e+08 2017 7 7 15
5 9.45 9.59 9.66 9.44 1360815.0 1.303090e+09 2017 7 10 15
minute datetime
0 0 2017-07-03 15:00
1 0 2017-07-04 15:00
2 0 2017-07-05 15:00
3 0 2017-07-06 15:00
4 0 2017-07-07 15:00
5 0 2017-07-10 15:00
open close high low vol amount year month day hour \
0 9.40 9.40 9.43 9.34 388349.0 364465856.0 2017 7 3 15
1 9.40 9.34 9.41 9.30 488362.0 456577024.0 2017 7 4 15
2 9.29 9.37 9.38 9.27 567720.0 529294112.0 2017 7 5 15
3 9.36 9.40 9.41 9.31 738911.0 691387200.0 2017 7 6 15
4 9.37 9.47 9.48 9.34 760369.0 717084352.0 2017 7 7 15
minute datetime
0 0 2017-07-03 15:00
1 0 2017-07-04 15:00
2 0 2017-07-05 15:00
3 0 2017-07-06 15:00
4 0 2017-07-07 15:00
from pytdx.
from pytdx.
from pytdx.
好的,我看下..
from pytdx.
@yutiansut 已经merge 了.. 👍
from pytdx.
@rainx 我觉得其他的也可以这么加,喵喵喵
from pytdx.
恩,关于交易日期的计算,我之前有一个库 https://github.com/rainx/cn_stock_holidays 应该也可以,我这边会持续更新这个日期...
另外,关于import 的时候使用 . 相对语法的问题,我之前看到谷歌的一个开发者规范,那边建议不适用相对导入,我最近正在实践,我觉得你也可以参考一下
http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/#id1 @yutiansut
from pytdx.
指数的日期,并不是和个股的日期一一对应的,因为个股有停牌的情况,这个方法还是不行啊。
from pytdx.
@jeffery82 交易日期的计算是取近似范围 然后再loc出来
from pytdx.
Related Issues (20)
- 扩展行情的IP都没有可以连接的。 HOT 1
- 扩展行情里面有没有可以获取多个行情quotes的接口?
- get_security_list 请问一下这个是用来获取股票列表的吗? HOT 2
- 请教一下下载的财务数据的 315个列字段的意义问题. HOT 1
- get_security_list这个函数的pre_close有误 HOT 10
- get_security_bars取出来的vol值差了1个 HOT 4
- 跳过的4个字节估计是上一日收盘价
- get_security_list获取的数据中的pre_close有解析正确有些解析不正确 HOT 1
- 不支持美股了?
- AttributeError: __enter__
- 怎么获取行情服务器的IP HOT 1
- 官方文档代码某行缺失 HOT 1
- 请问有办法获取涨停价和跌停价吗 HOT 1
- 可以获取level2的逐笔成交明细吗? HOT 1
- 心跳包还有多线程有没有详细的文档解释? HOT 1
- TdxDailyBarReader() 读取 上海 688 的时候,异常 Unknown security type ! HOT 1
- 盘口价格是不是颠倒了 HOT 1
- exhq.py文件 运行报错 AttributeError: __enter__
- debian python 3.7 get_security_quotes 解析 servertime 报错 HOT 2
- 如何判断股票代码是否指数
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytdx.