public void TestSetAccessToken()
        {
            Kite kite = new Kite("apikey");

            kite.SetAccessToken("access_token");
            Assert.ThrowsException <TokenException>(() => kite.GetPositions());
        }
示例#2
0
 public bool Login(string requestToken)
 {
     try
     {
         RequestToken = requestToken;
         User user = Kite.GenerateSession(requestToken, MySecret);
         MyPublicToken = user.PublicToken;
         MyAccessToken = user.AccessToken;
         Kite.SetAccessToken(MyAccessToken);
         //Kite.GetLTP(new string[] { "NSE:MEGH", "NSE:GTLINFRA" });
         //for (int i = 0; i < 2; i++)
         //{
         //    Kite k = new Kite(MyAPIKey, Debug:true);
         //    RequestToken = requestToken;
         //  //  User user1 = k.GenerateSession(requestToken, MySecret);
         //    k.SetAccessToken(MyAccessToken);
         //    k.GetLTP(new string[] { "NSE:SUBEX","NSE:SBI" });
         //}
         //StartPositionAsync();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#3
0
        public void Initialize(string accessToken)
        {
            Kite = new Kite(apiKey, Debug: false);
            Kite.SetSessionExpiryHook(OnTokenExpire);

            Kite.SetAccessToken(accessToken);
            Ticker = new Ticker(apiKey, accessToken);
        }
示例#4
0
        public Kite GetKite(UserInfo userInfo)
        {
            var kite = new Kite(userInfo.APIKey, Debug: false);

            kite.SetSessionExpiryHook(onTokenExpire);
            Kite.SetAccessToken(MyAccessToken);
            return(kite);
        }
        public User InitializeSession(string requestToken)
        {
            kite = new Kite(_apiKey, Debug: true);

            // For handling 403 errors
            kite.SetSessionExpiryHook(() => { Message = _logger.WriteMessage("Need to login again"); });

            User user = kite.GenerateSession(requestToken, _secretKey);

            Message = _logger.WriteMessage(ConnectConstants.SESSION_INITIALIZED);

            kite.SetAccessToken(user.AccessToken);

            Message = _logger.WriteMessage(ConnectConstants.ACCESSTOKEN_SET);

            return(user);
        }
示例#6
0
        private void webView1_NavigationCompleted(object sender, Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlNavigationCompletedEventArgs e)
        {
            try
            {
                var link = e.Uri.ToString();
                Log.WriteLog("trade-log.txt", "webView1_NavigationCompleted - " + e.Uri.ToString());
                btnLogin.Focus();
                if (link.Contains("request_token"))
                {
                    string[] strSplit = link.Split('?');
                    if (strSplit.Count() == 2)
                    {
                        string[] strSplit2 = strSplit[1].Split('&');
                        foreach (string s in strSplit2)
                        {
                            if (s.Contains("request_token"))
                            {
                                tradeUser.ApiReturnToken = s.Replace("request_token=", "");
                                break;
                            }
                        }
                    }
                    //tradeUser.ApiReturnToken = link.Replace("http://127.0.0.1:8080/?", "").Replace("&action=login&status=success", "").Replace("request_token=", "");

                    // Collect tokens and user details using the request token
                    User user = kite.GenerateSession(tradeUser.ApiReturnToken, tradeUser.ApiSecret);

                    tradeUser.AccessToken = user.AccessToken;
                    tradeUser.PublicToken = user.PublicToken;
                    tradeUser.kiteUser    = user;

                    // Initialize Kite APIs with access token
                    kite.SetAccessToken(tradeUser.AccessToken);
                    tradeUser.kite = kite;
                    HomeForm home = new HomeForm();
                    home.Show();
                    this.Hide();
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog("trade-log.txt", ex.ToString());
                throw ex;
            }
        }
示例#7
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            //log.LogInformation("start"+ DateTime.Now);
            try
            {
                log.LogInformation("C# HTTP trigger function processed a request.");
                kite.SetAccessToken(MyAccessToken);

                List <Historical> previousDaydata = TradeHelpers.CallAPIPreviousDayOHLC(log);

                Dictionary <string, decimal> dataCPR = new Dictionary <string, decimal>();

                if (previousDaydata != null)
                {
                    dataCPR = TradeHelpers.CalculateCPR(previousDaydata, log);
                }
                else
                {
                    log.LogInformation("PreviousDaydata is null");
                }

                if (dataCPR != null)
                {
                    TradeHelpers.ExecuteTrade(dataCPR, log);
                }
                else
                {
                    log.LogInformation("CalculateCPR is null");
                }
            }
            catch (Exception ex)
            {
                log.LogInformation("Exception Main Function- " + ex.Message);
            }
            string responseMessage = "End";

            //log.LogInformation("end" + DateTime.Now);
            return(new OkObjectResult(responseMessage));
        }
示例#8
0
        static void Main(string[] args)
        {
            kite = new Kite(MyAPIKey, Debug: true);

            // For handling 403 errors

            kite.SetSessionHook(onTokenExpire);

            // Initializes the login flow

            try
            {
                initSession();
            }
            catch (Exception e)
            {
                // Cannot continue without proper authentication
                Console.WriteLine(e.Message);
                Console.ReadKey();
                Environment.Exit(0);
            }

            kite.SetAccessToken(MyAccessToken);

            // Initialize ticker

            initTicker();

            // Positions

            PositionResponse positions = kite.GetPositions();

            Console.WriteLine(JsonSerialize(positions.Net[0]));

            kite.ModifyProduct("NSE", "ASHOKLEY", "BUY", "day", "1", "MIS", "CNC");

            // Holdings

            List <Holding> holdings = kite.GetHoldings();

            Console.WriteLine(JsonSerialize(holdings[0]));

            // Instruments

            List <Instrument> instruments = kite.GetInstruments();

            Console.WriteLine(JsonSerialize(instruments[0]));

            // Quote

            Quote quote = kite.GetQuote("NSE", "INFY");

            Console.WriteLine(JsonSerialize(quote));

            // Get OHLC and LTP of upto 200 scrips

            Dictionary <string, OHLC> ohlcs = kite.GetOHLC(new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(JsonSerialize(ohlcs));

            // Get LTP of upto 200 scrips

            Dictionary <string, LTP> ltps = kite.GetLTP(new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(JsonSerialize(ltps));

            // Trigger Range

            TrigerRange triggerRange = kite.GetTriggerRange("NSE", "INFY", "BUY");

            Console.WriteLine(JsonSerialize(triggerRange));

            // Orders

            List <Order> orders = kite.GetOrders();

            Console.WriteLine(JsonSerialize(orders[0]));

            Dictionary <string, dynamic> response = kite.PlaceOrder("CDS", "USDINR17AUGFUT", "SELL", "1", Price: "64.0000", OrderType: "MARKET", Product: "NRML");

            Console.WriteLine("Order Id: " + response["data"]["order_id"]);

            kite.PlaceOrder("CDS", "USDINR17AUGFUT", "BUY", "1", Price: "63.9000", OrderType: "LIMIT", Product: "NRML");
            kite.CancelOrder("1234");

            List <OrderInfo> orderinfo = kite.GetOrder("1234");

            Console.WriteLine(JsonSerialize(orderinfo[0]));


            //BO LIMIT order placing

            kite.PlaceOrder("NSE", "ASHOKLEY", "BUY", Quantity: "1", Price: "115", Product: "MIS", OrderType: "LIMIT", Validity: "DAY", SquareOffValue: "2", StoplossValue: "2", Variety: "bo");

            // BO LIMIT exiting

            kite.CancelOrder("1234", "bo", "5678"); // 1234 is order id and 5678 is parent order id

            // BO SL order placing

            kite.PlaceOrder("NSE", "ASHOKLEY", "BUY", Quantity: "1", Price: "117", Product: "MIS", OrderType: "SL", Validity: "DAY", SquareOffValue: "2", StoplossValue: "2", TriggerPrice: "117.5", Variety: "bo");

            // BO SL exiting

            kite.CancelOrder("1234", "bo", "5678"); // 1234 is order id and 5678 is parent order id

            // CO LIMIT order placing

            kite.PlaceOrder("NSE", "ASHOKLEY", "BUY", Quantity: "1", Price: "115.5", Product: "MIS", OrderType: "LIMIT", Validity: "DAY", TriggerPrice: "116.5", Variety: "co");

            // CO LIMIT exiting

            kite.CancelOrder("1234", "co", "5678"); // 1234 is order id and 5678 is parent order id

            // CO MARKET order placing

            kite.PlaceOrder("NSE", "ASHOKLEY", "BUY", Quantity: "1", Product: "MIS", OrderType: "MARKET", Validity: "DAY", TriggerPrice: "116.5", Variety: "co");

            // CO MARKET exiting

            kite.CancelOrder("1234", "co", "5678"); // 1234 is order id and 5678 is parent order id

            // Trades

            List <Trade> trades = kite.GetTrades("1234");

            Console.WriteLine(JsonSerialize(trades[0]));

            // Margins

            kite.Margins("commodity");
            kite.Margins("equity");

            // Historical Data With Dates

            List <Historical> historical = kite.GetHistorical("5633", "2015-12-28", "2016-01-01", "minute");

            Console.WriteLine(JsonSerialize(historical[0]));

            // Historical Data With Timestamps

            List <Historical> historical_timestamp = kite.GetHistorical("5633", "2016-01-01 11:00:00", "2016-01-01 11:10:00", "minute");

            Console.WriteLine(JsonSerialize(historical_timestamp[0]));

            // Continuous Historical Data

            List <Historical> historical_continuous = kite.GetHistorical("5633", "2015-12-28", "2016-01-01", "minute", Continuous: true);

            Console.WriteLine(JsonSerialize(historical_continuous[0]));

            // Mutual Funds Instruments

            List <MFInstrument> mfinstruments = kite.GetMFInstruments();

            Console.WriteLine(JsonSerialize(mfinstruments[0]));

            // Mutual Funds Orders

            List <MFOrder> mforders = kite.GetMFOrders();

            Console.WriteLine(JsonSerialize(mforders[0]));

            MFOrder mforder = kite.GetMFOrder("1234");

            Console.WriteLine(JsonSerialize(mforder));

            kite.PlaceMFOrder("INF174K01LS2", "BUY", "20000");

            kite.CancelMFOrder("1234");

            // Mutual Funds SIPs

            List <MFSIP> mfsips = kite.GetMFSIPs();

            Console.WriteLine(JsonSerialize(mfsips[0]));

            MFSIP sip = kite.GetMFSIP("63429");

            Console.WriteLine(JsonSerialize(sip));

            kite.PlaceMFSIP("INF174K01LS2", "1000", "5000", "monthly", "1", "-1");

            kite.ModifyMFSIP("1234", "1000", "monthly", "1", "10", "paused");

            kite.CancelMFSIP("1234");

            // Mutual Funds Holdings

            List <MFHolding> mfholdings = kite.GetMFHoldings();

            Console.WriteLine(JsonSerialize(mfholdings[0]));

            Console.ReadKey();

            // Disconnect from ticker

            ticker.Close();
        }
示例#9
0
        static void Main(string[] args)
        {
            kite = new Kite(MyAPIKey, Debug: true);

            // For handling 403 errors

            kite.SetSessionExpiryHook(OnTokenExpire);

            // Initializes the login flow

            try
            {
                initSession();
            }
            catch (Exception e)
            {
                // Cannot continue without proper authentication
                Console.WriteLine(e.Message);
                Console.ReadKey();
                Environment.Exit(0);
            }

            kite.SetAccessToken(MyAccessToken);

            // Initialize ticker

            initTicker();

            // Get all GTTs

            List <GTT> gtts = kite.GetGTTs();

            Console.WriteLine(Utils.JsonSerialize(gtts[0]));

            // Get GTT by Id

            GTT gtt = kite.GetGTT(99691);

            Console.WriteLine(Utils.JsonSerialize(gtt));

            // Cacncel GTT by Id

            var gttCancelResponse = kite.CancelGTT(1582);

            Console.WriteLine(Utils.JsonSerialize(gttCancelResponse));

            // Place GTT

            GTTParams gttParams = new GTTParams();

            gttParams.TriggerType   = Constants.GTT_TRIGGER_OCO;
            gttParams.Exchange      = "NSE";
            gttParams.TradingSymbol = "SBIN";
            gttParams.LastPrice     = 288.9m;

            List <decimal> triggerPrices = new List <decimal>();

            triggerPrices.Add(260m);
            triggerPrices.Add(320m);
            gttParams.TriggerPrices = triggerPrices;

            // Only sell is allowed for OCO or two-leg orders.
            // Single leg orders can be buy or sell order.
            // Passing a last price is mandatory.
            // A stop-loss order must have trigger and price below last price and target order must have trigger and price above last price.
            // Only limit order type  and CNC product type is allowed for now.

            GTTOrderParams order1Params = new GTTOrderParams();

            order1Params.OrderType       = Constants.ORDER_TYPE_LIMIT;
            order1Params.Price           = 250m;
            order1Params.Product         = Constants.PRODUCT_CNC;
            order1Params.TransactionType = Constants.TRANSACTION_TYPE_SELL;
            order1Params.Quantity        = 0;

            GTTOrderParams order2Params = new GTTOrderParams();

            order2Params.OrderType       = Constants.ORDER_TYPE_LIMIT;
            order2Params.Price           = 320m;
            order2Params.Product         = Constants.PRODUCT_CNC;
            order2Params.TransactionType = Constants.TRANSACTION_TYPE_SELL;
            order2Params.Quantity        = 1;

            // Target or upper trigger
            List <GTTOrderParams> ordersList = new List <GTTOrderParams>();

            ordersList.Add(order1Params);
            ordersList.Add(order2Params);
            gttParams.Orders = ordersList;

            var placeGTTResponse = kite.PlaceGTT(gttParams);

            Console.WriteLine(Utils.JsonSerialize(placeGTTResponse));

            var modifyGTTResponse = kite.ModifyGTT(407301, gttParams);

            Console.WriteLine(Utils.JsonSerialize(modifyGTTResponse));

            // Positions

            PositionResponse positions = kite.GetPositions();

            Console.WriteLine(Utils.JsonSerialize(positions.Net[0]));

            kite.ConvertPosition(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                PositionType: Constants.POSITION_DAY,
                Quantity: 1,
                OldProduct: Constants.PRODUCT_MIS,
                NewProduct: Constants.PRODUCT_CNC
                );

            // Holdings

            List <Holding> holdings = kite.GetHoldings();

            Console.WriteLine(Utils.JsonSerialize(holdings[0]));

            // Instruments

            List <Instrument> instruments = kite.GetInstruments();

            Console.WriteLine(Utils.JsonSerialize(instruments[0]));

            // Get quotes of upto 200 scrips

            Dictionary <string, Quote> quotes = kite.GetQuote(InstrumentId: new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(Utils.JsonSerialize(quotes));

            // Get OHLC and LTP of upto 200 scrips

            Dictionary <string, OHLC> ohlcs = kite.GetOHLC(InstrumentId: new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(Utils.JsonSerialize(ohlcs));

            // Get LTP of upto 200 scrips

            Dictionary <string, LTP> ltps = kite.GetLTP(InstrumentId: new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(Utils.JsonSerialize(ltps));

            // Trigger Range

            Dictionary <string, TrigerRange> triggerRange = kite.GetTriggerRange(
                InstrumentId: new string[] { "NSE:ASHOKLEY" },
                TrasactionType: Constants.TRANSACTION_TYPE_BUY
                );

            Console.WriteLine(Utils.JsonSerialize(triggerRange));

            // Get all orders

            List <Order> orders = kite.GetOrders();

            Console.WriteLine(Utils.JsonSerialize(orders[0]));

            // Get order by id

            List <Order> orderinfo = kite.GetOrderHistory("1234");

            Console.WriteLine(Utils.JsonSerialize(orderinfo[0]));

            // Place sell order

            Dictionary <string, dynamic> response = kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_CDS,
                TradingSymbol: "USDINR17AUGFUT",
                TransactionType: Constants.TRANSACTION_TYPE_SELL,
                Quantity: 1,
                Price: 64.0000m,
                OrderType: Constants.ORDER_TYPE_MARKET,
                Product: Constants.PRODUCT_MIS
                );

            Console.WriteLine("Order Id: " + response["data"]["order_id"]);

            // Place buy order

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_CDS,
                TradingSymbol: "USDINR17AUGFUT",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 63.9000m,
                OrderType: Constants.ORDER_TYPE_LIMIT,
                Product: Constants.PRODUCT_MIS
                );

            // Cancel order by id

            kite.CancelOrder("1234");

            //BO LIMIT order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 115,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_LIMIT,
                Validity: Constants.VALIDITY_DAY,
                SquareOffValue: 2,
                StoplossValue: 2,
                Variety: Constants.VARIETY_BO
                );

            // BO LIMIT exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // BO SL order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 117,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_SL,
                Validity: Constants.VALIDITY_DAY,
                SquareOffValue: 2,
                StoplossValue: 2,
                TriggerPrice: 117.5m,
                Variety: Constants.VARIETY_BO
                );

            // BO SL exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // CO LIMIT order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 115.5m,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_LIMIT,
                Validity: Constants.VALIDITY_DAY,
                TriggerPrice: 116.5m,
                Variety: Constants.VARIETY_CO
                );

            // CO LIMIT exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // CO MARKET order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_MARKET,
                Validity: Constants.VALIDITY_DAY,
                TriggerPrice: 116.5m,
                Variety: Constants.VARIETY_CO
                );

            // CO MARKET exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // Trades

            List <Trade> trades = kite.GetOrderTrades("1234");

            Console.WriteLine(Utils.JsonSerialize(trades[0]));

            // Margins

            UserMargin commodityMargins = kite.GetMargins(Constants.MARGIN_COMMODITY);
            UserMargin equityMargins    = kite.GetMargins(Constants.MARGIN_EQUITY);

            // Order margins

            OrderMarginParams orderParam = new OrderMarginParams();

            orderParam.Exchange        = Constants.EXCHANGE_NFO;
            orderParam.TradingSymbol   = "ASHOKLEY21JULFUT";
            orderParam.TransactionType = Constants.TRANSACTION_TYPE_SELL;
            orderParam.Quantity        = 1;
            orderParam.Price           = 64.0000m;
            orderParam.OrderType       = Constants.ORDER_TYPE_MARKET;
            orderParam.Product         = Constants.PRODUCT_MIS;

            List <OrderMargin> margins = kite.GetOrderMargins(new List <OrderMarginParams>()
            {
                orderParam
            });

            // Basket margins

            OrderMarginParams basketParam = new OrderMarginParams();

            basketParam.Exchange        = Constants.EXCHANGE_NFO;
            basketParam.TradingSymbol   = "NIFTY21JUL15000PE";
            basketParam.TransactionType = Constants.TRANSACTION_TYPE_BUY;
            basketParam.Quantity        = 75;
            basketParam.Price           = 300;
            basketParam.Product         = Constants.PRODUCT_MIS;
            basketParam.OrderType       = Constants.ORDER_TYPE_LIMIT;

            BasketMargin basketMargins = kite.GetBasketMargins(new List <OrderMarginParams>()
            {
                basketParam
            }, ConsiderPositions: true);

            // Historical Data With Dates

            List <Historical> historical = kite.GetHistoricalData(
                InstrumentToken: "5633",
                FromDate: new DateTime(2016, 1, 1, 12, 50, 0),  // 2016-01-01 12:50:00 AM
                ToDate: new DateTime(2016, 1, 1, 13, 10, 0),    // 2016-01-01 01:10:00 PM
                Interval: Constants.INTERVAL_MINUTE,
                Continuous: false
                );

            Console.WriteLine(Utils.JsonSerialize(historical[0]));

            // Mutual Funds Instruments

            List <MFInstrument> mfinstruments = kite.GetMFInstruments();

            Console.WriteLine(Utils.JsonSerialize(mfinstruments[0]));

            // Mutual funds get all orders

            List <MFOrder> mforders = kite.GetMFOrders();

            Console.WriteLine(Utils.JsonSerialize(mforders[0]));

            // Mutual funds get order by id

            MFOrder mforder = kite.GetMFOrders(OrderId: "1234");

            Console.WriteLine(Utils.JsonSerialize(mforder));

            // Mutual funds place order

            kite.PlaceMFOrder(
                TradingSymbol: "INF174K01LS2",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Amount: 20000
                );

            // Mutual funds cancel order by id

            kite.CancelMFOrder(OrderId: "1234");

            // Mutual Funds get all SIPs

            List <MFSIP> mfsips = kite.GetMFSIPs();

            Console.WriteLine(Utils.JsonSerialize(mfsips[0]));

            // Mutual Funds get SIP by id

            MFSIP sip = kite.GetMFSIPs("63429");

            Console.WriteLine(Utils.JsonSerialize(sip));

            // Mutual Funds place SIP order

            kite.PlaceMFSIP(
                TradingSymbol: "INF174K01LS2",
                Amount: 1000,
                InitialAmount: 5000,
                Frequency: "monthly",
                InstalmentDay: 1,
                Instalments: -1 // -1 means infinite
                );

            // Mutual Funds modify SIP order

            kite.ModifyMFSIP(
                SIPId: "1234",
                Amount: 1000,
                Frequency: "monthly",
                InstalmentDay: 1,
                Instalments: 10,
                Status: "paused"
                );

            kite.CancelMFSIP(SIPId: "1234");

            // Mutual Funds Holdings

            List <MFHolding> mfholdings = kite.GetMFHoldings();

            Console.WriteLine(Utils.JsonSerialize(mfholdings[0]));

            Console.ReadKey();

            // Disconnect from ticker

            ticker.Close();
        }
示例#10
0
        static void Main(string[] args)
        {
            kite = new Kite(MyAPIKey, Debug: true);

            // For handling 403 errors

            kite.SetSessionExpiryHook(OnTokenExpire);

            // Initializes the login flow

            try
            {
                initSession();
            }
            catch (Exception e)
            {
                // Cannot continue without proper authentication
                Console.WriteLine(e.Message);
                Console.ReadKey();
                Environment.Exit(0);
            }

            kite.SetAccessToken(MyAccessToken);

            // Initialize ticker

            initTicker();

            // Positions

            PositionResponse positions = kite.GetPositions();

            Console.WriteLine(Utils.JsonSerialize(positions.Net[0]));

            kite.ConvertPosition(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                PositionType: Constants.POSITION_DAY,
                Quantity: 1,
                OldProduct: Constants.PRODUCT_MIS,
                NewProduct: Constants.PRODUCT_CNC
                );

            // Holdings

            List <Holding> holdings = kite.GetHoldings();

            Console.WriteLine(Utils.JsonSerialize(holdings[0]));

            // Instruments

            List <Instrument> instruments = kite.GetInstruments();

            Console.WriteLine(Utils.JsonSerialize(instruments[0]));

            // Get quotes of upto 200 scrips

            Dictionary <string, Quote> quotes = kite.GetQuote(InstrumentId: new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(Utils.JsonSerialize(quotes));

            // Get OHLC and LTP of upto 200 scrips

            Dictionary <string, OHLC> ohlcs = kite.GetOHLC(InstrumentId: new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(Utils.JsonSerialize(ohlcs));

            // Get LTP of upto 200 scrips

            Dictionary <string, LTP> ltps = kite.GetLTP(InstrumentId: new string[] { "NSE:INFY", "NSE:ASHOKLEY" });

            Console.WriteLine(Utils.JsonSerialize(ltps));

            // Trigger Range

            Dictionary <string, TrigerRange> triggerRange = kite.GetTriggerRange(
                InstrumentId: new string[] { "NSE:ASHOKLEY" },
                TrasactionType: Constants.TRANSACTION_TYPE_BUY
                );

            Console.WriteLine(Utils.JsonSerialize(triggerRange));

            // Get all orders

            List <Order> orders = kite.GetOrders();

            Console.WriteLine(Utils.JsonSerialize(orders[0]));

            // Get order by id

            List <Order> orderinfo = kite.GetOrderHistory("1234");

            Console.WriteLine(Utils.JsonSerialize(orderinfo[0]));

            // Place sell order

            Dictionary <string, dynamic> response = kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_CDS,
                TradingSymbol: "USDINR17AUGFUT",
                TransactionType: Constants.TRANSACTION_TYPE_SELL,
                Quantity: 1,
                Price: 64.0000m,
                OrderType: Constants.ORDER_TYPE_MARKET,
                Product: Constants.PRODUCT_MIS
                );

            Console.WriteLine("Order Id: " + response["data"]["order_id"]);

            // Place buy order

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_CDS,
                TradingSymbol: "USDINR17AUGFUT",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 63.9000m,
                OrderType: Constants.ORDER_TYPE_LIMIT,
                Product: Constants.PRODUCT_MIS
                );

            // Cancel order by id

            kite.CancelOrder("1234");

            //BO LIMIT order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 115,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_LIMIT,
                Validity: Constants.VALIDITY_DAY,
                SquareOffValue: 2,
                StoplossValue: 2,
                Variety: Constants.VARIETY_BO
                );

            // BO LIMIT exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // BO SL order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 117,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_SL,
                Validity: Constants.VALIDITY_DAY,
                SquareOffValue: 2,
                StoplossValue: 2,
                TriggerPrice: 117.5m,
                Variety: Constants.VARIETY_BO
                );

            // BO SL exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // CO LIMIT order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Price: 115.5m,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_LIMIT,
                Validity: Constants.VALIDITY_DAY,
                TriggerPrice: 116.5m,
                Variety: Constants.VARIETY_CO
                );

            // CO LIMIT exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // CO MARKET order placing

            kite.PlaceOrder(
                Exchange: Constants.EXCHANGE_NSE,
                TradingSymbol: "ASHOKLEY",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Quantity: 1,
                Product: Constants.PRODUCT_MIS,
                OrderType: Constants.ORDER_TYPE_MARKET,
                Validity: Constants.VALIDITY_DAY,
                TriggerPrice: 116.5m,
                Variety: Constants.VARIETY_CO
                );

            // CO MARKET exiting

            kite.CancelOrder(
                OrderId: "1234",
                Variety: Constants.VARIETY_BO,
                ParentOrderId: "5678"
                );

            // Trades

            List <Trade> trades = kite.GetOrderTrades("1234");

            Console.WriteLine(Utils.JsonSerialize(trades[0]));

            // Margins

            UserMargin commodityMargins = kite.GetMargins(Constants.MARGIN_COMMODITY);
            UserMargin equityMargins    = kite.GetMargins(Constants.MARGIN_EQUITY);

            // Historical Data With Dates

            List <Historical> historical = kite.GetHistoricalData(
                InstrumentToken: "5633",
                FromDate: new DateTime(2016, 1, 1, 12, 50, 0),  // 2016-01-01 12:50:00 AM
                ToDate: new DateTime(2016, 1, 1, 13, 10, 0),    // 2016-01-01 01:10:00 PM
                Interval: Constants.INTERVAL_MINUTE,
                Continuous: false
                );

            Console.WriteLine(Utils.JsonSerialize(historical[0]));

            // Mutual Funds Instruments

            List <MFInstrument> mfinstruments = kite.GetMFInstruments();

            Console.WriteLine(Utils.JsonSerialize(mfinstruments[0]));

            // Mutual funds get all orders

            List <MFOrder> mforders = kite.GetMFOrders();

            Console.WriteLine(Utils.JsonSerialize(mforders[0]));

            // Mutual funds get order by id

            MFOrder mforder = kite.GetMFOrders(OrderId: "1234");

            Console.WriteLine(Utils.JsonSerialize(mforder));

            // Mutual funds place order

            kite.PlaceMFOrder(
                TradingSymbol: "INF174K01LS2",
                TransactionType: Constants.TRANSACTION_TYPE_BUY,
                Amount: 20000
                );

            // Mutual funds cancel order by id

            kite.CancelMFOrder(OrderId: "1234");

            // Mutual Funds get all SIPs

            List <MFSIP> mfsips = kite.GetMFSIPs();

            Console.WriteLine(Utils.JsonSerialize(mfsips[0]));

            // Mutual Funds get SIP by id

            MFSIP sip = kite.GetMFSIPs("63429");

            Console.WriteLine(Utils.JsonSerialize(sip));

            // Mutual Funds place SIP order

            kite.PlaceMFSIP(
                TradingSymbol: "INF174K01LS2",
                Amount: 1000,
                InitialAmount: 5000,
                Frequency: "monthly",
                InstalmentDay: 1,
                Instalments: -1 // -1 means infinite
                );

            // Mutual Funds modify SIP order

            kite.ModifyMFSIP(
                SIPId: "1234",
                Amount: 1000,
                Frequency: "monthly",
                InstalmentDay: 1,
                Instalments: 10,
                Status: "paused"
                );

            kite.CancelMFSIP(SIPId: "1234");

            // Mutual Funds Holdings

            List <MFHolding> mfholdings = kite.GetMFHoldings();

            Console.WriteLine(Utils.JsonSerialize(mfholdings[0]));

            Console.ReadKey();

            // Disconnect from ticker

            ticker.Close();
        }