Skip to content

Commit

Permalink
Merge pull request #183 from ranjanrak/feat-vcn
Browse files Browse the repository at this point in the history
feat: add virtual contract note API
  • Loading branch information
vividvilla authored Jul 31, 2023
2 parents 891fa49 + 1aae036 commit 7df83dd
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 44 additions & 1 deletion examples/order_margins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [{
Expand Down Expand Up @@ -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))
2 changes: 1 addition & 1 deletion kiteconnect/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = "[email protected]"
__license__ = "MIT"
12 changes: 11 additions & 1 deletion kiteconnect/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


Expand Down
2 changes: 1 addition & 1 deletion tests/mock_responses
52 changes: 52 additions & 0 deletions tests/unit/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7df83dd

Please sign in to comment.