diff --git a/.github/workflows/test-conda.yml b/.github/workflows/test-conda.yml index f5c5d968..9d500ad6 100644 --- a/.github/workflows/test-conda.yml +++ b/.github/workflows/test-conda.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-20.04", "windows-latest"] - python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10"] + python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10"] steps: - uses: conda-incubator/setup-miniconda@v2 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 04e583af..cf5b906b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,13 +9,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04, windows-latest] - python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10", pypy2, pypy3] - exclude: - - os: windows-latest - python-version: pypy3 - - os: windows-latest - python-version: pypy2 - + python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10"] steps: - uses: actions/checkout@v2 with: diff --git a/README.md b/README.md index 0ed56119..3ad3f718 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,14 @@ Kite Connect is a set of REST-like APIs that expose many capabilities required t ## v4 - Breaking changes -* Renamed ticker fields as per [kite connect doc](https://kite.trade/docs/connect/v3/websocket/#quote-packet-structure) -* Renamed `bsecds` to `bcd` in `ticker.EXCHANGE_MAP` +- Renamed ticker fields as per [kite connect doc](https://kite.trade/docs/connect/v3/websocket/#quote-packet-structure) +- Renamed `bsecds` to `bcd` in `ticker.EXCHANGE_MAP` + +## v5 - Breaking changes + +- **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. + +- **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. ## Installing the client diff --git a/examples/order_margins.py b/examples/order_margins.py index 078bfdcb..abba2ff1 100644 --- a/examples/order_margins.py +++ b/examples/order_margins.py @@ -28,7 +28,7 @@ }] margin_detail = kite.order_margins(order_param_single) - logging.info("Required margin for single order: {}".format(order_param_single)) + logging.info("Required margin for single order: {}".format(margin_detail)) # Fetch margin detail for list of orders order_param_multi = [{ @@ -92,3 +92,46 @@ except Exception as e: logging.info("Error fetching order margin: {}".format(e)) + + +# Fetch virtual contract note charges +try: + order_book_params = [ + { + "order_id": "111111111", + "exchange": "NSE", + "tradingsymbol": "SBIN", + "transaction_type": "BUY", + "variety": "regular", + "product": "CNC", + "order_type": "MARKET", + "quantity": 1, + "average_price": 560 + }, + { + "order_id": "2222222222", + "exchange": "MCX", + "tradingsymbol": "GOLDPETAL23AUGFUT", + "transaction_type": "SELL", + "variety": "regular", + "product": "NRML", + "order_type": "LIMIT", + "quantity": 1, + "average_price": 5862 + }, + { + "order_id": "3333333333", + "exchange": "NFO", + "tradingsymbol": "NIFTY23AUG17900PE", + "transaction_type": "BUY", + "variety": "regular", + "product": "NRML", + "order_type": "LIMIT", + "quantity": 100, + "average_price": 1.5 + }] + + order_book_charges = kite.get_virtual_contract_note(order_book_params) + logging.info("Virtual contract note charges: {}".format(order_book_charges)) +except Exception as e: + logging.info("Error fetching virtual contract note charges: {}".format(e)) \ No newline at end of file diff --git a/kiteconnect/__version__.py b/kiteconnect/__version__.py index b8304b60..c51c8730 100644 --- a/kiteconnect/__version__.py +++ b/kiteconnect/__version__.py @@ -2,7 +2,7 @@ __description__ = "The official Python client for the Kite Connect trading API" __url__ = "https://kite.trade" __download_url__ = "https://github.com/zerodhatech/pykiteconnect" -__version__ = "4.2.0" +__version__ = "5.0.0-beta" __author__ = "Zerodha Technology Pvt. Ltd. (India)" __author_email__ = "talk@zerodha.tech" __license__ = "MIT" diff --git a/kiteconnect/connect.py b/kiteconnect/connect.py index c3f49974..399f406f 100644 --- a/kiteconnect/connect.py +++ b/kiteconnect/connect.py @@ -161,7 +161,8 @@ class KiteConnect(object): # Margin computation endpoints "order.margins": "/margins/orders", - "order.margins.basket": "/margins/basket" + "order.margins.basket": "/margins/basket", + "order.contract_note": "/charges/orders", } def __init__(self, @@ -786,6 +787,15 @@ def basket_order_margins(self, params, consider_positions=True, mode=None): is_json=True, query_params={'consider_positions': consider_positions, 'mode': mode}) + def get_virtual_contract_note(self, params): + """ + Calculates detailed charges order-wise for the order book + - `params` is list of orders to fetch charges detail + """ + return self._post("order.contract_note", + params=params, + is_json=True) + def _warn(self, message): """ Add deprecation warning message """ warnings.simplefilter('always', DeprecationWarning) diff --git a/setup.py b/setup.py index 495098cd..7518f3c0 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,6 @@ "Programming Language :: Python", "Natural Language :: English", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index a035d81e..f58d7d28 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -45,7 +45,8 @@ # Order margin & charges "order.margins": "order_margins.json", - "order.margins.basket": "basket_margins.json" + "order.margins.basket": "basket_margins.json", + "order.contract_note": "virtual_contract_note.json" } diff --git a/tests/mock_responses b/tests/mock_responses index 02d0831c..0dd520a4 160000 --- a/tests/mock_responses +++ b/tests/mock_responses @@ -1 +1 @@ -Subproject commit 02d0831c44d30a9f4ac647a3a2c89b3c0279f317 +Subproject commit 0dd520a4b2d871d599920b0fbb7ba2c158499b93 diff --git a/tests/unit/test_connect.py b/tests/unit/test_connect.py index 3f312382..e6b1ba23 100644 --- a/tests/unit/test_connect.py +++ b/tests/unit/test_connect.py @@ -417,3 +417,55 @@ def test_basket_order_margins(kiteconnect): assert margin_detail['orders'][0]['type'] == "equity" # Order charges assert margin_detail['orders'][0]['total'] != 0 + +@responses.activate +def test_virtual_contract_note(kiteconnect): + """ Test virtual contract note charges """ + responses.add( + responses.POST, + "{0}{1}".format(kiteconnect.root, kiteconnect._routes["order.contract_note"]), + body=utils.get_response("order.contract_note"), + content_type="application/json" + ) + + order_book_params = [{ + "order_id": "111111111", + "exchange": "NSE", + "tradingsymbol": "SBIN", + "transaction_type": "BUY", + "variety": "regular", + "product": "CNC", + "order_type": "MARKET", + "quantity": 1, + "average_price": 560 + }, + { + "order_id": "2222222222", + "exchange": "MCX", + "tradingsymbol": "GOLDPETAL23JULFUT", + "transaction_type": "SELL", + "variety": "regular", + "product": "NRML", + "order_type": "LIMIT", + "quantity": 1, + "average_price": 5862 + }, + { + "order_id": "3333333333", + "exchange": "NFO", + "tradingsymbol": "NIFTY2371317900PE", + "transaction_type": "BUY", + "variety": "regular", + "product": "NRML", + "order_type": "LIMIT", + "quantity": 100, + "average_price": 1.5 + }] + + order_book_charges = kiteconnect.get_virtual_contract_note(order_book_params) + # Order charges + assert order_book_charges[0]['charges']['transaction_tax_type'] == "stt" + assert order_book_charges[0]['charges']['total'] != 0 + # CTT tax type + assert order_book_charges[1]['charges']['transaction_tax_type'] == "ctt" + assert order_book_charges[1]['charges']['total'] != 0