Ejemplo n.º 1
0
    def query_money_supply_data_year(start_date=None, end_date=None):
        """
        货币供应量(年底余额)
        方法说明:通过API接口获取货币供应量(年底余额),可以通过参数设置获取对应起止日期的数据。
        返回类型:pandas的DataFrame类型。
        参数含义:
        start_date:开始日期,格式XXXX,发布日期在这个范围内,可以为空;
        end_date:结束日期,格式XXXX,发布日期在这个范围内,可以为空。
        """
        lg = bs.login()
        if lg.error_code != '0':
            logger.error('login respond  error_msg:' + lg.error_msg)

        rs = bs.query_money_supply_data_year(start_date=start_date,
                                             end_date=end_date)
        if rs.error_code != '0':
            logger.error('query_money_supply_data_year 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
Ejemplo n.º 2
0
    def query_money_supply_data_year(self, start_date = None, end_date = None):
        '''
        start_date:开始日期,格式XXXX,发布日期在这个范围内,可以为空;
        end_date:结束日期,格式XXXX,发布日期在这个范围内,可以为空。
        '''
        rs = bs.query_money_supply_data_year(start_date=start_date, end_date=end_date)
        self.log('query_money_supply_data_year 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
def save_money_supply_data_year(start_date, end_date):
    '''
    获取货币供应量(年底余额)
    :param start_date:
    :param end_date:
    :return:
    '''
    bs.login()
    rs = bs.query_money_supply_data_year(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_year', engine, index=True)
    bs.logout()
 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_year(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
Ejemplo n.º 5
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_year(start_date="2010", end_date="2015")
print('query_money_supply_data_year respond error_code:' + rs.error_code)
print('query_money_supply_data_year 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("D:/money_supply_data_year.csv", encoding="gbk", index=False)
print(result)

# 登出系统
bs.logout()
Ejemplo n.º 6
0
 def normal_money_supply_data_year(self, start_date, end_date):
     self.getStockInstance()
     rs = bs.query_money_supply_data_year(start_date[0:4], end_date[0:4])
     self._test_rs(rs)
     return rs