Idirect-Tech / Breeze-Python-SDK

The official Python client library for the ICICI Securities trading APIs
MIT License
53 stars 28 forks source link

Margin Calculator does not work #47

Closed RajasKhokle closed 7 months ago

RajasKhokle commented 8 months ago

I am getting an error 'BreezeConnect' object has no attribute 'margin_calculator'. When I tried the code from https://api.icicidirect.com/breezeapi/documents/index.html#margin-calculator, it gave an error https://api.icicidirect.com/breezeapi/documents/index.html#margin-calculator.

RajasKhokle commented 8 months ago

Sorry, the error was {"Status":5,"Error":"Index was outside the bounds of the array."}'

Idirect-Tech commented 8 months ago

Dear Rajas,

Kindly share the parameters you are passing. Will check it and update you shortly.

[E29CF836]

Thanks & Regards,

Hiten Solanki,

Team Breeze API,

ICICI Securities


From: Rajas Khokle @.> Sent: Wednesday, November 8, 2023 9:58 AM To: Idirect-Tech/Breeze-Python-SDK @.> Cc: Subscribed @.***> Subject: Re: [Idirect-Tech/Breeze-Python-SDK] Margin Calculator does not work (Issue #47)

External Email Warning: Use 'Report suspicious Email' button to report Phishing mails. Do not click on any attachment or links/URL in this email unless sender is reliable.

Sorry, the error was {"Status":5,"Error":"Index was outside the bounds of the array."}'

— Reply to this email directly, view it on GitHubhttps://github.com/Idirect-Tech/Breeze-Python-SDK/issues/47#issuecomment-1801066538, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3TQZ43S7F23PH7MZF4LPH3YDMC6BAVCNFSM6AAAAAA7CF3BPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBRGA3DMNJTHA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

Print this mail only if absolutely necessary. Save Paper. Save Trees." "The information contained in this e-mail and any attachments to this message are intended for the exclusive use of the intended recipient and may contain proprietary, confidential or legally privileged information. If you are not the intended recipient, please note that you are not authorised to disseminate, distribute or copy this e-mail or any parts of it or act upon/rely on the contents of this e-mail in any manner. Please notify the sender immediately by e-mail and destroy all copies of this e-mail and any attachments. Please also note that ICICI Bank or its subsidiaries and associated companies, (collectively "ICICI Group"), are unable to exercise control or ensure the integrity of/over the contents of the information contained in e-mail transmissions and that any views expressed in this e-mail are not endorsed by/binding on the ICICI Group unless the sender does so expressly with due authority of ICICI Group. Before opening any attachments please check them for viruses and defects and please note that ICICI Group accepts no liability or responsibility for any damage caused by any virus that may be transmitted by this email. Any unauthorized use of this email or any attachment(s) may be treated as infringement of right(s) including right of privacy under the applicable laws of India including Information and Technology Act, 2000. Thank you for your cooperation. Regulatory Disclosures are available on https://www.icicisecurities.com (for institutional business) and www.icicidirect.com (for retail business).

RajasKhokle commented 8 months ago

It is same as given in the ref doc - except for my session key, secret key and app key

import http.client import json import hashlib conn = http.client.HTTPSConnection("api.icicidirect.com") payload = json.dumps({ "list_of_positions": [ { "strike_price": "0", "quantity": "15", "right": "others", "product": "futures", "action": "buy", "price": "46230.85", "expiry_date": "31-Aug-2023", "stock_code": "CNXBAN", "cover_order_flow": "N", "fresh_order_type": "N", "cover_limit_rate": "0", "cover_sltp_price": "0", "fresh_limit_rate": "0", "open_quantity": "0" }, { "strike_price": "37000", "quantity": "15", "right": "Call", "product": "options", "action": "buy", "price": "9100", "expiry_date": "27-Jul-2023", "stock_code": "CNXBAN", "cover_order_flow": "N", "fresh_order_type": "N", "cover_limit_rate": "0", "cover_sltp_price": "0", "fresh_limit_rate": "0", "open_quantity": "0" }, { "strike_price": "0", "quantity": "50", "right": "others", "product": "futureplus", "action": "buy", "price": "19800", "expiry_date": "27-Jul-2023", "stock_code": "NIFTY", "cover_order_flow": "N", "fresh_order_type": "N", "cover_limit_rate": "0", "cover_sltp_price": "0", "fresh_limit_rate": "0", "open_quantity": "0" }, { "strike_price": "19600", "quantity": "50", "right": "call", "product": "optionplus", "action": "buy", "price": "245.05", "expiry_date": "27-Jul-2023", "stock_code": "NIFTY", "cover_order_flow": "sell", "fresh_order_type": "limit", "cover_limit_rate": "180.00", "cover_sltp_price": "200.00", "fresh_limit_rate": "245.05", "open_quantity": "50" } ], "exchange_code": "NFO" })

checksum computation

time_stamp & checksum generation for request-headers

appkey = app_key secret_key = secret_key time_stamp = dt.datetime.utcnow().isoformat()[:19] + '.000Z' checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest()

headers = { 'Content-Type': 'application/json', 'X-Checksum': 'token ' + checksum, 'X-Timestamp': time_stamp, 'X-AppKey': appkey, 'X-SessionToken': token } conn.request("POST", "/breezeapi/api/v1/margincalculator", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))

