Quantitative transaction data acquisition interface

Overview

If you want to do good things, you must first sharpen your tools. If you want to do quantification, data is the basic! In this article, we will introduce how to obtain data.

Data interface type

  • Get a list of stocks in a specified industry and sector
  • history_bars: Specify historical data of stock contracts
  • get_fundamentals: Query financial data

Industry & Sector Stock Class Table

Stock code & code complement

RiceQuant shares

Shanghai
Insert picture description here
Stock Exchange: Shenzhen Stock Exchange:
Insert picture description here

Automatic search and completion of stocks

  • Windows users: type ctrl + i
  • Mac users: type command + i

When we enter this key combination, RiceQuant online IDE will enter the code search and auto-completion mode.
Insert picture description here
Then we can enter any of them to search and auto-complete.

  • Stock digital code: automatically complete to the stock digital code, such as "000001.XSHE"
  • Full Chinese name of the stock: Automatically complete the full Chinese name of the stock, such as "Kweichow Moutai"
  • Stock pinyin abbreviation: automatically completes the full Chinese name of the stock, because the stock pinyin abbreviation is not unique, for example, ZSDC is completed as "China Merchants Real Estate"

Get industry

To obtain stock data of a certain industry, the code is as follows:

industry (code)

Insert picture description here
return:

The order_book_id or order_book_id list of stocks belonging to the industry.

example:

[In]
industry('A01')
[Out]
['600540.XSHG', '600371.XSHG', '600359.XSHG', '600506.XSHG',...]
[In]
industry(industry_code.A01)
[Out]
['600540.XSHG', '600371.XSHG', '600359.XSHG', '600506.XSHG',...]

Get section

To get a list of stocks in a certain sector, the code is as follows:

sector(code, market='cn')

Insert picture description here
return:

The order_book_id or order_book_id list of stocks belonging to the sector.

example:

[In]sector('Energy')
[Out]
['300023.XSHE', '000571.XSHE', '600997.XSHG', '601798.XSHG', '603568.XSHG', .....]
[In]sector(sector_code.Energy)
[Out]
['300023.XSHE', '000571.XSHE', '600997.XSHG', '601798.XSHG', '603568.XSHG', .....]

The supported industries are as follows, if you want to understand the global industry standard classification standard, please refer to the global industry standard classification:
Insert picture description here

Code display

def init(context):
    # 在context中保存全局变量
    context.s1 = "000001.XSHE"
    context.stock = "000007.XSHE"

    # 获取计算机通信行业的一些公司股票代码
    context.stock_list = industry("C39")

    # 获取能源板块的股票代码
    context.sector_list = sector("energy")

    # 获取沪深300的指数股票
    context.index_list = index_components("000300.XSHG")

    # 调试输出
    logger.info(context.stock_list)
    logger.info(context.sector_list)
    logger.info(context.index_list)
   
