Пример #1
0
def Zijinmian():
    today = datetime.datetime.today()
    year = today.year
    month = today.month
    dic = {'m2': []}
    # 登陆系统
    lg = bs.login()
    # 获取货币供应量
    if month < 10:
        enddate = str(year) + '-' + '0' + str(month)
    else:
        enddate = str(year) + '-' + str(month)
    rs5 = bs.query_money_supply_data_month(start_date="2020-01",
                                           end_date=enddate)
    # 打印结果集
    data_list = []
    while (rs5.error_code == '0') & rs5.next():
        # 获取一条记录,将记录合并在一起
        data_list.append(rs5.get_row_data())
    result = pd.DataFrame(data_list, columns=rs5.fields)
    print(np.array(result['m2Month']))
    # 登出系统
    bs.logout()
    dic['m2'] = np.array(result['m2Month']).tolist()
    dic['m2'] = list(map(eval, dic['m2']))
    return json.dumps(dic, ensure_ascii=False)
Пример #2
0
    def query_money_supply_data_month(start_date=None, end_date=None):
        """
        货币供应量
        方法说明:通过API接口获取货币供应量,可以通过参数设置获取对应起止日期的数据。
        返回类型:pandas的DataFrame类型。
        参数含义:
        start_date:开始日期,格式XXXX-XX,发布日期在这个范围内,可以为空;
        end_date:结束日期,格式XXXX-XX,发布日期在这个范围内,可以为空。
        """
        lg = bs.login()
        if lg.error_code != '0':
            logger.error('login respond  error_msg:' + lg.error_msg)

        rs = bs.query_money_supply_data_month(start_date=start_date,
                                              end_date=end_date)
        if rs.error_code != '0':
            logger.error('query_money_supply_data_month respond  error_msg:' +
                         rs.error_msg)

        data_list = []
        while (rs.error_code == '0') & rs.next():
            data_list.append(rs.get_row_data())
        result = pd.DataFrame(data_list, columns=rs.fields)

        bs.logout()
        return result
Пример #3
0
    def query_money_supply_data_month(self, start_date = None, end_date = None):
        '''
        start_date:开始日期,格式XXXX-XX,发布日期在这个范围内,可以为空;
        end_date:结束日期,格式XXXX-XX,发布日期在这个范围内,可以为空。
        '''
        rs = bs.query_money_supply_data_month(start_date=start_date, end_date=end_date)
        self.log('query_money_supply_data_month respond  error_msg:', rs)

        # 打印结果集
        data_list = []
        while (rs.error_code == '0') & rs.next():
            # 获取一条记录,将记录合并在一起
            data_list.append(rs.get_row_data())
        result = pd.DataFrame(data_list, columns=rs.fields)
        return result
Пример #4
0
def save_money_supply_data_month(start_date, end_date):
    '''
    获取货币供应量
    :param start_date:
    :param end_date:
    :return:
    '''
    bs.login()
    rs = bs.query_money_supply_data_month(start_date=start_date,
                                          end_date=end_date)
    data_list = []
    while (rs.error_code == '0') & rs.next():
        data_list.append(rs.get_row_data())
    result = pd.DataFrame(data_list, columns=rs.fields)
    engine = create_engine(
        'mysql+pymysql://root:root@localhost:3306/stock_quant?charset=utf8')
    result.to_sql('bs_money_supply_data_month', engine, index=True)
    bs.logout()
Пример #5
0
def download(beginDate: str, endDate: str, fileName):
    #### 登陆系统 ####
    lg = bs.login()
    # 显示登陆返回信息
    print('login respond error_code:' + lg.error_code)
    print('login respond  error_msg:' + lg.error_msg)

    # 查询季频估值指标盈利能力
    list = []
    # yearList = range(2003, 2020)
    # for year in yearList:
    #     rs = bs.query_money_supply_data_month(str(year)+"-01", str(year)+"-12")
    rs = bs.query_money_supply_data_month(beginDate, endDate)
    # print('query_loan_rate_data respond error_code:'+rs.error_code)
    # print('query_loan_rate_data respond  error_msg:'+rs.error_msg)
    while (rs.error_code == '0') & rs.next():
        list.append(rs.get_row_data())

    saveToCsv(list, fileName)
 def get_money_supply_data(self,
                           start_date: str = None,
                           end_date: str = None,
                           save=False):
     """
     货币供应量
     """
     if end_date == None:
         end_date = self.end_date
     elif start_day == None:
         start_day = start_date
     data_saver = []
     rs = bs.query_money_supply_data_month(start_date, end_date)
     while (rs.error_code == "0") and rs.next():
         data_saver.append(rs.get_row_data())
     if save == True:
         result = pd.DataFrame(data_saver, columns=rs.fields)
         result.to_csv("../data_home/%s.csv" % targetStock)
     return data_saver, rs.fields
