Git Product home page Git Product logo

Comments (12)

yutiansut avatar yutiansut commented on July 4, 2024

通过内置一个交易日历,就可以把通达信的模式改进成常用的 起始日期-结束日期的模式获取数据 @rainx

from pytdx.

yutiansut avatar yutiansut commented on July 4, 2024

要不我把你的改一下发个pr给你?

from pytdx.

yutiansut avatar yutiansut commented on July 4, 2024

这里还有个改进点,就是如果那个日期不交易,自动往前/往后回溯,把区间调整到交易的区间内
我写在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.

yutiansut avatar yutiansut commented on July 4, 2024
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.

yutiansut avatar yutiansut commented on July 4, 2024

#6

from pytdx.

yutiansut avatar yutiansut commented on July 4, 2024

在quantaxis里的应用

from pytdx.

rainx avatar rainx commented on July 4, 2024

好的,我看下..

from pytdx.

rainx avatar rainx commented on July 4, 2024

@yutiansut 已经merge 了.. 👍

from pytdx.

yutiansut avatar yutiansut commented on July 4, 2024

@rainx 我觉得其他的也可以这么加,喵喵喵

from pytdx.

rainx avatar rainx commented on July 4, 2024

恩,关于交易日期的计算,我之前有一个库 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.

jeffery82 avatar jeffery82 commented on July 4, 2024

指数的日期,并不是和个股的日期一一对应的,因为个股有停牌的情况,这个方法还是不行啊。

from pytdx.

yutiansut avatar yutiansut commented on July 4, 2024

@jeffery82 交易日期的计算是取近似范围 然后再loc出来

from pytdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.