Пример #1
0
    def _build_index(self):
        def with_index(df, type, column, new_name="symbol"):
            if not "country" in df:
                df["country"] = "unknown"
            else:
                df["country"] = df["country"].replace({
                    None: "unknown",
                    "": "unknown"
                }).fillna('unknown')

            df.index = pd.MultiIndex.from_tuples([
                (s, type, c)
                for s, c in zip(df[column].to_list(), df["country"].to_list())
            ]).rename([
                new_name if new_name is not None else column, "type", "country"
            ])
            df = df.drop([column, "country"], axis=1)
            df = df.drop(df.index[df.index.duplicated('first')], axis=0)
            return df.loc[df.index.dropna()]

        symbols_df = pd.concat(
            [
                with_index(ip.get_bonds(), "BOND",
                           "name"),  # country	"name"	full_name
                with_index(
                    ip.get_certificates(), "CERT", "symbol"
                ),  # country', 'name', 'full_name', '"symbol"', 'issuer', 'isin', 'asset_class', 'underlying'
                with_index(ip.get_cryptos(), "CRYPTO",
                           "symbol"),  # 'name', '"symbol"', 'currency'
                with_index(
                    ip.get_commodities(), "COMM", "name"
                ),  # 'title', 'country', '"name"', 'full_name', 'currency', 'group'
                with_index(
                    ip.get_etfs(), "ETF", "symbol"
                ),  # 'country', 'name', 'full_name', '"symbol"', 'isin', 'asset_class', 'currency', 'stock_exchange', 'def_stock_exchange'
                # with_index(ip.get_funds(), "FUND", "isin"),             # 'country', 'name', 'symbol', 'issuer', '"isin"', 'asset_class', 'currency', 'underlying'
                with_index(
                    ip.get_indices(), "INDEX", "symbol"
                ),  # 'country', 'name', 'full_name', '"symbol"', 'currency', 'class', 'market'
                with_index(
                    ip.get_stocks(), "STOCK", "symbol"
                ),  # ['country', 'name', 'full_name', 'isin', 'currency', '"symbol"'
                with_index(
                    pd.DataFrame(
                        [f'{c}/USD' for c in ip.get_available_currencies()],
                        columns=['symbol']), "FX", "symbol")
            ],
            axis=0)

        # update the index table
        upsert(self.engine,
               symbols_df,
               DataProvider.symbols_table_name,
               if_row_exists='ignore')
Пример #2
0
def get_cryptos():
    # function to get dictionary of crypto available at Investing 
    try:
        tickers_df = investpy.get_cryptos()
    except:
        tickers_df = pd.DataFrame(data=dict(name=['No results'], symbol=['No results']) )
    # extract names and symbols
    tickers_df.loc[:, 'name'] = tickers_df.loc[:, 'name'].apply(lambda x: x.strip('u200b') )
    
    labels= [', '.join(i) for i in tickers_df.loc[:, ['name','symbol']].values]
    values = tickers_df.loc[:, ['symbol']].values.T[0]
    tickers_dict = [{'label':i, 'value':j.split(',')[0]} for i,j in zip(labels, labels)]
    return tickers_dict
Пример #3
0
def test_investpy_cryptos():
    """
    This function checks that crypto currencies data retrieval functions listed in investpy work properly.
    """
    
    investpy.get_cryptos()
    investpy.get_cryptos_list()

    params = [
        {
            'columns': None,
            'as_json': False
        },
        {
            'columns': ['name', 'symbol', 'currency'],
            'as_json': False
        },
        {
            'columns': None,
            'as_json': True
        },    
    ]

    for param in params:
        investpy.get_cryptos_dict(columns=param['columns'],
                                  as_json=param['as_json'])

    params = [
        {
            'as_json': True,
            'order': 'ascending',
        },
        {
            'as_json': False,
            'order': 'ascending',
        },
        {
            'as_json': True,
            'order': 'descending',
        },
        {
            'as_json': False,
            'order': 'descending',
        },
    ]

    for param in params:
        investpy.get_crypto_recent_data(crypto='bitcoin',
                                        as_json=param['as_json'],
                                        order=param['order'],
                                        interval='Daily')

        investpy.get_crypto_historical_data(crypto='bitcoin',
                                            from_date='01/01/1990',
                                            to_date='01/01/2019',
                                            as_json=param['as_json'],
                                            order=param['order'],
                                            interval='Daily')

    params = [
        {
            'crypto': 'bitcoin',
            'as_json': False
        },
        {
            'crypto': 'bitcoin',
            'as_json': True
        }
    ]

    for param in params:
        investpy.get_crypto_information(crypto=param['crypto'], as_json=param['as_json'])
    
    params = [
        {
            'as_json': False,
            'n_results': 10
        },
        {
            'as_json': True,
            'n_results': 10
        },
        {
            'as_json': False,
            'n_results': 110
        },
        {
            'as_json': True,
            'n_results': 110
        },
        {
            'as_json': False,
            'n_results': None
        },
        {
            'as_json': True,
            'n_results': None
        },
    ]

    for param in params:
        investpy.get_cryptos_overview(as_json=param['as_json'], n_results=param['n_results'])

    investpy.search_cryptos(by='name', value='bitcoin')
Пример #4
0
                                                       interval='Daily')
investpy_bitcoin.to_pickle('./Market_Watch_Data/investpy_bitcoin.pkl')

investpy_Ethereum = investpy.get_crypto_historical_data(crypto='Ethereum',
                                                        from_date="30/01/1900",
                                                        to_date=DD_END_DATE,
                                                        interval='Daily')
investpy_Ethereum.to_pickle('./Market_Watch_Data/investpy_Ethereum.pkl')

investpy_Ripple = investpy.get_crypto_historical_data(crypto='XRP',
                                                      from_date="30/01/1900",
                                                      to_date=DD_END_DATE,
                                                      interval='Daily')
investpy_Ripple.to_pickle('./Market_Watch_Data/investpy_Ripple.pkl')

df_cryptos = investpy.get_cryptos()

########################################################################################################################
# investpy 패키지를 사용하여 삼성전자 자료 받기
investpy_005930 = investpy.get_stock_historical_data(stock="005930",
                                                     country="south korea",
                                                     from_date="30/01/1900",
                                                     to_date=DD_END_DATE)
investpy_005930.to_pickle('./Market_Watch_Data/investpy_005930.pkl')

########################################################################################################################
# investpy 패키지를 사용하여 ETF 자료 받기 (069500)
investpy_069500 = investpy.get_etf_historical_data(
    etf="Samsung KODEX KOSPI 200 Securities",
    country="south korea",
    from_date="30/01/1900",