pybovespa is a basic library to get Bovespa stock values.
The BM&FBOVESPA (in full, Bolsa de Valores, Mercadorias & Futuros de São Paulo) is a stock exchange located at São Paulo, Brazil.
pybovespa is a basic and simple library to get official BM&FBOVESPA stock values.
# pip install -U pybovespa
When you make a request, 15-minute-old information is retrieved. You can check the date and time with stock.time. Example:
#!/usr/bin/env python3 from pybovespa.bovespa import * from pybovespa.stock import * bovespa = Bovespa() stock = bovespa.query("PETR3") print(stock.cod, stock.name, stock.last)
The output should be something like this:
PETR3 PETROBRAS ON 24,24
It is possible to make only one request for many stocks:
stocks = bovespa.query("PETR4", "VALE5", "OGXP3") for stock in stocks.values(): print(stock.cod, stock.last) stock_vale = stocks["VALE5"]
Unfortunately, BM&FBovespa does not allow the distribution of their data. However, it is very simple to download them using this library:
bovespa = Bovespa() bovespa.download(dst="/tmp/hist", year="2012", overwrite=True)
To download data of all available years: