Skip to content

Commit 7df83dd

Browse files
authored
Merge pull request #183 from ranjanrak/feat-vcn
feat: add virtual contract note API
2 parents 891fa49 + 1aae036 commit 7df83dd

File tree

10 files changed

+121
-16
lines changed

10 files changed

+121
-16
lines changed

.github/workflows/test-conda.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
os: ["ubuntu-20.04", "windows-latest"]
13-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10"]
13+
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10"]
1414
steps:
1515
- uses: conda-incubator/setup-miniconda@v2
1616
with:

.github/workflows/test.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
os: [ubuntu-20.04, windows-latest]
12-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10", pypy2, pypy3]
13-
exclude:
14-
- os: windows-latest
15-
python-version: pypy3
16-
- os: windows-latest
17-
python-version: pypy2
18-
12+
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10"]
1913
steps:
2014
- uses: actions/checkout@v2
2115
with:

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ Kite Connect is a set of REST-like APIs that expose many capabilities required t
1818

1919
## v4 - Breaking changes
2020

21-
* Renamed ticker fields as per [kite connect doc](https://kite.trade/docs/connect/v3/websocket/#quote-packet-structure)
22-
* Renamed `bsecds` to `bcd` in `ticker.EXCHANGE_MAP`
21+
- Renamed ticker fields as per [kite connect doc](https://kite.trade/docs/connect/v3/websocket/#quote-packet-structure)
22+
- Renamed `bsecds` to `bcd` in `ticker.EXCHANGE_MAP`
23+
24+
## v5 - Breaking changes
25+
26+
- **Drop Support for Python 2.7**: Starting from version v5, support for Python 2.7 has been discontinued. This decision was made due to the [announcement](https://github.com/actions/setup-python/issues/672) by `setup-python`, which stopped supporting Python 2.x since May 2023.
27+
28+
- **For Python 2.x Users**: If you are using Python 2.x, you can continue using the `kiteconnect` library, but please stick to the <= 4.x.x versions of the library. You can find the previous releases on the [PyKiteConnect GitHub Releases](https://github.com/zerodha/pykiteconnect/releases) page.
2329

2430
## Installing the client
2531

examples/order_margins.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}]
2929

3030
margin_detail = kite.order_margins(order_param_single)
31-
logging.info("Required margin for single order: {}".format(order_param_single))
31+
logging.info("Required margin for single order: {}".format(margin_detail))
3232

3333
# Fetch margin detail for list of orders
3434
order_param_multi = [{
@@ -92,3 +92,46 @@
9292

9393
except Exception as e:
9494
logging.info("Error fetching order margin: {}".format(e))
95+
96+
97+
# Fetch virtual contract note charges
98+
try:
99+
order_book_params = [
100+
{
101+
"order_id": "111111111",
102+
"exchange": "NSE",
103+
"tradingsymbol": "SBIN",
104+
"transaction_type": "BUY",
105+
"variety": "regular",
106+
"product": "CNC",
107+
"order_type": "MARKET",
108+
"quantity": 1,
109+
"average_price": 560
110+
},
111+
{
112+
"order_id": "2222222222",
113+
"exchange": "MCX",
114+
"tradingsymbol": "GOLDPETAL23AUGFUT",
115+
"transaction_type": "SELL",
116+
"variety": "regular",
117+
"product": "NRML",
118+
"order_type": "LIMIT",
119+
"quantity": 1,
120+
"average_price": 5862
121+
},
122+
{
123+
"order_id": "3333333333",
124+
"exchange": "NFO",
125+
"tradingsymbol": "NIFTY23AUG17900PE",
126+
"transaction_type": "BUY",
127+
"variety": "regular",
128+
"product": "NRML",
129+
"order_type": "LIMIT",
130+
"quantity": 100,
131+
"average_price": 1.5
132+
}]
133+
134+
order_book_charges = kite.get_virtual_contract_note(order_book_params)
135+
logging.info("Virtual contract note charges: {}".format(order_book_charges))
136+
except Exception as e:
137+
logging.info("Error fetching virtual contract note charges: {}".format(e))

kiteconnect/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__description__ = "The official Python client for the Kite Connect trading API"
33
__url__ = "https://kite.trade"
44
__download_url__ = "https://github.com/zerodhatech/pykiteconnect"
5-
__version__ = "4.2.0"
5+
__version__ = "5.0.0-beta"
66
__author__ = "Zerodha Technology Pvt. Ltd. (India)"
77
__author_email__ = "talk@zerodha.tech"
88
__license__ = "MIT"

kiteconnect/connect.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ class KiteConnect(object):
161161

162162
# Margin computation endpoints
163163
"order.margins": "/margins/orders",
164-
"order.margins.basket": "/margins/basket"
164+
"order.margins.basket": "/margins/basket",
165+
"order.contract_note": "/charges/orders",
165166
}
166167

167168
def __init__(self,
@@ -786,6 +787,15 @@ def basket_order_margins(self, params, consider_positions=True, mode=None):
786787
is_json=True,
787788
query_params={'consider_positions': consider_positions, 'mode': mode})
788789

790+
def get_virtual_contract_note(self, params):
791+
"""
792+
Calculates detailed charges order-wise for the order book
793+
- `params` is list of orders to fetch charges detail
794+
"""
795+
return self._post("order.contract_note",
796+
params=params,
797+
is_json=True)
798+
789799
def _warn(self, message):
790800
""" Add deprecation warning message """
791801
warnings.simplefilter('always', DeprecationWarning)

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"Programming Language :: Python",
3434
"Natural Language :: English",
3535
"License :: OSI Approved :: MIT License",
36-
"Programming Language :: Python :: 2.7",
3736
"Programming Language :: Python :: 3.5",
3837
"Programming Language :: Python :: 3.6",
3938
"Programming Language :: Python :: 3.7",

tests/helpers/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545

4646
# Order margin & charges
4747
"order.margins": "order_margins.json",
48-
"order.margins.basket": "basket_margins.json"
48+
"order.margins.basket": "basket_margins.json",
49+
"order.contract_note": "virtual_contract_note.json"
4950
}
5051

5152

tests/unit/test_connect.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,55 @@ def test_basket_order_margins(kiteconnect):
417417
assert margin_detail['orders'][0]['type'] == "equity"
418418
# Order charges
419419
assert margin_detail['orders'][0]['total'] != 0
420+
421+
@responses.activate
422+
def test_virtual_contract_note(kiteconnect):
423+
""" Test virtual contract note charges """
424+
responses.add(
425+
responses.POST,
426+
"{0}{1}".format(kiteconnect.root, kiteconnect._routes["order.contract_note"]),
427+
body=utils.get_response("order.contract_note"),
428+
content_type="application/json"
429+
)
430+
431+
order_book_params = [{
432+
"order_id": "111111111",
433+
"exchange": "NSE",
434+
"tradingsymbol": "SBIN",
435+
"transaction_type": "BUY",
436+
"variety": "regular",
437+
"product": "CNC",
438+
"order_type": "MARKET",
439+
"quantity": 1,
440+
"average_price": 560
441+
},
442+
{
443+
"order_id": "2222222222",
444+
"exchange": "MCX",
445+
"tradingsymbol": "GOLDPETAL23JULFUT",
446+
"transaction_type": "SELL",
447+
"variety": "regular",
448+
"product": "NRML",
449+
"order_type": "LIMIT",
450+
"quantity": 1,
451+
"average_price": 5862
452+
},
453+
{
454+
"order_id": "3333333333",
455+
"exchange": "NFO",
456+
"tradingsymbol": "NIFTY2371317900PE",
457+
"transaction_type": "BUY",
458+
"variety": "regular",
459+
"product": "NRML",
460+
"order_type": "LIMIT",
461+
"quantity": 100,
462+
"average_price": 1.5
463+
}]
464+
465+
order_book_charges = kiteconnect.get_virtual_contract_note(order_book_params)
466+
# Order charges
467+
assert order_book_charges[0]['charges']['transaction_tax_type'] == "stt"
468+
assert order_book_charges[0]['charges']['total'] != 0
469+
# CTT tax type
470+
assert order_book_charges[1]['charges']['transaction_tax_type'] == "ctt"
471+
assert order_book_charges[1]['charges']['total'] != 0

0 commit comments

Comments
 (0)