C++ Kite Connect API library / SDK

Overview

Kite Connect API C++ client

Overview

The official C++ client for communicating with the Kite Connect API.

kitepp is a header only library that wraps around Zerodha's REST API, Websockets saving you the hassle of directly communicating with API and provides an easy to use, modern C++ interface.

Kite Connect is a set of REST-like APIs that expose many capabilities required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (WebSockets), and more, with the simple HTTP API collection.

Dependencies

kitepp has following dependancies:

Getting dependencies

Linux:

  • On Fedora 32: sudo dnf install openssl-devel zlib-devel + (uWS v0.14) + (gtest-devel gmock-devel for running tests)
  • On Ubuntu: sudo apt install libssl-dev zlib1g-dev + (uWS v0.14) + (googletest & googlemock for running tests)

Others & uWS v0.14

kitepp saves you the hassle of finding dependencies and provides convenient cmake target to download source packages as tarballs.

  • To download dependencies (including uWS v0.14): cmake . in deps directory.

Alternatively and preferably, use package managers provided by your OS. Unless your package manager provides v0.14 of uWS, you'll have to build and install it manually.

Building & Installation

kitepp is a header-only C++ library. Just copy the include folder to system or project's include path.

Refer to this repository to see a project using kitepp and a boilerplate CMakeLists.txt to get started.

Build examples and tests:

mkdir build && cd build
cmake .. 
make

Run tests:

make && make test ARGS='-V'

Generate docs:

make docs

Examples

REST API

#include <iostream>
#include <kitepp.hpp>

namespace kc = kiteconnect;

int main() {

    std::cout << "Running..\n";

    try {

        kc::kite Kite("---apikey---");

        std::cout << "Login URL: " << Kite.loginURL() << "\nLogin with this URL and obtain the request token.\n";

        std::string apiSecret;
        std::string reqToken;

        std::cout << "Enter obtained request token: ";
        std::cin >> reqToken;
        std::cout << "Enter API secret: ";
        std::cin >> apiSecret;

        std::string accessToken = Kite.generateSession(reqToken, apiSecret).tokens.accessToken;
        std::cout << "access token is " << accessToken << "\n";

        Kite.setAccessToken(accessToken);

        kc::userProfile profile = Kite.profile();
        std::cout << "email is :" << profile.email << "\n";
        std::cout << "Order types are: \n";
        for (const std::string& type : profile.orderTypes) { std::cout << type << ", "; };

} catch (kc::kiteppException& e) {
    std::cerr << e.what() << ", " << e.code() << ", " << e.message() << "\n";
} catch (kc::libException& e) {
    std::cerr << e.what() << "\n";
}
catch (std::exception& e) {
    std::cerr << e.what() << std::endl;
};
    return 0;
};

Ticker

#include <iostream>
#include "kitepp.hpp"

namespace kc = kiteconnect;

void onConnect(kc::kiteWS* ws) {
    std::cout << "connected.. Subscribing now..\n";
    ws->setMode("full", { 408065, 2953217 });
};

void onTicks(kc::kiteWS* ws, const std::vector<kc::tick>& ticks) {
    for (const auto& i : ticks) {
        std::cout << "instrument token: " << i.instrumentToken << " last price: " << i.lastPrice << "\n";
    };
};

void onError(kc::kiteWS* ws, int code, const std::string& message) {
    std::cout << "Error! Code: " << code << " message: " << message << "\n";
};

void onConnectError(kc::kiteWS* ws) { std::cout << "Couldn't connect..\n"; };

void onClose(kc::kiteWS* ws, int code, const std::string& message) {
    std::cout << "Closed the connection.. code: " << code << " message: " << message << "\n";
};

int main(int argc, char const* argv[]) {

    kc::kiteWS kWS("---APIKEY---", 5, true, 5);

    kWS.setAccessToken("---ACCESSTOKEN---");

    kWS.onConnect = onConnect;
    kWS.onTicks = onTicks;
    kWS.onError = onError;
    kWS.onConnectError = onConnectError;
    kWS.onClose = onClose;

    kWS.connect();

    kWS.run();

    kWS.stop();

    return 0;
};

These and other more extensive examples as well as their cmake build files for reference can be found in the examples directory.

Documentation

License

MIT

