How to use the investpy.utils.data.Data function in investpy

To help you get started, we’ve selected a few investpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alvarob96 / investpy / investpy / certificates.py View on Github external
if elements_.xpath(".//td")[0].text_content() == 'No results found':
                raise IndexError("ERR#0102: certificate information unavailable or not found.")

            info = []
        
            for nested_ in elements_.xpath(".//td"):
                info.append(nested_.get('data-real-value'))

            certificate_date = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
            
            certificate_close = float(info[1].replace(',', ''))
            certificate_open = float(info[2].replace(',', ''))
            certificate_high = float(info[3].replace(',', ''))
            certificate_low = float(info[4].replace(',', ''))

            result.insert(len(result), Data(certificate_date, certificate_open, certificate_high,
                                            certificate_low, certificate_close, None, None, None))

        if order in ['ascending', 'asc']:
            result = result[::-1]
        elif order in ['descending', 'desc']:
            result = result

        if as_json is True:
            json_ = {
                'name': name,
                'recent':
                    [value.certificate_as_json() for value in result]
            }

            return json.dumps(json_, sort_keys=False)
        elif as_json is False:
github alvarob96 / investpy / investpy / etfs.py View on Github external
info = []

                for nested_ in elements_.xpath(".//td"):
                    info.append(nested_.get('data-real-value'))

                if data_flag is True:
                    etf_date = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
                    
                    etf_close = float(info[1].replace(',', ''))
                    etf_open = float(info[2].replace(',', ''))
                    etf_high = float(info[3].replace(',', ''))
                    etf_low = float(info[4].replace(',', ''))

                    result.insert(len(result),
                                  Data(etf_date, etf_open, etf_high, etf_low, etf_close, None, etf_currency, etf_exchange))

            if data_flag is True:
                if order in ['ascending', 'asc']:
                    result = result[::-1]
                elif order in ['descending', 'desc']:
                    result = result

                if as_json is True:
                    json_ = {'name': name,
                             'historical':
                                 [value.etf_as_json() for value in result]
                             }

                    final.append(json_)
                elif as_json is False:
                    df = pd.DataFrame.from_records([value.etf_to_dict() for value in result])
github alvarob96 / investpy / investpy / bonds.py View on Github external
if data_flag is True:
                    info = []

                    for nested_ in elements_.xpath(".//td"):
                        info.append(nested_.get('data-real-value'))

                    bond_date = datetime.fromtimestamp(int(info[0]))
                    bond_date = date(bond_date.year, bond_date.month, bond_date.day)

                    bond_close = float(info[1].replace(',', ''))
                    bond_open = float(info[2].replace(',', ''))
                    bond_high = float(info[3].replace(',', ''))
                    bond_low = float(info[4].replace(',', ''))

                    result.insert(len(result),
                                  Data(bond_date, bond_open, bond_high, bond_low, bond_close, None, None, None))

            if data_flag is True:
                if order in ['ascending', 'asc']:
                    result = result[::-1]
                elif order in ['descending', 'desc']:
                    result = result

                if as_json is True:
                    json_ = {
                        'name': name,
                        'historical':
                            [value.bond_as_json() for value in result]
                    }

                    final.append(json_)
                elif as_json is False:
github alvarob96 / investpy / investpy / utils / search_obj.py View on Github external
info.append(val)

                date_ = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
                
                close_ = float(info[1].replace(',', ''))
                open_ = float(info[2].replace(',', ''))
                high_ = float(info[3].replace(',', ''))
                low_ = float(info[4].replace(',', ''))

                volume_ = None
                
                if has_volume is True:
                    volume_ = int(info[5])

                result.insert(len(result),
                              Data(date_, open_, high_, low_, close_, volume_, None, None))

            result = result[::-1]

            df = pd.DataFrame.from_records([value.unknown_to_dict() for value in result])
            df.set_index('Date', inplace=True)

            return df
github alvarob96 / investpy / investpy / bonds.py View on Github external
info = []

            for nested_ in elements_.xpath(".//td"):
                info.append(nested_.get('data-real-value'))

            bond_date = datetime.fromtimestamp(int(info[0]))
            bond_date = date(bond_date.year, bond_date.month, bond_date.day)

            bond_close = float(info[1].replace(',', ''))
            bond_open = float(info[2].replace(',', ''))
            bond_high = float(info[3].replace(',', ''))
            bond_low = float(info[4].replace(',', ''))

            result.insert(len(result),
                          Data(bond_date, bond_open, bond_high, bond_low, bond_close, None, None, None))

        if order in ['ascending', 'asc']:
            result = result[::-1]
        elif order in ['descending', 'desc']:
            result = result

        if as_json is True:
            json_ = {
                'name': name,
                'recent':
                    [value.bond_as_json() for value in result]
            }

            return json.dumps(json_, sort_keys=False)
        elif as_json is False:
            df = pd.DataFrame.from_records([value.bond_to_dict() for value in result])
