Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annoucements function added #89

Merged
merged 4 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jugaad_data/nse/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):
self.s = requests.Session()
h = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36",
"accept-encoding": "gzip, deflate, br",
"accept-encoding": "gzip, deflate",
"accept":
"""text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9""",

Expand Down Expand Up @@ -147,7 +147,7 @@ def __init__(self):
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
Expand Down Expand Up @@ -214,7 +214,7 @@ def expiry_dates(dt, instrument_type="", symbol="", contracts=0):
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
Expand Down
4 changes: 2 additions & 2 deletions jugaad_data/nse/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):
"sec-fetch-site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
Expand Down Expand Up @@ -282,7 +282,7 @@ def __init__(self):
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
"Origin": "https://niftyindices.com",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
Expand Down
26 changes: 24 additions & 2 deletions jugaad_data/nse/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class NSELive:
"equity_option_chain": "/option-chain-equities",
"currency_option_chain": "/option-chain-currency",
"pre_open_market": "/market-data-pre-open",
"holiday_list": "/holiday-master?type=trading"
"holiday_list": "/holiday-master?type=trading",
"corporate_announcements": "/corporate-announcements"
}

def __init__(self):
Expand All @@ -37,7 +38,7 @@ def __init__(self):
"sec-fetch-site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
Expand Down Expand Up @@ -125,3 +126,24 @@ def pre_open_market(self, key="NIFTY"):
@live_cache
def holiday_list(self):
return self.get("holiday_list", {})

def corporate_announcements(self, segment='equities', from_date=None, to_date=None, symbol=None):
"""
This function returns the corporate annoucements
(https://www.nseindia.com/companies-listing/corporate-filings-announcements)
"""

#from_date: 02-12-2024
#to_date: 06-12-2024
#symbol:
payload = {"index": segment}

if from_date and to_date:
payload['from_date'] = from_date.strftime("%d-%m-%Y")
payload['to_date'] = to_date.strftime("%d-%m-%Y")
elif from_date or to_date:
raise Exception("Please provide both from_date and to_date")
if symbol:
payload['symbol'] = symbol
return self.get("corporate_announcements", payload)

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "jugaad-data"
version = "0.26"
version = "0.27"
requires-python = ">= 3.6"
authors = [{"name"= "jugaad-coder", "email"="abc@xyz.com"}]
description = "Free Zerodha API python library"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_nse.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test__post(self):
r = h._post_json("mypath", params=params)
assert json.loads(r.json()['data']) == params

"""
def test_index_raw(self):
symbol = "NIFTY 50"
from_date = date(2020, 6, 1)
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_index_df(self):
assert len(index_df) > 100
assert list(index_df.columns) == ['Index Name', 'INDEX_NAME', 'HistoricalDate', 'OPEN', 'HIGH',
'LOW', 'CLOSE']

"""

def test_expiry_dates():
dt = date(2020,1,1)
Expand Down
25 changes: 22 additions & 3 deletions tests/test_nse_live.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from jugaad_data.nse.live import NSELive

from datetime import date, datetime
n = NSELive()
def test_stock_quote():
r = n.stock_quote("HDFC")
Expand All @@ -25,13 +25,13 @@ def test_tick_data():
assert "grapthData" in d
d = n.tick_data("NIFTY 50", True)
assert "grapthData" in d

"""
def test_market_turnover():
d = n.market_turnover()
assert "data" in d
assert len(d['data']) > 1
assert 'name' in d['data'][0]

"""
def test_eq_derivative_turnover():
d = n.eq_derivative_turnover()
assert "value" in d
Expand Down Expand Up @@ -82,3 +82,22 @@ def test_pre_open_market():
assert "declines" in d
assert "unchanged" in d
assert "advances" in d

def test_corporate_announcements():
d = n.corporate_announcements()
assert type(d) == list
if len(d) > 0:
row = d[0]
assert 'symbol' in row.keys()

from_date = date(2024,1,1)
to_date = date(2024,1,2)
d = n.corporate_announcements(from_date=from_date, to_date=to_date)
assert len(d) > 0
for x in d:
print(x['symbol'])
if len(d) > 0:
assert 'symbol' in d[0].keys()
d = n.corporate_announcements(from_date=from_date, to_date=to_date, symbol='NESCO')

assert d[0]['symbol'] == 'NESCO'
Loading