Issues
  • Failed to send http/https request (enum code: 10)

    Failed to send http/https request (enum code: 10)

    $ ./example1 Running.. Login URL: https://kite.zerodha.com/connect/login?v=3&api_key=uuuuuuuuuu Login with this URL and obtain the request token. Enter obtained request token: BHUBjVL4o5w5F4kZXfUU5D6q327JqmnG Failed to send http/https request (enum code: 10)

    when trying to run example1 after successfully building it with the make it generates Failed to sent http/https request during runtime. I couldn't figure it out why is it happening and how to fix it.

    I would be thankful if this problem is fixed.

    Thanks in advance : )

    example1.cpp

    /*

    • Licensed under the MIT License http://opensource.org/licenses/MIT.
    • SPDX-License-Identifier: MIT
    • Copyright (c) 2020-2021 Bhumit Attarde
    • Permission is hereby granted, free of charge, to any person obtaining a copy
    • of this software and associated documentation files (the "Software"), to deal
    • in the Software without restriction, including without limitation the rights
    • to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    • copies of the Software, and to permit persons to whom the Software is
    • furnished to do so, subject to the following conditions:
    • The above copyright notice and this permission notice shall be included in all
    • copies or substantial portions of the Software.
    • THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    • IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    • FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    • AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    • LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    • OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    • SOFTWARE. */

    #include #include #include "kitepp.hpp"

    namespace kc = kiteconnect;

    int main() {

    std::cout << "Running..\n";
    
    try {
    
        //kc::kite Kite(std::getenv("KITE_API_KEY"));
         kc::kite Kite("please_enter_api_key");
    
        std::cout << "Login URL: " << Kite.loginURL() << "\nLogin with this URL and obtain the request token.\n";
    
        std::string apiSecret;
        std::string reqToken;
    
        std::cout << "Enter obtained request token: ";
        std::cin >> reqToken;
        
        // std::cout << "Enter API secret: ";
        // std::cin >> apiSecret;
        //apiSecret = std::getenv("KITE_API_SECRET");
    apiSecret="please_enter_apisecret";
    
        std::string accessToken = Kite.generateSession(reqToken, apiSecret).tokens.accessToken;
        std::cout << "access token is " << accessToken << "\n";
    
        Kite.setAccessToken(accessToken);
    
        kc::userProfile profile = Kite.profile();
        std::cout << "email is :" << profile.email << "\n";
        std::cout << "Order types are: \n";
        for (const std::string& type : profile.orderTypes) { std::cout << type << ", "; };
    
        // clang-format off
    

    } catch (kc::kiteppException& e) {

    std::cerr << e.what() << ", " << e.code() << ", " << e.message() << "\n";
    

    } catch (kc::libException& e) {

     std::cerr << e.what() << "\n";
    

    } catch (std::exception& e) {

    std::cerr << e.what() << std::endl;
    

    }; // clang-format on

    return 0;
    

    };

    bug 
    opened by Udesh-Ranjan 20
  • Documentation issues (pre-release)

    Documentation issues (pre-release)

    Opening this thread for collecting any documentation related issues/suggestions before the first release.

    cc @ranjanrak, you can mention the issues you spotted here.

    documentation 
    opened by rhnvrm 9
  • Multiple definition issue in utils.hpp & config.hpp

    Multiple definition issue in utils.hpp & config.hpp

    opened by navkamalrakra 8
  • Thoughts on replacing cpp-httplib with a non-blocking library

    Thoughts on replacing cpp-httplib with a non-blocking library

    opened by rahulswaminathan 5
  • Failed to send http/https request (enum code: 10)

    Failed to send http/https request (enum code: 10)

    Describe the bug I am getting the error code in title when trying to run the example1 given in the directory. I am trying to run the code on AWS lightsail machine. Somehow I dont face this issue when running on my local ubuntu box.

    Unit test output Output of make && make test ARGS='-V' Running tests... Test project /home/ubuntu/cppkiteconnect Start 1: rapidjson-test 1/3 Test #1: rapidjson-test ................... Passed 0.00 sec Start 2: kite-test 2/3 Test #2: kite-test ........................***Failed 0.01 sec Start 3: kiteWS-test 3/3 Test #3: kiteWS-test ......................***Failed 0.01 sec

    33% tests passed, 2 tests failed out of 3

    Total Test time (real) = 0.02 sec

    The following tests FAILED: 2 - kite-test (Failed) 3 - kiteWS-test (Failed) Errors while running CTest make: *** [Makefile:84: test] Error 8

    Machine (please complete the following information):

    • OS: Ubuntu 20.04

    Dependency versions OpenSSL 1.1.1i 8 Dec 2020,

    duplicate question 
    opened by anmolsinghal 4
  • Fix getMFOrdersTest

    Fix getMFOrdersTest

    Ref: #30

    The unit test for getMFOrdersTest failed locally. We need to investigate what is causing the issue.

    2: [ RUN      ] kiteTest.getMFOrdersTest
    2: unknown file: Failure
    2: C++ exception with description "std::exception" thrown in the test body.
    2: [  FAILED  ] kiteTest.getMFOrdersTest (0 ms)
    
    opened by rhnvrm 4
  • refactor: fluent-ish interface for methods with lot of params

    refactor: fluent-ish interface for methods with lot of params

    • methods that used to take a lot of parameters have been refactored to take a single struct argument which has fluent-ish interface
    • segregated response structs into separate files
    • refactored method and struct names so they follow camel case
    • other minor improvements like converting magic numbers to constants and using DEFAULT* constants as default values
    • updated lint and format configs
    opened by bhumitattarde 3
  • cppkiteconnect SDK mock test is getting failed in kiteTest

    cppkiteconnect SDK mock test is getting failed in kiteTest

    I have successfully build the SDK but it fails in kite-test

    Describe the bug Start 2: kite-test

    2: Test command: /home/shubsri93/tradeBot/cppkiteconnect-main/build/tests/kiteTest 2: Test timeout computed to be: 1500 2: Running main() from /home/shubsri93/tradeBot/cppkiteconnect-main/deps/deps/googletest-release-1.10.0/googletest/src/gtest_main.cc 2: [==========] Running 40 tests from 1 test suite. 2: [----------] Global test environment set-up. 2: [----------] 40 tests from kiteTest 2: [ RUN ] kiteTest.constructorTest 2: [ OK ] kiteTest.constructorTest (1 ms) 2: [ RUN ] kiteTest.loginURLTest 2: [ OK ] kiteTest.loginURLTest (0 ms) 2: [ RUN ] kiteTest.generateSessionTest 2: [ OK ] kiteTest.generateSessionTest (1 ms) 2: [ RUN ] kiteTest.invalidateSessionTest 2: [ OK ] kiteTest.invalidateSessionTest (0 ms) 2: [ RUN ] kiteTest.profile 2: /home/shubsri93/tradeBot/cppkiteconnect-main/tests/unit/kitetest.cpp:131: Failure 2: Value of: jsonFile 2: Actual: false 2: Expected: true . . 2: [ FAILED ] kiteTest.getSIPsTest 2: [ FAILED ] kiteTest.getSIPTest 2: [ FAILED ] kiteTest.getOrderMarginsTest 2: [ FAILED ] kiteTest.getInstrumentsTest 2: [ FAILED ] kiteTest.getMFInstrumentsTest 2: 2: 35 FAILED TESTS 2/3 Test #2: kite-test ........................***Failed 0.01 sec

    . . 67% tests passed, 1 tests failed out of 3

    Total Test time (real) = 0.03 sec

    The following tests FAILED: 2 - kite-test (Failed) Errors while running CTest

    To Reproduce make && make test ARGS='-V'

    Machine (please complete the following information):

    • OS: [Linux]
    • Distribution Debian
    opened by shubsri93 3
  • Add macOS CI workflow

    Add macOS CI workflow

    The boilerplate is ready, just need to add install commands like this. I took a crack at this (#35), but couldn't get it right because of not having access to a mac machine.

    enhancement help wanted 
    opened by bhumitattarde 3
  • bug: Switched from uNetworking/uWS to hoytech/uWS

    bug: Switched from uNetworking/uWS to hoytech/uWS

    cmake . in deps will now install https://github.com/hoytech/uWebSockets -- a fork of uWebSockets with some improvements, most important one being an improved Makefile. It installs the library in /usr/local/ and fixes #24.

    Tests pass, but it is important someone tests this live before merging. I'm not subscribed to KiteConnect at the moment.

    bug 
    opened by bhumitattarde 3
  • Discussion: uWebSockets version

    Discussion: uWebSockets version

    Hello, This isn't an issue but a discussion topic (also, if you could enable Discussions in the repo, Issues can be kept only for bug reporting). Just wanted to know if there is a specific reason why specifically v0.14 of uWebSockets is required, which is an archived version in the uWS repo.

    RS

    question 
    opened by rahulswaminathan 2
  • Issue in isValid() function

    Issue in isValid() function

    This happened when I was trying to send a limit order in live market where isValid() returned false for DEFAULTDOUBLE as defined in the project.

    For reproducing the issue checkout https://github.com/kushsharma2910/tmp-cppkiteconnect-bug-check/tree/nullValsComp.

    It seems that use of comparison operator == returns false value. Instead using std::isnan() function of the cmath library gives the correct output.

    Could you please take a look? Maybe I am missing something here.

    I am using c++11 on ubuntu 20.

    opened by kushsharma2910 5
Releases(v1.0.0)
Owner
Zerodha Technology
Zerodha Technology
This repo contains Direct3D 9, Direct3D 10, a few Direct3D 11, and DirectSound C++ samples from the legacy DirectX SDK updated to build using the Windows 10 SDK and the Microsoft.DXSDK.D3DX NuGet package

DirectX SDK Legacy Samples This repo contains Direct3D 9, Direct3D 10, a few Direct3D 11, and DirectSound samples that originally shipped in the legac

Chuck Walbourn 36 Jul 24, 2022
Enabling services on your device 70 Jul 31, 2022
Cross-connect Linux interfaces with XDP

Cross-connect Linux interfaces with XDP redirect xdp-xconnect daemon is a long-running process that uses a YAML file as its configuration API. For exa

Michael Kashin 43 Jul 18, 2022
OceanBase Client for C. A driver to connect applications developed in C language to OceanBase Database.

Oceanbase Client for C OceanBase Client for C is a driver used to connect applications developed in C to OceanBase Database Server. Compatibility Serv

OceanBase 21 Jul 18, 2022
Husarnet is a Peer-to-Peer VPN to connect your laptops, servers and microcontrollers over the Internet with zero configuration.

Husarnet Client Husarnet is a Peer-to-Peer VPN to connect your laptops, servers and microcontrollers over the Internet with zero configuration. Key fe

Husarnet 138 Jul 22, 2022
Linux Terminal Service Manager (LTSM) is a set of service programs that allows remote computers to connect to a Linux operating system computer using a remote terminal session (over VNC or RDP)

Linux Terminal Service Manager (LTSM) is a set of service programs that allows remote computers to connect to a Linux operating system computer using a remote terminal session (over VNC)

null 14 Jan 5, 2022
An implementation of the Mobile Adapter GB protocol, to connect to custom game servers.

libmobile Library that implements the Mobile Adapter GB protocol, in a way that should be easy to integrate into a plethora of different emulators/har

REON Team 9 Jul 6, 2022
Connect to dialup modems over VoIP using SIP, no modem hardware required.

D-Modem Connect to dialup modems over VoIP using SIP, no modem hardware required.

Aon's Cyber Labs 47 Jul 31, 2022
Unofficial Linux client for the Adobe Connect meeting application

Unofficial Adobe Connect Client for Linux Description: Adobe Connect does not have a linux version officially, however, since it's written in flash, i

Mahan Lamee 14 Jun 30, 2022
A forward proxy module for CONNECT request handling

name This module provides support for the CONNECT method request. This method is mainly used to tunnel SSL requests through proxy servers. Table of Co

Xiaochen Wang 1.2k Jul 28, 2022
The Telegram Bot API provides an HTTP API for creating Telegram Bots.

The Telegram Bot API provides an HTTP API for creating Telegram Bots.

Telegram Library 1.7k Aug 6, 2022
Tuya MCU SDK Arduino Library is developed based on the Tuya Wi-Fi general integration solution

Tuya MCU SDK Arduino Library is developed based on the Tuya Wi-Fi general integration solution. The device's MCU is connected to a Wi-Fi module through a serial port to implement a network connection. The development is based on general firmware, which supports the adaptative 9600 and115200 baud rate

Tuya 73 Jun 28, 2022
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket, MQTT built-in protocols, async DNS resolver, and non-blocking API.

Mongoose - Embedded Web Server / Embedded Networking Library Mongoose is a networking library for C/C++. It implements event-driven non-blocking APIs

Cesanta Software 8.6k Jul 29, 2022
A modding SDK that allows you to interact with a modified version of Cocos 2DX v2.2.3 utilized by Geometry Dash

What is CappuccinoSDK CappucinoSDK is a modding utility that allows you to interact with a modified version of the game engine Cocos-2DX v2.2.3, which

null 17 Jul 5, 2022
Good Game, Peace Out Rollback Network SDK

(日本語ドキュメントはこちら) What's GGPO? Traditional techniques account for network transmission time by adding delay to a players input, resulting in a sluggish,

Tony Cannon 2.5k Jul 27, 2022
grey sdk

grey是龙游天下公司的产品"汉末霸业"的一个附属产品。开始是为了解决产品的扩展性,自由度,热更新,视频流播放,用户DIY,3d扩展,人工智能等功能而开发。后来把这些功能集成整理后,从而形成了一个完整的应用级解决方案。 grey是一套应用开发解决方案,使用类似c++的语言(cplus)进行开发。 让

grey-platform 51 Jun 18, 2022
MCUXpresso SDK

Overview MCUXpresso SDK is a comprehensive software enablement package designed to simplify and accelerate application development with Arm® Cortex®-M

NXP Micro 180 Jul 27, 2022
A modding SDK for Hitman 3

ZHM Mod SDK A modding SDK and mod loader for HITMAN 3. Description This is a community-made modding SDK and mod loader for HITMAN 3. Its purpose is to

Orfeas Zafeiris 38 Jul 3, 2022
Tuya IoTOS Embeded SDK WiFi & BLE for BK7231T

Tuya IoTOS Embedded Wi-Fi and BLE SDK for BK7231T 中文版 | English Overview Developed independently by Tuya Smart, Tuya IoTOS is the world's only IoT ope

Tuya 34 Jul 31, 2022