github alvarob96 / investpy / investpy / stocks.py View on Github external
info = []

            for nested_ in elements_.xpath(".//td"):
                info.append(nested_.get('data-real-value'))

            stock_date = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
            
            stock_close = float(info[1].replace(',', ''))
            stock_open = float(info[2].replace(',', ''))
            stock_high = float(info[3].replace(',', ''))
            stock_low = float(info[4].replace(',', ''))

            stock_volume = int(info[5])

            result.insert(len(result),
                          Data(stock_date, stock_open, stock_high, stock_low,
                               stock_close, stock_volume, stock_currency, None))

        if order in ['ascending', 'asc']:
            result = result[::-1]
        elif order in ['descending', 'desc']:
            result = result

        if as_json is True:
            json_ = {
                'name': name,
                'recent':
                    [value.stock_as_json() for value in result]
            }

            return json.dumps(json_, sort_keys=False)
        elif as_json is False:
github alvarob96 / investpy / investpy / indices.py View on Github external
info = []
        
            for nested_ in elements_.xpath(".//td"):
                info.append(nested_.get('data-real-value'))

            index_date = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
            
            index_close = float(info[1].replace(',', ''))
            index_open = float(info[2].replace(',', ''))
            index_high = float(info[3].replace(',', ''))
            index_low = float(info[4].replace(',', ''))

            index_volume = int(info[5])

            result.insert(len(result), Data(index_date, index_open, index_high, index_low,
                                            index_close, index_volume, index_currency, None))

        if order in ['ascending', 'asc']:
            result = result[::-1]
        elif order in ['descending', 'desc']:
            result = result

        if as_json is True:
            json_ = {'name': name,
                     'recent':
                         [value.index_as_json() for value in result]
                     }

            return json.dumps(json_, sort_keys=False)
        elif as_json is False:
            df = pd.DataFrame.from_records([value.index_to_dict() for value in result])
github alvarob96 / investpy / investpy / crypto.py View on Github external
for nested_ in elements_.xpath(".//td"):
                    info.append(nested_.get('data-real-value'))

                if data_flag is True:
                    crypto_date = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
            
                    crypto_close = float(info[1].replace(',', ''))
                    crypto_open = float(info[2].replace(',', ''))
                    crypto_high = float(info[3].replace(',', ''))
                    crypto_low = float(info[4].replace(',', ''))

                    crypto_volume = int(info[5])

                    result.insert(len(result),
                                  Data(crypto_date, crypto_open, crypto_high, crypto_low,
                                       crypto_close, crypto_volume, crypto_currency, None))

            if data_flag is True:
                if order in ['ascending', 'asc']:
                    result = result[::-1]
                elif order in ['descending', 'desc']:
                    result = result

                if as_json is True:
                    json_ = {
                        'name': crypto_name,
                        'historical':
                            [value.crypto_as_json() for value in result]
                    }
                    
                    final.append(json_)
github alvarob96 / investpy / investpy / commodities.py View on Github external
info = []

            for nested_ in elements_.xpath(".//td"):
                info.append(nested_.get('data-real-value'))

            commodity_date = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
            
            commodity_close = float(info[1].replace(',', ''))
            commodity_open = float(info[2].replace(',', ''))
            commodity_high = float(info[3].replace(',', ''))
            commodity_low = float(info[4].replace(',', ''))

            commodity_volume = int(info[5])

            result.insert(len(result),
                          Data(commodity_date, commodity_open, commodity_high, commodity_low,
                               commodity_close, commodity_volume, currency, None))

        if order in ['ascending', 'asc']:
            result = result[::-1]
        elif order in ['descending', 'desc']:
            result = result

        if as_json is True:
            json_ = {
                'name': name,
                'recent':
                    [value.commodity_as_json() for value in result]
            }

            return json.dumps(json_, sort_keys=False)
        elif as_json is False:
github alvarob96 / investpy / investpy / funds.py View on Github external
data_flag = True

                info = []
        
                for nested_ in elements_.xpath(".//td"):
                    info.append(nested_.get('data-real-value'))

                if data_flag is True:
                    fund_date = datetime.strptime(str(datetime.fromtimestamp(int(info[0])).date()), '%Y-%m-%d')
                    
                    fund_close = float(info[1].replace(',', ''))
                    fund_open = float(info[2].replace(',', ''))
                    fund_high = float(info[3].replace(',', ''))
                    fund_low = float(info[4].replace(',', ''))

                    result.insert(len(result), Data(fund_date, fund_open, fund_high, fund_low,
                                                    fund_close, None, fund_currency, None))

            if data_flag is True:
                if order in ['ascending', 'asc']:
                    result = result[::-1]
                elif order in ['descending', 'desc']:
                    result = result

                if as_json is True:
                    json_ = {'name': name,
                             'historical':
                                 [value.fund_as_json() for value in result]
                             }

                    final.append(json_)
                elif as_json is False: