Skip to content

Commit

Permalink
- Package divided into BSE.py and constants.py
Browse files Browse the repository at this point in the history
- New methods added:
    BSE.bhavcopyReport
    BSE.deliveryReport
    BSE.resultCalendar
    BSE.gainers
    BSE.losers
    BSE.quoteWeeklyHL
- BSE.allAnnouncements and BSE.announcements merged into BSE.announcements
- BSE.allCorporateActions and BSE.corporateActions merged into BSE.actions
- BSE.scripMeta dropped in favor of BSE.listSecurities
- BSE.announcements now returns a single page of announcements.
- User agent updated
- Added detailed documentation with sphinx
  • Loading branch information
BennyThadikaran committed Oct 23, 2023
1 parent ce2b2a8 commit 33d73f4
Show file tree
Hide file tree
Showing 28 changed files with 1,397 additions and 21,893 deletions.
116 changes: 11 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# BseIndiaApi

An unofficial python api for BSE India stock exchange.
An Unofficial Python Api for BSE India stock exchange.

Python version: >= 3.6
Python version: >= 3.10

## Install with PIP

```
pip install bse
```

## Documentation

[https://bennythadikaran.github.io/BseIndiaApi/](https://bennythadikaran.github.io/BseIndiaApi/)

## Usage

Using with statement
Expand All @@ -18,25 +22,26 @@ Using with statement
from bse import BSE

with BSE() as bse:
code = bse.getScripCode('tcs') # 532540 bse scrip code
scripCode = bse.getScripCode('tcs') # 532540 bse scrip code

bse.getScripName('532540') # TCS

data = bse.corporateActions(code)
data = bse.corporateActions(scripCode)

bse.quote(scrip_code) # Open, High, Low, LTP
oclc = bse.quote(scripCode) # Open, High, Low, LTP
```

or

```python
from bse import BSE
from bse.constants import INDEX

bse = BSE()

code = bse.getScripCode('tcs') # 532540 bse scrip code

bse.scripMeta(segment=bse.SEGMENT_EQUITY, status=bse.STATUS_ACTIVE, industry=bse.INDUSTRY_IT)
gainers = bse.gainers(by='index', name=INDEX.BSE500)

bse.exit() # close the request session
```
Expand All @@ -47,105 +52,6 @@ bse.exit() # close the request session

The files are named after the corresponding method in `src/BSE.py`. Use it to understand the API response structure.

## Available methods

```
Help on class BSE in module BSE:
class BSE(builtins.object)
| Unofficial api for BSE India
|
| Methods defined here:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| advanceDecline(self)
| returns list of dictionary of advance decline values for each index
|
| allAnnouncements(self, fromDate, toDate, category='-1')
| Returns all news items by date
|
| allCorporateActions(self)
| returns list of dictionary of all corporate actions
|
| announcements(self, scripcode, fromDate, toDate)
| Return Corporate announcements by scripcode and date
|
| corporateActions(self, scripcode)
| Returns Corporate Actions by scripcode
|
| exit(self)
|
| getScripCode(self, scripname)
| returns bse symbol code for stock symbol name
|
| getScripName(self, scripcode)
| returns stock symbol name for bse scrip code
|
| listSecurities(self, industry='', scripcode='', group='', segment='Equity', status='Active')
| List all securities with their meta info or filter by industry etc.
|
| near52WeekHighLow(self, scripcode='', indexcode='', group='')
| Returns stocks near 52 week highs and lows
|
| quote(self, scripcode)
| Get OHLC quotes for given scripcode
|
| scripMeta(self, scripcode='', segment='Equity', status='Active', group='', industry='')
| Return scrip meta info for all stocks or filtered by industry etc
```

## CONSTANTS

```python
# Corporate Announcement categories
CATEGORY_AGM = 'AGM/EGM'
CATEGORY_BOARD_MEETING = 'Board Meeting'
CATEGORY_UPDATE = 'Company Update'
CATEGORY_ACTION = 'Corp. Action'
CATEGORY_INSIDER = 'Insider Trading / SAST'
CATEGORY_NEW_LISTING = 'New Listing'
CATEGORY_RESULT = 'Result'
CATEGORY_OTHERS = 'Others'

# segments
SEGMENT_EQUITY = 'Equity'
SEGMENT_MF = 'MF'
SEGMENT_PREFERENCE_SHARES = 'Preference Shares'
SEGMENT_DEBENTURES_BONDS = 'Debentures and Bonds'
SEGMENT_EQUITY_INSTITUTIONAL = 'Equity - Institutional Series'
SEGMENT_COMMERCIAL_PAPERS = 'Commercial Papers'

# status
STATUS_ACTIVE = 'Active'
STATUS_SUSPENDED = 'Suspended'
STATUS_DELISTED = 'Delisted'

# industry / sector
INDUSTRY_AUTO = 'Automobile and Auto Components'
INDUSTRY_CAPITAL_GOODS = 'Capital Goods'
INDUSTRY_CHEMICALS = 'Chemicals'
INDUSTRY_CONSTRUCTION = 'Construction'
INDUSTRY_CONSTRUCTION_MATERIALS = 'Construction Materials'
INDUSTRY_CONSUMER_DURABLES = 'Consumer Durables'
INDUSTRY_CONSUMER_SERVICES = 'Consumer Services'
INDUSTRY_DIVERSIFIED = 'Diversified'
INDUSTRY_FMCG = 'Fast Moving Consumer Goods'
INDUSTRY_FIN_SERVICES = 'Financial Services'
INDUSTRY_FOREST_MATERIALS = 'Forest Materials'
INDUSTRY_IT = 'Information Technology'
INDUSTRY_MEDIA = 'Media, Entertainment & Publication'
INDUSTRY_METAL_MINING = 'Metals & Mining'
INDUSTRY_OIL_GAS = 'Oil, Gas & Consumable Fuels'
INDUSTRY_POWER = 'Power'
INDUSTRY_REALTY = 'Realty'
INDUSTRY_SERVICES = 'Services'
INDUSTRY_TELECOM = 'Telecommunication'
INDUSTRY_TEXTILES = 'Textiles'
INDUSTRY_UTILITIES = 'Utilities'
```

## Example Folder

`src/examples` contains scripts that use the `BSE.py`. These are script i wrote some years back. All scripts incorporate color and fancy formatting to look good. 😄
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
furo==2023.9.10
bse>=0.0.1
34 changes: 34 additions & 0 deletions docs/source/Constants.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Constants
---------

.. autoclass:: bse.constants.CATEGORY
:members:
:undoc-members:

.. autoclass:: bse.constants.SEGMENT
:members:
:undoc-members:

.. autoclass:: bse.constants.STATUS
:members:
:undoc-members:

.. autoclass:: bse.constants.INDEX
:members:
:undoc-members:

.. autoclass:: bse.constants.PURPOSE
:members:
:undoc-members:

.. autoclass:: bse.constants.SECTOR
:members:
:undoc-members:

.. autoclass:: bse.constants.SECTOR_ISIN
:members:
:undoc-members:

.. autoclass:: bse.constants.INDUSTRY
:members:
:undoc-members:
36 changes: 36 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
from pathlib import Path

src = Path(__file__).parents[2].resolve() / 'src'

sys.path.insert(0, src.as_posix())

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'bse'
copyright = '2023, Benny Thadikaran'
author = 'Benny Thadikaran'
release = '1.0.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
]

templates_path = ['_templates']
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'furo'
html_static_path = ['_static']
23 changes: 23 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. bse documentation master file, created by
sphinx-quickstart on Mon Oct 23 12:04:38 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to BSE's documentation!
=======================================

**BSE** is an Unofficial Python Api for BSE India stock exchange

Python version: >= 3.10

All network requests through BSE are rate limited or throttled. This allows making large number of requests without overloading the server or getting blocked.

GitHub Source: `BennyThadikaran/BseIndiaApi <https://github.com/BennyThadikaran/BseIndiaApi>`_

Contents
--------

.. toctree::

usage
Constants
71 changes: 71 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
=====
Usage
=====

Installation
------------

To use ``bse``, first install it using pip:

.. code:: console
$ pip install bse
Example
-------

.. code-block:: python
from bse import BSE
bse = BSE()
bse.exit() # close requests session
.. code-block:: python
:caption: Using 'with' statement
with BSE() as bse:
pass
API
___

General Methods
---------------

.. automethod:: bse.BSE.exit

.. automethod:: bse.BSE.getScripName

.. automethod:: bse.BSE.getScripCode

Download Reports
----------------
.. automethod:: bse.BSE.bhavcopyReport

.. automethod:: bse.BSE.deliveryReport

Corporate Filings
-----------------

.. automethod:: bse.BSE.announcements

.. automethod:: bse.BSE.actions

.. automethod:: bse.BSE.resultCalendar

Market Updates and Summary
--------------------------

.. automethod:: bse.BSE.gainers

.. automethod:: bse.BSE.losers

.. automethod:: bse.BSE.near52WeekHighLow

.. automethod:: bse.BSE.quote

.. automethod:: bse.BSE.quoteWeeklyHL

.. automethod:: bse.BSE.listSecurities
Loading

0 comments on commit 33d73f4

Please sign in to comment.