输出结果:
2016-01-03
INFO
['300847.XSHE', '601138.XSHG', '688183.XSHG', '688138.XSHG', '000810.XSHE', '603380.XSHG', '600363.XSHG', '600980.XSHG', '300
211.XSHE', '600870.XSHG', '688181.XSHG', '600353.XSHG', '688081.XSHG', '000823.XSHE', '600745.XSHG', '002308.XSHE', '600839.X
SHG', '002528.XSHE', '603516.XSHG', '300666.XSHE', '688123.XSHG', '002222.XSHE', '002841.XSHE', '300078.XSHE', '688418.XSHG',
'002992.XSHE', '688020.XSHG', '603002.XSHG', '300205.XSHE', '300390.XSHE', '000066.XSHE', '300046.XSHE', '688208.XSHG', '688
027.XSHG', '300213.XSHE', '600405.XSHG', '600171.XSHG', '300455.XSHE', '300077.XSHE', '002983.XSHE', '002414.XSHE', '000687.X
SHE', '002806.XSHE', '300739.XSHE', '000050.XSHE', '300042.XSHE', '300458.XSHE', '002888.XSHE', '300686.XSHE', '002993.XSHE',
'300939.XSHE', '600764.XSHG', '002156.XSHE', '603160.XSHG', '600584.XSHG', '603803.XSHG', '002897.XSHE', '300327.XSHE', '300
811.XSHE', '300456.XSHE', '300548.XSHE', '605118.XSHG', '002660.XSHE', '002681.XSHE', '300831.XSHE', '002089.XSHE', '002161.X
SHE', '300088.XSHE', '002241.XSHE', '002115.XSHE', '688195.XSHG', '300752.XSHE', '002792.XSHE', '688079.XSHG', '688667.XSHG',
'603023.XSHG', '300835.XSHE', '002655.XSHE', '002579.XSHE', '002180.XSHE', '603019.XSHG', '300220.XSHE', '002119.XSHE', '603
996.XSHG', '002281.XSHE', '688005.XSHG', '300590.XSHE', '002519.XSHE', '688288.XSHG', '300115.XSHE', '601869.XSHG', '300479.X
SHE', '300083.XSHE', '300079.XSHE', '688665.XSHG', '688608.XSHG', '300303.XSHE', '002402.XSHE', '002456.XSHE', '002866.XSHE',
'300566.XSHE', '002138.XSHE', '300120.XSHE', '300351.XSHE', '000413.XSHE', '300155.XSHE', '300940.XSHE', '603986.XSHG', '002
214.XSHE', '002796.XSHE', '600485.XSHG', '300270.XSHE', '688609.XSHG', '002475.XSHE', '300602.XSHE', '300516.XSHE', '300353.X
SHE', '605058.XSHG', '300514.XSHE', '002925.XSHE', '603773.XSHG', '002426.XSHE', '002829.XSHE', '688696.XSHG', '600183.XSHG',
'000801.XSHE', '002296.XSHE', '002376.XSHE', '300709.XSHE', '002782.XSHE', '600330.XSHG', '300162.XSHE', '002351.XSHE', '688
311.XSHG', '002383.XSHE', '000063.XSHE', '600151.XSHG', '000977.XSHE', '002017.XSHE', '000021.XSHE', '002937.XSHE', '002415.X
SHE', '000725.XSHE', '688080.XSHG', '000100.XSHE', '688019.XSHG', '002231.XSHE', '688002.XSHG', '002055.XSHE', '300308.XSHE',
'300691.XSHE', '002835.XSHE', '600288.XSHG', '002388.XSHE', '002815.XSHE', '603595.XSHG', '300102.XSHE', '600562.XSHG', '300
698.XSHE', '300397.XSHE', '300656.XSHE', '300502.XSHE', '300627.XSHE', '300301.XSHE', '002960.XSHE', '003015.XSHE', '000586.X
SHE', '300555.XSHE', '002413.XSHE', '688025.XSHG', '002179.XSHE', '300916.XSHE', '603115.XSHG', '688008.XSHG', '300546.XSHE',
'002972.XSHE', '002137.XSHE', '002025.XSHE', '600898.XSHG', '300782.XSHE', '002861.XSHE', '002387.XSHE', '002952.XSHE', '300
903.XSHE', '688396.XSHG', '600775.XSHG', '300065.XSHE', '300657.XSHE', '603328.XSHG', '603528.XSHG', '002192.XSHE', '002079.X
SHE', '002045.XSHE', '300708.XSHE', '605218.XSHG', '300956.XSHE', '688260.XSHG', '600776.XSHG', '300531.XSHE', '600345.XSHG',
'002587.XSHE', '300114.XSHE', '600100.XSHG', '300884.XSHE', '300139.XSHE', '603005.XSHG', '600260.XSHG', '603678.XSHG', '300
629.XSHE', '300227.XSHE', '002583.XSHE', '300919.XSHE', '600118.XSHG', '603106.XSHG', '300282.XSHE', '002217.XSHE', '300256.X
SHE', '002729.XSHE', '300647.XSHE', '603236.XSHG', ...
2016-01-03
INFO
['600028.XSHG', '000554.XSHE', '000159.XSHE', '600397.XSHG', '002221.XSHE', '600583.XSHG', '601918.XSHG', '603113.XSHG', '600
725.XSHG', '002259.XSHE', '601225.XSHG', '000968.XSHE', '002629.XSHE', '601011.XSHG', '603353.XSHG', '600508.XSHG', '600777.X
SHG', '000571.XSHE', '600123.XSHG', '603619.XSHG', '600871.XSHG', '601088.XSHG', '600740.XSHG', '002128.XSHE', '300839.XSHE',
'002554.XSHE', '000937.XSHE', '600968.XSHG', '600688.XSHG', '000723.XSHE', '002278.XSHE', '300309.XSHE', '000983.XSHE', '000
096.XSHE', '002490.XSHE', '601699.XSHG', '601898.XSHG', '002828.XSHE', '600387.XSHG', '000852.XSHE', '300084.XSHE', '600403.X
SHG', '300164.XSHE', '000059.XSHE', '600758.XSHG', '600121.XSHG', '600256.XSHG', '601808.XSHG', '600188.XSHG', '601001.XSHG',
'002353.XSHE', '688377.XSHG', '603727.XSHG', '600971.XSHG', '002207.XSHE', '000698.XSHE', '601101.XSHG', '000552.XSHE', '000
780.XSHE', '601857.XSHG', '601015.XSHG', '300471.XSHE', '600989.XSHG', '601666.XSHG', '603800.XSHG', '600759.XSHG', '300157.X
SHE', '300540.XSHE', '603798.XSHG', '600792.XSHG', '601798.XSHG', '000637.XSHE', '600997.XSHG', '603036.XSHG', '300191.XSHE',
'600348.XSHG', '600395.XSHG']
2016-01-03
INFO
['600030.XSHG', '002153.XSHE', '002065.XSHE', '002594.XSHE', '600332.XSHG', '601016.XSHG', '600739.XSHG', '600010.XSHG', '600
588.XSHG', '601216.XSHG', '601600.XSHG', '601818.XSHG', '601333.XSHG', '000983.XSHE', '600867.XSHG', '600028.XSHG', '600549.X
SHG', '601099.XSHG', '000793.XSHE', '002739.XSHE', '600048.XSHG', '002252.XSHE', '600718.XSHG', '601958.XSHG', '002456.XSHE',
'600958.XSHG', '600827.XSHG', '600196.XSHG', '600837.XSHG', '000027.XSHE', '600021.XSHG', '600104.XSHG', '600166.XSHG', '000
568.XSHE', '600309.XSHG', '601377.XSHG', '000002.XSHE', '000826.XSHE', '000402.XSHE', '000415.XSHE', '000333.XSHE', '000917.X
SHE', '002736.XSHE', '000413.XSHE', '002202.XSHE', '002399.XSHE', '300146.XSHE', '600023.XSHG', '600489.XSHG', '601991.XSHG',
'601166.XSHG', '000712.XSHE', '300002.XSHE', '601788.XSHG', '600038.XSHG', '600783.XSHG', '601919.XSHG', '002410.XSHE', '000
825.XSHE', '600031.XSHG', '000400.XSHE', '000001.XSHE', '601668.XSHG', '601688.XSHG', '601866.XSHG', '600276.XSHG', '600518.X
SHG', '601989.XSHG', '300104.XSHE', '002081.XSHE', '601555.XSHG', '600703.XSHG', '002500.XSHE', '600066.XSHG', '000063.XSHE',
'002450.XSHE', '600068.XSHG', '601006.XSHG', '600406.XSHG', '000629.XSHE', '600369.XSHG', '601988.XSHG', '300017.XSHE', '600
085.XSHG', '601288.XSHG', '601106.XSHG', '601179.XSHG', '000883.XSHE', '600893.XSHG', '601238.XSHG', '601158.XSHG', '600011.X
SHG', '600674.XSHG', '600016.XSHG', '600570.XSHG', '600317.XSHG', '300070.XSHE', '300144.XSHE', '000768.XSHE', '300015.XSHE',
'000060.XSHE', '601872.XSHG', '000686.XSHE', '603993.XSHG', '600485.XSHG', '600999.XSHG', '600153.XSHG', '601618.XSHG', '600
663.XSHG', '600372.XSHG', '601117.XSHG', '000876.XSHE', '002007.XSHE', '002422.XSHE', '300027.XSHE', '600373.XSHG', '000581.X
SHE', '000338.XSHE', '600583.XSHG', '601328.XSHG', '600717.XSHG', '603288.XSHG', '600642.XSHG', '000503.XSHE', '601186.XSHG',
'600115.XSHG', '000725.XSHE', '000538.XSHE', '600050.XSHG', '600900.XSHG', '600177.XSHG', '600150.XSHG', '600383.XSHG', '000
999.XSHE', '601898.XSHG', '600863.XSHG', '300124.XSHE', '600633.XSHG', '002465.XSHE', '300003.XSHE', '600350.XSHG', '601800.X
SHG', '002142.XSHE', '000009.XSHE', '601111.XSHG', '600170.XSHG', '601899.XSHG', '600895.XSHG', '600795.XSHG', '600221.XSHG',
'600839.XSHG', '000630.XSHE', '000792.XSHE', '000831.XSHE', '000963.XSHE', '600208.XSHG', '601992.XSHG', '600705.XSHG', '601
018.XSHG', '601398.XSHG', '002292.XSHE', '000046.XSHE', '603885.XSHG', '600600.XSHG', '000166.XSHE', '601009.XSHG', '001979.X
SHE', '600188.XSHG', '600690.XSHG', '000157.XSHE', '000776.XSHE', '601766.XSHG', '002304.XSHE', '000898.XSHE', '300058.XSHE',
'600018.XSHG', '600015.XSHG', '601118.XSHG', '601225.XSHG', '600029.XSHG', '600352.XSHG', '000039.XSHE', '601231.XSHG', '002
008.XSHE', '300315.XSHE', '600009.XSHG', '000100.XSHE', '000750.XSHE', '600019.XSHG', '600100.XSHG', '600252.XSHG', '600887.X
SHG', '601098.XSHG', '300133.XSHE', '000858.XSHE', '601928.XSHG', '000539.XSHE', '002470.XSHE', '600111.XSHG', '601969.XSHG', ...

Get stock contract data

Historical data of a certain contract

history_bars(order_book_id, bar_count, frequency, fields=None, skip_suspended=True, include_now=False)

Get the historical market data of the specified contract, and support daily and minute historical data. Cannot be called in init.

parameter:
Insert picture description here

Obtained by bar_dict

The bar_dict object can also obtain market data: only the current running date can be obtained, and the previous date cannot be obtained.

Bar object
Insert picture description here
example:

logger.info(bar_dict[context.s1].close)

Code display

def handle_bar(context, bar_dict):
    # 开始编写你的主要的算法逻辑

    # bar_dict[order_book_id] 可以拿到某个证券的bar信息
    # context.portfolio 可以拿到现在的投资组合信息

    # 使用order_shares(id_or_ins, amount)方法进行落单

    # TODO: 开始编写你的算法吧!
    # 获取从当前提取运行开始之前5天的行情数据
    history_1 = history_bars(context.s1, 5, "1d", ["close", "open"])

    # 调试输出
    logger.info(history_1)
 
输出结果:
 2016-01-04
INFO
[(11.98, 12.43) (12.09, 11.99) (12.1 , 12.09) (11.99, 12.1 )
(11.33, 12. )]
2016-01-05
INFO
[(12.09, 11.99) (12.1 , 12.09) (11.99, 12.1 ) (11.33, 12. )
(11.4 , 11.27)]
2016-01-06
INFO
[(12.1 , 12.09) (11.99, 12.1 ) (11.33, 12. ) (11.4 , 11.27)
(11.53, 11.42)]
2016-01-07
INFO
[(11.99, 12.1 ) (11.33, 12. ) (11.4 , 11.27) (11.53, 11.42)
(10.94, 11.41)]
2016-01-08
INFO
[(11.33, 12. ) (11.4 , 11.27) (11.53, 11.42) (10.94, 11.41)
(11.12, 11.21)]
2016-01-11
INFO
[(11.4 , 11.27) (11.53, 11.42) (10.94, 11.41) (11.12, 11.21)
(10.76, 11. )]
2016-01-12
INFO
[(11.53, 11.42) (10.94, 11.41) (11.12, 11.21) (10.76, 11. )
(10.81, 10.83)]
2016-01-13
INFO
[(10.94, 11.41) (11.12, 11.21) (10.76, 11. ) (10.81, 10.83)
(10.71, 10.89)]
2016-01-14
INFO
[(11.12, 11.21) (10.76, 11. ) (10.81, 10.83) (10.71, 10.89)
(10.77, 10.59)]
2016-01-15
INFO
[(10.76, 11. ) (10.81, 10.83) (10.71, 10.89) (10.77, 10.59)
(10.46, 10.66)]
2016-01-18
INFO
[(10.81, 10.83) (10.71, 10.89) (10.77, 10.59) (10.46, 10.66)
(10.41, 10.34)]
2016-01-19
INFO
[(10.71, 10.89) (10.77, 10.59) (10.46, 10.66) (10.41, 10.34)
(10.71, 10.45)]
2016-01-20
INFO
[(10.77, 10.59) (10.46, 10.66) (10.41, 10.34) (10.71, 10.45)
(10.54, 10.7 )]
2016-01-21
INFO
[(10.46, 10.66) (10.41, 10.34) (10.71, 10.45) (10.54, 10.7 )
(10.32, 10.48)]
2016-01-22
INFO
[(10.41, 10.34) (10.71, 10.45) (10.54, 10.7 ) (10.32, 10.48)
(10.4 , 10.4 )]
2016-01-25
INFO
[(10.71, 10.45) (10.54, 10.7 ) (10.32, 10.48) (10.4 , 10.4 )
(10.37, 10.4 )]
2016-01-26
INFO
[(10.54, 10.7 ) (10.32, 10.48) (10.4 , 10.4 ) (10.37, 10.4 )
( 9.87, 10.32)]
2016-01-27
INFO
[(10.32, 10.48) (10.4 , 10.4 ) (10.37, 10.4 ) ( 9.87, 10.32)
( 9.88, 9.93)]
2016-01-28
INFO
[(10.4 , 10.4 ) (10.37, 10.4 ) ( 9.87, 10.32) ( 9.88, 9.93)
( 9.69, 9.82)]
2016-01-29
INFO
[(10.37, 10.4 ) ( 9.87, 10.32) ( 9.88, 9.93) ( 9.69, 9.82)
(10. , 9.74)]
2016-02-01
...

Get financial data

Query financial data

get_fundamentals-query financial data

get_fundamentals(query, entry_date, interval=None, report_quarter=False, expect_df=False)

Obtain historical financial data tables. Currently supports more than 400 indicators in the Chinese market. Please refer to the financial data documents for details. Currently only supports the Chinese market. Please note that when querying fundamental data on RiceQuant, we use the announcement date of all annual reports. date) shall prevail, because only after the financial report is released will it become publicly available data on the market.

parameter:

parameter Types of Description
query SQLAlchemyQueryObject SQLAlchemy's Query object. Among them, you can fill in the index to be queried in the'query', and fill in the data filtering conditions in the'filter'. For details, please refer to sqlalchemy's query documentation to learn to use more convenient query statements. From a data scientist's point of view, the use of sqlalchemy is simpler and more powerful than sql
entry_date str, datetime.date, datetime.datetime, pandasTimestamp Base start date for querying financial data
interval str The interval for querying financial data. For example, fill in '5y', it means to go back 5 years from entry_date (including entry_date), and the time of returning data is at intervals of years. 'd'-day,'w'-week,'m'-month,'q'-quarter,'y'-year
report_quarter bool Whether to display the reporting period, the default is not to display. 'Q1'-quarterly report,'Q2'-semi-annual report,'Q3'-quarterly report,'Q4'-annual report
expect_df boolean The original Panel data structure is returned by default. If it is set to true, it returns a pandas dataframe

Return
pandas DataPanel-financial data query results.

example

[In]
dp = get_fundamentals(query(fundamentals.eod_derivative_indicator.pe_ratio).filter(fundamentals.stockcode == '000001.XSHE'), '2016-08-01','4q' ,report_quarter = True)
[In]
dp.minor_xs('000001.XSHE')
[Out]
		report_quarter	pe_ratio
2016-08-01	2016-Q1 	7.0768
2016-04-29	2016-Q1		6.7755
2016-01-29	2015-Q3		6.5492
2015-10-29	2015-Q3		7.3809

Filter criteria

  • query().filter: filter size
  • query().order_by: sort
  • query.limit(): limit the number
  • fundamentals.stockcode.in_(): filter in the specified stock pool

Case:

q = query(
            fundamentals.eod_derivative_indicator.pe_ratio,  # 获取市盈率
            fundamentals.eod_derivative_indicator.pcf_ratio  # 获取市现率 
        ).filter(
            fundamentals.eod_derivative_indicator.pe_ratio > 20,  # 过滤市盈率大于20
            fundamentals.eod_derivative_indicator.pcf_ratio < 50  # 过滤市现率小于50
        ).order_by(
            fundamentals.eod_derivative_indicator.pe_ratio # 用盈率排序, 从小到大
        ).limit(10)  # 取10个

Code display

def handle_bar(context, bar_dict):
    # 开始编写你的主要的算法逻辑

    # bar_dict[order_book_id] 可以拿到某个证券的bar信息
    # context.portfolio 可以拿到现在的投资组合信息

    # 使用order_shares(id_or_ins, amount)方法进行落单

    # TODO: 开始编写你的算法吧!
    # 创建一个查询语句 (pb_ratio: 市净率)
    q = query(
            fundamentals.eod_derivative_indicator.pb_ratio
        )

    # 回测不需要日期, 默认当天的数据
    fund = get_fundamentals(q)

    # 转置
    fund = fund.T

    # 调试输出
    logger.info(fund)
    
输出结果:
 2016-01-04
INFO
pb_ratio
000010.XSHE 3.8286
000014.XSHE 6.4342
000006.XSHE 3.537
000008.XSHE 9.7601
000012.XSHE 3.6253
000011.XSHE 4.121
000007.XSHE 14.8823
000009.XSHE 6.3938
000001.XSHE 1.0623
000002.XSHE 2.695
000004.XSHE 47.2814
000005.XSHE 9.2519
000016.XSHE 5.9121
000017.XSHE 651.399
000018.XSHE 17.1477
000019.XSHE 5.4866
000021.XSHE 3.4096
000022.XSHE 2.8029
000023.XSHE 11.0294
000020.XSHE 27.2062
000025.XSHE 28.7225
000026.XSHE 2.7981
000027.XSHE 1.7913
000028.XSHE 4.3987
000029.XSHE 5.6056
000030.XSHE 2.816
000031.XSHE 4.2624
000032.XSHE 6.5288
000033.XSHE 355.578
000034.XSHE 53.5046
... ...
300426.XSHE 15.1151
002736.XSHE 3.6212
300488.XSHE 9.2783
300434.XSHE 11.4555
603398.XSHG 16.4336
603808.XSHG 5.3673
300439.XSHE 10.5654
603223.XSHG 7.9353
300450.XSHE 18.5618
300446.XSHE 16.6062
300493.XSHE 10.9242
300427.XSHE 11.9498
300487.XSHE 8.0302
300459.XSHE 7.8616
603968.XSHG 5.5646
300457.XSHE 15.0464
300451.XSHE 20.5081
300394.XSHE 12.6802
603669.XSHG 8.1029
300481.XSHE 10.3629
300458.XSHE 12.4225
300413.XSHE 10.0609
300408.XSHE 7.5259
603996.XSHG 4.3534
000166.XSHE 3.1675
300498.XSHE 7.4478
601155.XSHG 2.8596
001979.XSHE 3.3113
001872.XSHE 2.8029
001914.XSHE 2.0273
[2811 rows x 1 columns]
2016-01-05
INFO
pb_ratio
000010.XSHE 3.4495
000014.XSHE 5.791
000006.XSHE 3.1898
000008.XSHE 8.7908
000012.XSHE 3.2641
000011.XSHE 3.7094
000007.XSHE 14.8823
000009.XSHE 5.753
000001.XSHE 1.0038
000002.XSHE 2.695
000004.XSHE 42.5533
000005.XSHE 8.3304
000016.XSHE 5.3217
000017.XSHE 586.259
000018.XSHE 15.4643
000019.XSHE 4.9428
000021.XSHE 3.0675
000022.XSHE 2.5256
000023.XSHE 11.0294
000020.XSHE 24.5874
000025.XSHE 25.8496
000026.XSHE 2.518
000027.XSHE 1.6142
000028.XSHE 4.3987
000029.XSHE 5.0459
000030.XSHE 2.5426
000031.XSHE 3.8468
000032.XSHE 5.8759
000033.XSHE 355.578
000034.XSHE 53.5046
...

Get data regularly

Run every day

scheduler.run_daily

scheduler.run_daily(function)

parameter:

parameter Types of Annotation
function function Make the incoming function run daily. Note that the function function must contain (and can only contain) two input parameters: context and bar_dict

Run every week

scheduler.run_weekly

scheduler.run_weekly(function, weekday=x, tradingday=t)

note:

  • Negative number in tradingday means reciprocal
  • tradingday means trading day. If there are only four trading days in a week, tradingday=4 and tradingday=-1 for this week indicate the same day
  • weekday and tradingday cannot be used at the same time

Run monthly

scheduler.run_monthly

scheduler.run_monthly(function, tradingday=t)

note:

  • Negative number in tradingday means reciprocal
  • tradingday means trading day. If there are only four trading days in a week, tradingday=4 and tradingday=-1 for this week indicate the same day

Run sequence

If we set a monthly run: scheduler.run_monthly(get_data, tradingday=1). Assuming it is March 2021, March 1 is the first trading day:

  • 3 月 1 号: before_trading -> get_data -> handle_bar
  • Other dates in March: before_trading -> handle_bar

Guess you like

Origin blog.csdn.net/weixin_46274168/article/details/114818513