Пример #7
0
    def query_money_supply_data_month(self):
        # 登陆系统
        lg = bs.login()
        # 显示登陆返回信息
        print('login respond error_code:' + lg.error_code)
        print('login respond  error_msg:' + lg.error_msg)

        today_ISO_yymm = self.end_date[0:7]

        # 获取货币供应量
        rs = bs.query_money_supply_data_month(start_date="2010-01",
                                              end_date=today_ISO_yymm)
        print('query_money_supply_data_month respond error_code:' +
              rs.error_code)
        print('query_money_supply_data_month respond  error_msg:' +
              rs.error_msg)

        # 打印结果集
        data_list = []
        while (rs.error_code == '0') & rs.next():
            # 获取一条记录,将记录合并在一起
            data_list.append(rs.get_row_data())
        result = pd.DataFrame(data_list, columns=rs.fields)
        # 结果集输出到csv文件
        result = result[result.m0Month >= '0']
        result.sort_values(by=['statYear', 'statMonth'],
                           ascending=False,
                           inplace=True)
        result.to_csv(self.path + "money_supply_data_month.csv",
                      encoding="gbk",
                      index=False)
        #print(result)

        # 登出系统
        bs.logout()
        return
Пример #8
0
import baostock as bs
import pandas as pd

# 登陆系统
lg = bs.login()
# 显示登陆返回信息
print('login respond error_code:'+lg.error_code)
print('login respond  error_msg:'+lg.error_msg)

# 获取货币供应量
rs = bs.query_money_supply_data_month(start_date="2010-01", end_date="2021-09")
print('query_money_supply_data_month respond error_code:'+rs.error_code)
print('query_money_supply_data_month respond  error_msg:'+rs.error_msg)

# 打印结果集
data_list = []
while (rs.error_code == '0') & rs.next():
    # 获取一条记录,将记录合并在一起
    data_list.append(rs.get_row_data())
result = pd.DataFrame(data_list, columns=rs.fields)
# 结果集输出到csv文件
result.to_csv("./数据文件/货币流通量/2021-09.csv", encoding="gbk", index=False)
print(result)

# 登出系统
bs.logout()
Пример #9
0
    log = Logger(level='debug')
    log.logger.info('baostock_auto_downloader_' + version + ' start!')

    # logon to Baostock and download
    # 登陆系统
    lg = bs.login()
    # 显示登陆返回信息
    log.logger.info('login respond error_code:' + lg.error_code)
    log.logger.info('login respond  error_msg:' + lg.error_msg)

    today_ISO = datetime.today().date().isoformat()
    today_ISO_yymm = today_ISO[0:7]

    # 获取货币供应量
    rs = bs.query_money_supply_data_month(start_date="2019-01",
                                          end_date=today_ISO_yymm)
    log.logger.info('query_money_supply_data_month respond error_code:' +
                    rs.error_code)
    log.logger.info('query_money_supply_data_month respond  error_msg:' +
                    rs.error_msg)

    # 打印结果集
    data_list = []
    while (rs.error_code == '0') & rs.next():
        # 获取一条记录,将记录合并在一起
        data_list.append(rs.get_row_data())
    result = pd.DataFrame(data_list, columns=rs.fields)
    # 结果集输出到csv文件
    result = result[result.m0Month >= '0']
    result.sort_values(by=['statYear', 'statMonth'],
                       ascending=False,
Пример #10
0
 def normal_money_supply_data_month(self, start_date, end_date):
     self.getStockInstance()
     rs = bs.query_money_supply_data_month(start_date[0:7], end_date[0:7])
     self._test_rs(rs)
     return rs