Idirect-Tech commented 8 months ago

Dear Rajas,

In expiry date, and in price field the input parameters you are giving for margin calculation are incorrect. Please provide the parameters according to current price of the stock or instrument.

[E29CF836]

Thanks & Regards,

Hiten Solanki,

Team Breeze API,

ICICI Securities


From: Rajas Khokle @.> Sent: Wednesday, November 8, 2023 10:42 AM To: Idirect-Tech/Breeze-Python-SDK @.> Cc: BREEZEAPI @.>; Comment @.> Subject: Re: [Idirect-Tech/Breeze-Python-SDK] Margin Calculator does not work (Issue #47)

External Email Warning: Use 'Report suspicious Email' button to report Phishing mails. Do not click on any attachment or links/URL in this email unless sender is reliable.

It is same as given in the ref doc - except for my session key, secret key and app key

import http.client import json import hashlib conn = http.client.HTTPSConnection("api.icicidirect.com") payload = json.dumps({ "list_of_positions": [ { "strike_price": "0", "quantity": "15", "right": "others", "product": "futures", "action": "buy", "price": "46230.85", "expiry_date": "31-Aug-2023", "stock_code": "CNXBAN", "cover_order_flow": "N", "fresh_order_type": "N", "cover_limit_rate": "0", "cover_sltp_price": "0", "fresh_limit_rate": "0", "open_quantity": "0" }, { "strike_price": "37000", "quantity": "15", "right": "Call", "product": "options", "action": "buy", "price": "9100", "expiry_date": "27-Jul-2023", "stock_code": "CNXBAN", "cover_order_flow": "N", "fresh_order_type": "N", "cover_limit_rate": "0", "cover_sltp_price": "0", "fresh_limit_rate": "0", "open_quantity": "0" }, { "strike_price": "0", "quantity": "50", "right": "others", "product": "futureplus", "action": "buy", "price": "19800", "expiry_date": "27-Jul-2023", "stock_code": "NIFTY", "cover_order_flow": "N", "fresh_order_type": "N", "cover_limit_rate": "0", "cover_sltp_price": "0", "fresh_limit_rate": "0", "open_quantity": "0" }, { "strike_price": "19600", "quantity": "50", "right": "call", "product": "optionplus", "action": "buy", "price": "245.05", "expiry_date": "27-Jul-2023", "stock_code": "NIFTY", "cover_order_flow": "sell", "fresh_order_type": "limit", "cover_limit_rate": "180.00", "cover_sltp_price": "200.00", "fresh_limit_rate": "245.05", "open_quantity": "50" } ], "exchange_code": "NFO" })

checksum computation

time_stamp & checksum generation for request-headers

appkey = app_key secret_key = secret_key time_stamp = dt.datetime.utcnow().isoformat()[:19] + '.000Z' checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest()

headers = { 'Content-Type': 'application/json', 'X-Checksum': 'token ' + checksum, 'X-Timestamp': time_stamp, 'X-AppKey': appkey, 'X-SessionToken': token } conn.request("POST", "/breezeapi/api/v1/margincalculator", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))

— Reply to this email directly, view it on GitHubhttps://github.com/Idirect-Tech/Breeze-Python-SDK/issues/47#issuecomment-1801096923, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3TQZ45745BNSCP4CLJY5XTYDMIDRAVCNFSM6AAAAAA7CF3BPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBRGA4TMOJSGM. You are receiving this because you commented.Message ID: @.***>

Print this mail only if absolutely necessary. Save Paper. Save Trees." "The information contained in this e-mail and any attachments to this message are intended for the exclusive use of the intended recipient and may contain proprietary, confidential or legally privileged information. If you are not the intended recipient, please note that you are not authorised to disseminate, distribute or copy this e-mail or any parts of it or act upon/rely on the contents of this e-mail in any manner. Please notify the sender immediately by e-mail and destroy all copies of this e-mail and any attachments. Please also note that ICICI Bank or its subsidiaries and associated companies, (collectively "ICICI Group"), are unable to exercise control or ensure the integrity of/over the contents of the information contained in e-mail transmissions and that any views expressed in this e-mail are not endorsed by/binding on the ICICI Group unless the sender does so expressly with due authority of ICICI Group. Before opening any attachments please check them for viruses and defects and please note that ICICI Group accepts no liability or responsibility for any damage caused by any virus that may be transmitted by this email. Any unauthorized use of this email or any attachment(s) may be treated as infringement of right(s) including right of privacy under the applicable laws of India including Information and Technology Act, 2000. Thank you for your cooperation. Regulatory Disclosures are available on https://www.icicisecurities.com (for institutional business) and www.icicidirect.com (for retail business).