Пример #1
0
def get_fundamentals_n(table,
                       symbols,
                       end_date,
                       fields=None,
                       filter=None,
                       order_by=None,
                       count=1,
                       df=False):
    """
    查询基本面财务数据,每个股票在end_date的前n条
    """
    fields_str, fields_list = standard_fields(fields, letter_upper=True)
    data = fundamentalapi.get_fundamentals_n(table=table,
                                             symbols=symbols,
                                             end_date=end_date,
                                             fields=fields_str,
                                             filter=filter,
                                             order_by=order_by,
                                             count=count)

    if df:
        data = pd.DataFrame(data)
        if fields_list:
            fields_list = ['symbol', 'pub_date', 'end_date'] + fields_list
            columns = [field for field in fields_list if field in data.columns]
            data = data[columns]

    return data
Пример #2
0
def get_fundamentals(table,
                     symbols,
                     start_date,
                     end_date,
                     fields=None,
                     filter=None,
                     order_by=None,
                     limit=1000,
                     df=False):
    """
    查询基本面财务数据
    """
    fields_str, fields_list = standard_fields(fields, letter_upper=True)
    start_date = utils.to_datestr(start_date)
    end_date = utils.to_datestr(end_date)
    data = fundamentalapi.get_fundamentals(table=table,
                                           symbols=symbols,
                                           start_date=start_date,
                                           end_date=end_date,
                                           fields=fields_str,
                                           filter=filter,
                                           order_by=order_by,
                                           limit=limit)

    if df:
        data = pd.DataFrame(data)
        if fields_list:
            fields_list = ['symbol', 'pub_date', 'end_date'] + fields_list
            columns = [field for field in fields_list if field in data.columns]
            data = data[columns]

    return data
Пример #3
0
    def get_history_bars(self,
                         symbols,
                         frequency,
                         start_time,
                         end_time,
                         fields=None,
                         skip_suspended=True,
                         fill_missing=None,
                         adjust=ADJUST_NONE,
                         adjust_end_time='',
                         df=False):
        self._init_addr()

        req = GetHistoryBarsReq(symbols=symbols,
                                frequency=frequency,
                                start_time=start_time,
                                end_time=end_time,
                                fields=fields,
                                skip_suspended=skip_suspended,
                                fill_missing=fill_missing,
                                adjust=adjust,
                                adjust_end_time=adjust_end_time)
        resp = self.stub.GetHistoryBars(
            req,
            metadata=[
                (str('authorization'), context.token),
                (str('grpc-internal-encoding-request'), str('gzip')),
                (str('sdk-lang'), context.sdk_lang),
                (str('sdk-version'), context.sdk_version),
                (str('sdk-arch'), context.sdk_arch),
                (str('sdk-os'), context.sdk_os),
            ])

        datas = [
            protobuf_to_dict(bar,
                             is_utc_time=True,
                             including_default_value_fields=True)
            for bar in resp.data
        ]
        fields_str, fields_list = standard_fields(fields, letter_upper=False)
        if not fields_list:
            datas = datas if not df else pd.DataFrame(datas)
            return datas

        else:
            result = []
            for data in datas:
                info = {}
                for field in fields_list:
                    info[field] = data.get(field)
                result.append(info)

            result = result if not df else pd.DataFrame(result)
            return result
Пример #4
0
def get_constituents(index, fields=None, df=False):
    """
    查询指数最新成分股
    返回的list每项是个字典,包含的key值有:
    symbol 股票symbol
    weight 权重
    """
    fields_str, fields_list = standard_fields(fields, letter_upper=False)
    data = fundamentalapi.get_constituents(index, fields, df)
    if df:
        data = pd.DataFrame(data)
        if fields_list:
            columns = [field for field in fields_list if field in data.columns]
            data = data[columns]

    return data
Пример #5
0
def get_history_instruments(symbols,
                            fields=None,
                            start_date=None,
                            end_date=None,
                            df=False):
    """
    返回指定的symbols的标的日指标数据
    """
    fields_str, fields_list = standard_fields(fields, letter_upper=False)

    data = fundamentalapi.get_history_instruments(symbols, fields_str,
                                                  start_date, end_date)

    if df:
        data = pd.DataFrame(data)
        if fields_list:
            columns = [field for field in fields_list if field in data.columns]
            data = data[columns]

    return data
Пример #6
0
def get_instrumentinfos(symbols=None,
                        exchanges=None,
                        sec_types=None,
                        names=None,
                        fields=None,
                        df=False):
    """
    查询交易标的基本信息
    如果没有数据的话,返回空列表. 有的话, 返回list[dict]这样的列表. 其中 listed_date, delisted_date 为 datetime 类型
    @:param fields: 可以是 'symbol, sec_type' 这样的字符串, 也可以是 ['symbol', 'sec_type'] 这样的字符list
    """
    fields_str, fields_list = standard_fields(fields, letter_upper=False)
    data = fundamentalapi.get_instrumentinfos(symbols, exchanges, sec_types,
                                              names, fields)

    if df:
        data = pd.DataFrame(data)
        if fields_list:
            columns = [field for field in fields_list if field in data.columns]
            data = data[columns]

    return data
Пример #7
0
def get_instruments(symbols=None,
                    exchanges=None,
                    sec_types=None,
                    names=None,
                    skip_suspended=True,
                    skip_st=True,
                    fields=None,
                    df=False):
    """
    查询最新交易标的信息,有基本数据及最新日频数据
    """
    fields_str, fields_list = standard_fields(fields, letter_upper=False)
    data = fundamentalapi.get_instruments(symbols, exchanges, sec_types, names,
                                          skip_suspended, skip_st, fields_str)

    if df:
        data = pd.DataFrame(data)
        if fields_list:
            columns = [field for field in fields_list if field in data.columns]
            data = data[columns]

    return data