Python determines whether the trading day is on the market

Source: Internet
Author: User

Using the Tushare library, he has a function that reads whether all dates are open and the return value is Dataframe type

import tushare as tsts.trade_cal()

IsOpen 1 is the opening.

The full source code is as follows:

import tushare as tsimport datetimeimport timedef JiaoYiRiQi():    while True:        DatetimeNOW = datetime.datetime.now().strftime(‘%Y-%m-%d‘)        OpenList = ts.trade_cal()        OpentimeList = OpenList.isOpen[OpenList.calendarDate == DatetimeNOW]        if OpentimeList.values[0] == 1:            XianZaiShiJian = datetime.datetime.now().strftime(‘%H%M%S‘)            if 93000 < int(XianZaiShiJian) < 150000:                break            else:                pass        else:            pass        time.sleep(60)

If you jump out of the loop within the trading hours, wait 60 seconds to execute again.

Python determines whether the stock day

Tags: python A shares

Original: http://blog.51cto.com/12541359/2122463,

Function name pending modification, function to be verified

Python determines whether the trading day is on the market

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.