It looks like you're new here. If you want to get involved, click one of these buttons!
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()
[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