Keep getting "Starting new HTTPS connection (1): api.kite.trade:443" every time before any api call

koolstar
Hi,
I was trying the python client code provided on github and found that in my case it is making a call to _new_conn() before every api call. Is it correct behavior? Or am I missing something? This call is taking 100-300ms every time and thus makes the overall order placement slow particularly when multiple orders are being placed in quick succession.

Client version: python kiteconnect 4.1.0

Code:

 def zerodha_order():
api_key, api_secret = get_api_secrets()
access_token = get_access_token()
kite = KiteConnect(api_key=api_key)
kite.set_access_token(access_token)

try:
instruments = ['NFO:NIFTY22N0317500PE', 'NFO:NIFTY22N0318500PE']
ltp = kite.ltp(instruments)
pos = kite.positions()
except Exception as e:
logging.info("Query failed: {}".format(str(e)))

# Place an order
order_id = 0
try:
order_id = kite.place_order(tradingsymbol="INFY",
exchange=kite.EXCHANGE_NSE,
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=1,
variety=kite.VARIETY_AMO,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_CNC,
validity=kite.VALIDITY_DAY)

logging.info("Order placed. ID is: {}".format(order_id))
except Exception as e:
logging.info("Order placement failed: {}".format(str(e)))
return order_id

if __name__=="__main__":
zerodha_order()

Debug log:

[2022-11-25 08:31:25.255][DEBUG][29756][connectionpool:1003 - _new_conn()] Starting new HTTPS connection (1): api.kite.trade:443
[2022-11-25 08:31:25.409][DEBUG][29756][connectionpool:456 - _make_request()] https://api.kite.trade:443 "GET /quote/ltp?i=NFO%3ANIFTY22N0317500PE&i=NFO%3ANIFTY22N0318500PE HTTP/1.1" 200 30
[2022-11-25 08:31:25.445][DEBUG][29756][connectionpool:1003 - _new_conn()] Starting new HTTPS connection (1): api.kite.trade:443
[2022-11-25 08:31:25.580][DEBUG][29756][connectionpool:456 - _make_request()] https://api.kite.trade:443 "GET /portfolio/positions HTTP/1.1" 200 None
[2022-11-25 08:31:25.605][DEBUG][29756][connectionpool:1003 - _new_conn()] Starting new HTTPS connection (1): api.kite.trade:443
[2022-11-25 08:31:25.779][DEBUG][29756][connectionpool:456 - _make_request()] https://api.kite.trade:443 "POST /orders/amo HTTP/1.1" 200 None
[2022-11-25 08:31:25.794][INFO][29756][test_zerodha:65 - zerodha_order()] Order placed. ID is: 221125200012238
  • rakeshr
    We are checking on this. Meanwhile, you can use a pool connection to avoid this:
    pool_value = {"pool_connections": 10, "pool_maxsize": 10,
    "max_retries": 0, "pool_block": False}
    kite = KiteConnect(...., pool=pool_value)
Sign In or Register to comment.