# BVCscrap
BVCscrap is a Python library to retrieve data from [LeBoursier.ma](https://www.leboursier.ma/) and [Bourse de Casablanca](https://www.casablanca-bourse.com/bourseweb/index.aspx), which provides data retrieval from up to 78 stocks and indices. BVCscrap allows the user to download historical and intraday data from all the shares traded on Casablanca Stock Exchange.
BVCscrap stands for "La Bourse des valeurs de Casablanca" scraper.
- PyPI: https://pypi.org/project/BVCscrap/
## Requirements
In order to use BVCscrap you should download the following packages: requests, beautifulsoup4, lxml, json, and datetime.
The outputs of this library are DataFrames or dictionaries, so Pandas should be installed
## Install
```python
pip install BVCscrap
import BVCscrap as bvc
```
## What's new :
For each stock you can get: Session data, latest transactions, best limit and data of the last 5 sessions:
https://user-images.githubusercontent.com/49843367/159122217-c2bc3225-df3a-40eb-abfd-a890fdfa2f2b.mp4
You can get all the key indicators available at "Bourse de Casablanca"
https://user-images.githubusercontent.com/49843367/159122265-efe58782-02ae-43ff-8fe8-04054c3de5e3.mp4
You can also get indexes summary for each session. Examples and more functions are available at [this notebook](/BVCscrap_Exemple.ipynb)
![indicateur_02](https://user-images.githubusercontent.com/49843367/159123465-bd556c63-bbbf-4354-aea8-fbd43f900983.png)
## How to use
To use this libary there is a notation to respect: names of stocks.
You can find jupyter notebooks on [Github](https://github.com/AmineAndam04/BVCscrap)
### Get the notation
```python
import BVCscrap as bvc
bvc.notation()
```
```{r, engine='python', count_lines}
['Addoha',
'AFMA',
'Afric Indus',
'Afriquia Gaz',
'Agma',
.
.
'Zellidja',
'MASI','MSI20']
```
### Data of one single stock
Syntaxe :`loadata(name, start=None,end=None,decode="utf-8")`
To get data from date 0 (The data is provided from Septembre 2016)
```python
import BVCscrap as bvc
data=bvc.loadata('BCP')
data.tail()
```
```{r, engine='python', count_lines}
Value Min Max Variation Volume
date
22/09/2021 271.00 269.60 271.00 0.00 52908
23/09/2021 272.60 271.00 273.00 0.59 37230
24/09/2021 276.00 271.00 278.00 1.25 162109
27/09/2021 275.00 272.05 276.95 -0.36 51533
28/09/2021 276.05 272.70 276.05 0.38 17676
```
You can get data between two periods :
```python
data=bvc.loadata('CIH',start='2018-01-01',end='2019-01-01')
data
```
```{r, engine='python', count_lines}
Value Min Max Variation Volume
date
02/01/2018 278.0 278.00 279.5 -2.80 312
03/01/2018 278.0 278.00 279.5 0.00 312
... ... ... ... ... ...
28/12/2018 294.0 294.00 301.0 -2.00 211865
31/12/2018 300.0 300.00 300.0 2.04 12
```
You can get the historical data of MASI and MSI20
```python
data=bvc.loadata('MASI',start='2022-09-01',end='2022-09-5')
data
```
```{r, engine='python', count_lines}
Value
labels
2022-09-01 12127.1717
2022-09-02 12136.2882
2022-09-05 12140.7196
```
```python
data=bvc.loadata('MSI20',start='2022-09-01',end='2022-09-5')
data
```
```{r, engine='python', count_lines}
Value
labels
2022-09-01 980.633689
2022-09-02 981.350658
2022-09-05 982.005686
```
Sometime you may face some encoding\decoding issues, you can change the value of `decode` argument from its default value "utf-8" to another format (e.g "utf-8-sig" is working )
### Data of many stocks
Syntaxe :`loadmany(*args,start=None,end=None,feature="Value",decode="utf-8")`
```python
data=bvc.loadmany('BCP','CIH')
data.tail()
```
```{r, engine='python', count_lines}
BCP CIH
22/09/2021 271.00 301.0
23/09/2021 272.60 305.0
24/09/2021 276.00 313.0
27/09/2021 275.00 310.0
28/09/2021 276.05 305.8
```
You can use start and end arguments :
```python
data=bvc.loadmany('BCP','CIH',start='2018-01-01',end='2019-01-01')
data.tail()
```
```{r, engine='python', count_lines}
BCP CIH
date
02/01/2018 293.0 278.0
03/01/2018 289.9 278.0
04/01/2018 285.3 280.8
05/01/2018 283.0 280.8
08/01/2018 285.4 280.8
... ... ...
25/12/2018 279.0 294.2
26/12/2018 277.0 296.0
27/12/2018 279.9 300.0
28/12/2018 280.0 294.0
31/12/2018 280.0 300.0
```
In case you want to have data of lots of stocks you can give the function a list of these stocks. Moreover `feature` argument let you choose another variable (Value, Min, Max, Variation, Volume")
```python
data=bvc.loadmany(['BCP','BMCI','BOA','CIH'],start="2021-08-30",end='2021-09-04',feature="Volume")
data
```
```{r, engine='python', count_lines}
BCP BMCI BOA CIH
Date
30/08/2021 702 33 172 53
31/08/2021 69575 2515 5853 1005
01/09/2021 28095 2515 3700 1005
02/09/2021 55744 2353 14 50
03/09/2021 26533 2353 8300 500
```
## Intraday data
Syntaxe : `getIntraday(name,decode="utf-8")`
```python
import BVCscrap as load
data=load.getIntraday('MASI')
data
```
```{r, engine='python',count_lines}
Value
09:30 12899.66
09:31 12900.10
09:32 12900.60
09:34 12900.45
09:35 12901.24
... ...
15:12 12975.64
15:14 12976.79
15:17 12976.69
15:18 12978.58
15:30 13019.20
```
## Session data
Syntaxe : `getCours(name)`
```python
cours=bvc.getCours("BOA")
cours.keys()
```
```{r,engine="python",count_lines}
dict_keys(['Données_Seance', 'Meilleur_limit', 'Dernieres_Tansaction', 'Seance_prec'])
```
```python
import pandas as pd
cours["Données_Seance"]
cours['Meilleur_limit']
pd.DataFrame(cours["Seance_prec"])
pd.DataFrame(cours["Dernieres_Tansaction"])
```
## Key Indicators
Syntaxe : `getKeyIndicators(name,decode='utf-8')`
```python
indicateur=bvc.getKeyIndicators('BOA')
indicateur.keys()
```
```{r,engine="python",count_lines}
dict_keys(['Info_Societe', 'Actionnaires', 'Chiffres_cles', 'Ratio'])
```
## Dividend
Syntaxe: `getDividend(name,decode='utf-8')`
```python
dividends=bvc.getDividend("BOA")
pd.DataFrame(dividends)
```
```{r,engine="python",count_lines}
Annee Montant_Dividende Type_Dividende Date_detachement Date_paiement
0 2020 5,00 Ordinaire 15/07/2021 29/07/2021
1 2019 5,00 Ordinaire 10/08/2020 28/09/2020
2 2018 5,00 Ordinaire 03/07/2019 15/08/2019
3 2017 5,00 Ordinaire 29/06/2018 10/07/2018
```
## Indexes summary
Syntaxe : `getIndex()`
```python
index=bvc.getIndex()
index.keys()
```
```{r,engine="python",count_lines}
dict_keys(['Resume indice', 'Indice rentabilite', 'Indices en devises', 'Indice FTSE', 'Indices sectoriels'])
```
## Weights
Syntaxe : `getPond()`
```python
pond=bvc.getPond()
pd.DataFrame(pond)
```
```{r,engine="python",count_lines}
Code Isin Instrument Nombre de titres Cours Facteur flottant Facteur plafonnement Capitalisation flottante Poids
0 MA0000012445 ATTIJARIWAFA BANK 215140839 477,95 0,30 1,00 30847969200,02 0,1834
1 MA0000011488 ITISSALAT AL-MAGHRIB 879095340 130,10 0,20 1,00 22874060746,80 0,1360
2 MA0000012320 LAFARGEHOLCIM MAR 23431240 1919,00 0,30 1,00 13489364868,00 0,0802
```
## Indexes of the current session
Syntaxe: `getIndexRecap()`
```python
recap=bvc.getIndexRecap()
recap.keys()
```
```{r,engine="python",count_lines}
dict_keys(['Indice', 'Volume Global', 'Plus forte hausse', 'Plus forte baisse'])
```
## Getting Help
If you are working in Jupyter notebook/lab, you can see the docstring of our functions by using Shift+Tab. An example is shown below
```python
"""
Load Data
Inputs:
Input | Type | Description
=================================================================================
name |string | You must respect the notation. To see the notation see BVCscrap.notation
start |string "YYYY-MM-DD" | starting date Must respect the notation
end |string "YYYY-MM-DD" | Must respect the notation
Outputs:
Output | Type | Description
=================================================================================
| pandas.DataFrame (4 columns) | close high low open vol
"""
```
Question? Contact me on Twitter [@AmineAndam](https://twitter.com/AmineAndam) or on Linkedin [ANDAM AMINE](https://www.linkedin.com/in/amineandam/).
Raw data
{
"_id": null,
"home_page": "https://github.com/AmineAndam04/BVCscrap",
"name": "BVCscrap",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "Web scrapping,financial data,Bourse des Valeurs de Casablanca",
"author": "ANDAM Amine",
"author_email": "andamamine83@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/da/9c/5e3ddc0e55125533e797c4427dce58662307c6567d46fcd956f5bcf09fca/BVCscrap-0.2.1.tar.gz",
"platform": null,
"description": "# BVCscrap\r\nBVCscrap is a Python library to retrieve data from [LeBoursier.ma](https://www.leboursier.ma/) and [Bourse de Casablanca](https://www.casablanca-bourse.com/bourseweb/index.aspx), which provides data retrieval from up to 78 stocks and indices. BVCscrap allows the user to download historical and intraday data from all the shares traded on Casablanca Stock Exchange. \r\n\r\nBVCscrap stands for \"La Bourse des valeurs de Casablanca\" scraper.\r\n\r\n-\tPyPI: https://pypi.org/project/BVCscrap/\r\n## Requirements \r\nIn order to use BVCscrap you should download the following packages: requests, beautifulsoup4, lxml, json, and datetime.\r\n\r\nThe outputs of this library are DataFrames or dictionaries, so Pandas should be installed \r\n\r\n## Install\r\n\r\n```python\r\npip install BVCscrap\r\nimport BVCscrap as bvc\r\n```\r\n## What's new :\r\nFor each stock you can get: Session data, latest transactions, best limit and data of the last 5 sessions:\r\n\r\nhttps://user-images.githubusercontent.com/49843367/159122217-c2bc3225-df3a-40eb-abfd-a890fdfa2f2b.mp4\r\n\r\n\r\nYou can get all the key indicators available at \"Bourse de Casablanca\"\r\n\r\n\r\nhttps://user-images.githubusercontent.com/49843367/159122265-efe58782-02ae-43ff-8fe8-04054c3de5e3.mp4\r\n\r\nYou can also get indexes summary for each session. Examples and more functions are available at [this notebook](/BVCscrap_Exemple.ipynb)\r\n![indicateur_02](https://user-images.githubusercontent.com/49843367/159123465-bd556c63-bbbf-4354-aea8-fbd43f900983.png)\r\n\r\n## How to use\r\nTo use this libary there is a notation to respect: names of stocks.\r\nYou can find jupyter notebooks on [Github](https://github.com/AmineAndam04/BVCscrap)\r\n### Get the notation\r\n```python \r\nimport BVCscrap as bvc\r\nbvc.notation()\r\n```\r\n```{r, engine='python', count_lines}\r\n['Addoha',\r\n 'AFMA',\r\n 'Afric Indus',\r\n 'Afriquia Gaz',\r\n 'Agma',\r\n .\r\n .\r\n 'Zellidja',\r\n 'MASI','MSI20']\r\n\r\n```\r\n\r\n### Data of one single stock\r\nSyntaxe :`loadata(name, start=None,end=None,decode=\"utf-8\")`\r\n\r\nTo get data from date 0 (The data is provided from Septembre 2016)\r\n```python\r\nimport BVCscrap as bvc\r\ndata=bvc.loadata('BCP')\r\ndata.tail()\r\n```\r\n```{r, engine='python', count_lines}\r\n Value\t Min\t Max\t Variation\t Volume\r\n date \r\n22/09/2021\t271.00\t 269.60\t 271.00\t0.00\t\t52908\r\n23/09/2021\t272.60\t 271.00\t 273.00\t0.59\t\t37230\r\n24/09/2021\t276.00\t 271.00\t 278.00\t1.25\t\t162109\r\n27/09/2021\t275.00\t 272.05\t 276.95 -0.36\t\t51533\r\n28/09/2021\t276.05\t 272.70\t 276.05\t0.38\t\t17676\r\n```\r\nYou can get data between two periods :\r\n```python\r\ndata=bvc.loadata('CIH',start='2018-01-01',end='2019-01-01')\r\ndata\r\n```\r\n```{r, engine='python', count_lines}\r\n\t Value\tMin\t Max Variation \tVolume\r\ndate\t\t\t\t\t\r\n02/01/2018\t278.0\t278.00\t279.5\t-2.80\t \t312\r\n03/01/2018\t278.0\t278.00\t279.5\t0.00\t\t312\r\n...\t...\t...\t...\t...\t...\r\n28/12/2018\t294.0\t294.00\t301.0\t-2.00\t\t211865\r\n31/12/2018\t300.0\t300.00\t300.0\t2.04\t\t12\r\n```\r\nYou can get the historical data of MASI and MSI20\r\n```python\r\ndata=bvc.loadata('MASI',start='2022-09-01',end='2022-09-5')\r\ndata\r\n```\r\n```{r, engine='python', count_lines}\r\n\t\t Value\r\nlabels\t\r\n2022-09-01\t12127.1717\r\n2022-09-02\t12136.2882\r\n2022-09-05\t12140.7196\r\n```\r\n\r\n```python\r\ndata=bvc.loadata('MSI20',start='2022-09-01',end='2022-09-5')\r\ndata\r\n```\r\n```{r, engine='python', count_lines}\r\n\t\t Value\r\nlabels\t\r\n2022-09-01\t980.633689\r\n2022-09-02\t981.350658\r\n2022-09-05\t982.005686\r\n```\r\nSometime you may face some encoding\\decoding issues, you can change the value of `decode` argument from its default value \"utf-8\" to another format (e.g \"utf-8-sig\" is working )\r\n\r\n### Data of many stocks\r\nSyntaxe :`loadmany(*args,start=None,end=None,feature=\"Value\",decode=\"utf-8\")`\r\n```python\r\ndata=bvc.loadmany('BCP','CIH')\r\ndata.tail()\r\n```\r\n```{r, engine='python', count_lines}\r\n BCP CIH\r\n22/09/2021\t271.00\t301.0\r\n23/09/2021\t272.60\t305.0\r\n24/09/2021\t276.00\t313.0\r\n27/09/2021\t275.00\t310.0\r\n28/09/2021\t276.05\t305.8\r\n```\r\nYou can use start and end arguments :\r\n```python\r\ndata=bvc.loadmany('BCP','CIH',start='2018-01-01',end='2019-01-01')\r\ndata.tail()\r\n```\r\n```{r, engine='python', count_lines}\r\n\t BCP\tCIH\r\ndate\t\t\r\n02/01/2018\t293.0\t278.0\r\n03/01/2018\t289.9\t278.0\r\n04/01/2018\t285.3\t280.8\r\n05/01/2018\t283.0\t280.8\r\n08/01/2018\t285.4\t280.8\r\n...\t...\t...\r\n25/12/2018\t279.0\t294.2\r\n26/12/2018\t277.0\t296.0\r\n27/12/2018\t279.9\t300.0\r\n28/12/2018\t280.0\t294.0\r\n31/12/2018\t280.0\t300.0\r\n```\r\nIn case you want to have data of lots of stocks you can give the function a list of these stocks. Moreover `feature` argument let you choose another variable (Value, Min, Max, Variation, Volume\")\r\n\r\n```python\r\ndata=bvc.loadmany(['BCP','BMCI','BOA','CIH'],start=\"2021-08-30\",end='2021-09-04',feature=\"Volume\")\r\ndata\r\n```\r\n```{r, engine='python', count_lines}\r\n\t\tBCP\tBMCI\tBOA\tCIH\r\n Date\t\t\t\t\r\n30/08/2021\t702\t33\t172\t53\r\n31/08/2021\t69575\t2515\t5853\t1005\r\n01/09/2021\t28095\t2515\t3700\t1005\r\n02/09/2021\t55744\t2353\t14\t50\r\n03/09/2021\t26533\t2353\t8300\t500\r\n```\r\n## Intraday data\r\nSyntaxe : `getIntraday(name,decode=\"utf-8\")`\r\n```python\r\nimport BVCscrap as load\r\ndata=load.getIntraday('MASI')\r\ndata\r\n```\r\n```{r, engine='python',count_lines}\r\n \t Value\r\n09:30\t12899.66\r\n09:31\t12900.10\r\n09:32\t12900.60\r\n09:34\t12900.45\r\n09:35\t12901.24\r\n...\t...\r\n15:12\t12975.64\r\n15:14\t12976.79\r\n15:17\t12976.69\r\n15:18\t12978.58\r\n15:30\t13019.20\r\n```\r\n## Session data\r\nSyntaxe : `getCours(name)`\r\n```python\r\ncours=bvc.getCours(\"BOA\") \r\ncours.keys()\r\n```\r\n```{r,engine=\"python\",count_lines}\r\ndict_keys(['Donn\u00e9es_Seance', 'Meilleur_limit', 'Dernieres_Tansaction', 'Seance_prec'])\r\n```\r\n```python\r\nimport pandas as pd\r\ncours[\"Donn\u00e9es_Seance\"]\r\ncours['Meilleur_limit']\r\npd.DataFrame(cours[\"Seance_prec\"])\r\npd.DataFrame(cours[\"Dernieres_Tansaction\"])\r\n```\r\n## Key Indicators\r\nSyntaxe : `getKeyIndicators(name,decode='utf-8')`\r\n```python\r\nindicateur=bvc.getKeyIndicators('BOA')\r\nindicateur.keys()\r\n```\r\n```{r,engine=\"python\",count_lines}\r\ndict_keys(['Info_Societe', 'Actionnaires', 'Chiffres_cles', 'Ratio'])\r\n```\r\n## Dividend\r\nSyntaxe: `getDividend(name,decode='utf-8')`\r\n```python\r\ndividends=bvc.getDividend(\"BOA\")\r\npd.DataFrame(dividends)\r\n```\r\n```{r,engine=\"python\",count_lines}\r\n Annee\tMontant_Dividende Type_Dividende Date_detachement Date_paiement\r\n0\t2020\t 5,00\t Ordinaire\t 15/07/2021\t 29/07/2021\r\n1\t2019\t 5,00\t Ordinaire\t 10/08/2020\t 28/09/2020\r\n2\t2018\t 5,00\t\t Ordinaire\t 03/07/2019\t 15/08/2019\r\n3\t2017\t 5,00\t\t Ordinaire\t 29/06/2018\t 10/07/2018\r\n```\r\n## Indexes summary\r\nSyntaxe : `getIndex()`\r\n```python\r\nindex=bvc.getIndex()\r\nindex.keys()\r\n```\r\n```{r,engine=\"python\",count_lines}\r\ndict_keys(['Resume indice', 'Indice rentabilite', 'Indices en devises', 'Indice FTSE', 'Indices sectoriels'])\r\n```\r\n## Weights\r\nSyntaxe : `getPond()`\r\n```python\r\npond=bvc.getPond()\r\npd.DataFrame(pond)\r\n```\r\n```{r,engine=\"python\",count_lines}\r\n\tCode Isin\tInstrument Nombre de titres\tCours\tFacteur flottant Facteur plafonnement\tCapitalisation flottante Poids\r\n0\tMA0000012445\tATTIJARIWAFA BANK\t215140839 477,95\t0,30\t 1,00\t 30847969200,02\t 0,1834\r\n1\tMA0000011488\tITISSALAT AL-MAGHRIB\t879095340 130,10\t0,20\t 1,00\t\t\t 22874060746,80\t 0,1360\r\n2\tMA0000012320\tLAFARGEHOLCIM MAR\t23431240 1919,00\t0,30\t 1,00\t\t\t 13489364868,00\t 0,0802\r\n```\r\n## Indexes of the current session\r\nSyntaxe: `getIndexRecap()`\r\n```python\r\nrecap=bvc.getIndexRecap()\r\nrecap.keys()\r\n```\r\n```{r,engine=\"python\",count_lines}\r\ndict_keys(['Indice', 'Volume Global', 'Plus forte hausse', 'Plus forte baisse'])\r\n```\r\n\r\n\r\n## Getting Help \r\nIf you are working in Jupyter notebook/lab, you can see the docstring of our functions by using Shift+Tab. An example is shown below\r\n```python\r\n\"\"\"\r\n\tLoad Data \r\n\tInputs: \r\n\t\t\tInput | Type | Description\r\n\t\t\t=================================================================================\r\n\t\t\t name |string | You must respect the notation. To see the notation see BVCscrap.notation\r\n\t start |string \"YYYY-MM-DD\" | starting date Must respect the notation\r\n\t end |string \"YYYY-MM-DD\" | Must respect the notation\r\n\tOutputs:\r\n\t Output | Type | Description\r\n\t ================================================================================= \r\n\t \t | pandas.DataFrame (4 columns) | close high low open vol\r\n\"\"\"\r\n```\r\n\r\n\r\nQuestion? Contact me on Twitter [@AmineAndam](https://twitter.com/AmineAndam) or on Linkedin [ANDAM AMINE](https://www.linkedin.com/in/amineandam/).\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Python library to scrape financial data from Casablanca Stock Exchange(Bourse des Valeurs de Casablanca)",
"version": "0.2.1",
"split_keywords": [
"web scrapping",
"financial data",
"bourse des valeurs de casablanca"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fbaf2fe715ccece6db253da3613ddcf473c2ed924d7f03645ab730e4786f1709",
"md5": "90db19b7e6bb07962b957655d80abbdd",
"sha256": "5f31491de5c16a0d61c484b8e25b69100f535d96119004f8d1da1b63be755a72"
},
"downloads": -1,
"filename": "BVCscrap-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "90db19b7e6bb07962b957655d80abbdd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 13056,
"upload_time": "2023-04-02T11:16:34",
"upload_time_iso_8601": "2023-04-02T11:16:34.387216Z",
"url": "https://files.pythonhosted.org/packages/fb/af/2fe715ccece6db253da3613ddcf473c2ed924d7f03645ab730e4786f1709/BVCscrap-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "da9c5e3ddc0e55125533e797c4427dce58662307c6567d46fcd956f5bcf09fca",
"md5": "ac4766e59c8808e97a0b3f96f49516e3",
"sha256": "421122e65775bbc364745f7cb856ecf251839623a98b0f2b436645b7e637f412"
},
"downloads": -1,
"filename": "BVCscrap-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "ac4766e59c8808e97a0b3f96f49516e3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 12655,
"upload_time": "2023-04-02T11:16:36",
"upload_time_iso_8601": "2023-04-02T11:16:36.555084Z",
"url": "https://files.pythonhosted.org/packages/da/9c/5e3ddc0e55125533e797c4427dce58662307c6567d46fcd956f5bcf09fca/BVCscrap-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-02 11:16:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "AmineAndam04",
"github_project": "BVCscrap",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "bvcscrap"
}