Skip to content

Commit

Permalink
- Patched kite.historical_data and kite.instruments for Kite Web
Browse files Browse the repository at this point in the history
- exchange parameter not allowed on Kite Web for kite.instruments
- Bump version to 0.0.5
  • Loading branch information
BennyThadikaran committed Jul 10, 2024
1 parent 9d8c3f6 commit 204eda6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion aio_trader/kite/Kite.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class Kite(AbstractBroker):
GTT_STATUS_REJECTED = "rejected"
GTT_STATUS_DELETED = "deleted"

_type = "KITE_CONNECT"

base_dir = Path(__file__).parent
base_url = "https://api.kite.trade"
cookies = None
Expand Down Expand Up @@ -160,6 +162,7 @@ def _set_cookie(self, cookies):

def _set_enctoken(self, token):
self.req.session.headers.update({"Authorization": f"enctoken {token}"})
self._type = "KITE_WEB"

def _set_access_token(self, api_key, token):
return self.req.session.headers.update(
Expand Down Expand Up @@ -341,6 +344,9 @@ async def instruments(self, exchange: Optional[str] = None) -> bytes:

endpoint = "instruments"

if self._type == "KITE_WEB" and exchange:
raise ValueError("Exchange parameter cannot be used with Kite Web")

if exchange:
endpoint = f"{endpoint}/{exchange}"

Expand Down Expand Up @@ -481,6 +487,8 @@ async def historical_data(
:type oi: bool
"""

kite_web_url = "https://kite.zerodha.com/oms"

endpoint = f"instruments/historical/{instrument_token}/{interval}"

if isinstance(from_dt, datetime):
Expand All @@ -496,8 +504,13 @@ async def historical_data(
"oi": int(oi),
}

if self._type == "KITE_WEB":
url = kite_web_url
else:
url = self.base_url

return await self.req.get(
f"{self.base_url}/{endpoint}",
f"{url}/{endpoint}",
params=params,
throttle=hist_throttler,
)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
project = "Aio-Trader"
copyright = "2024, Benny Thadikaran"
author = "Benny Thadikaran"
release = "0.0.4"
release = "0.0.5"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
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 = "hatchling.build"

[project]
name = "aio_trader"
version = "0.0.4"
version = "0.0.5"
author = "Benny Thadikaran"
description = "Async Python library for various Indian stock brokers."
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="aio_trader",
version="0.0.4",
version="0.0.5",
description="Async Python library for various Indian stock brokers.",
long_description=(DIR / "README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 204eda6

Please sign in to comment.