kiteconnect python api

Solutions on MaxInterview for kiteconnect python api by the best coders in the world

showing results for - "kiteconnect python api"
Felipe
23 Nov 2017
1import logging
2from kiteconnect import KiteConnect
3
4logging.basicConfig(level=logging.DEBUG)
5
6kite = KiteConnect(api_key="your_api_key")
7
8# Redirect the user to the login url obtained
9# from kite.login_url(), and receive the request_token
10# from the registered redirect url after the login flow.
11# Once you have the request_token, obtain the access_token
12# as follows.
13
14data = kite.generate_session("request_token_here", api_secret="your_secret")
15kite.set_access_token(data["access_token"])
16
17######################## USE TILL HERE TO AUTHENTICATE KITE ########################
18
19# Place an order
20try:
21    order_id = kite.place_order(tradingsymbol="INFY",
22                                exchange=kite.EXCHANGE_NSE,
23                                transaction_type=kite.TRANSACTION_TYPE_BUY,
24                                quantity=1,
25                                order_type=kite.ORDER_TYPE_MARKET,
26                                product=kite.PRODUCT_NRML)
27
28    logging.info("Order placed. ID is: {}".format(order_id))
29except Exception as e:
30    logging.info("Order placement failed: {}".format(e.message))
31
32# Fetch all orders
33kite.orders()
34
35# Get instruments
36kite.instruments()
37
38# Place an mutual fund order
39kite.place_mf_order(
40    tradingsymbol="INF090I01239",
41    transaction_type=kite.TRANSACTION_TYPE_BUY,
42    amount=5000,
43    tag="mytag"
44)
45
46# Cancel a mutual fund order
47kite.cancel_mf_order(order_id="order_id")
48
49# Get mutual fund instruments
50kite.mf_instruments()