C++ library/SDK for Kite API!

_bhumit
_bhumit edited May 2021 in General
Hi everyone,

You can get the library here: https://github.com/zerodha/cppkiteconnect

Feel free to offer suggestions or to report issues! Opening issues in linked GitHub repo would be the preferred way.
  • brijesin
    trying to build it but getting error. any suggestion?
    https://github.com/zerodha/cppkiteconnect
    *******
    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    Please set them or make sure they are set and tested correctly in the CMake files:
    used as include directory in directory
    cppkiteconnect/examples/example3
    cppkiteconnect/examples/example4/UWS_INCLUDE

    used as include directory in directory cppkiteconnect/examples/example4
    cppkiteconnect/tests/UWS_INCLUDE
    used as include directory in directory cppkiteconnect/tests

    UWS_LIB
    linked by target "example3" in directory cppkiteconnect/examples/example3
    linked by target "example4" in directory cppkiteconnect/examples/example4
    linked by target "kWSTest" in directory cppkiteconnect/tests
  • anonymous
    That most likely means you don't have uWebsockets v0.14 installed or it is installed where cmake cannot find it. README already mentions dependency installation guidelines, but I'll repeat them here under the assumption that you're on Linux.
    Run `cmake .` in `deps` directory. That'll download uWS. After that, unzip and install it. You can just do the standard `make && sudo make install`.
  • brijesin
    Thanks a lot for the help. I found that i needed the exact version of uWebsockets v0.14. That did the trick. it's working now.
  • ak1194
    ak1194 edited March 2021
    note: 'std::thread' is defined in header ''; did you forget to '#include ', using windows
  • ak1194
    note: see reference to function template instantiation 'bool isnan(_Ty) throw()' being compiled
    with
    [
    _Ty=int
    ]
  • tarunmi
    is it faster than Python API? any benchmark done?
  • brijesin
    _bhumit@ and team,

    How do we know that last trade was buy or sell?

    i printed this in my code but did not get the clear picture.
    eq:972545 lprice:267.45 lastTradeno:50 totalbuyno:101130 totalsellno:100737

    looked into following code kitews.hpp but it's not clear here. Looks like i have to do further calculations to figure out about last trade was buy or sell?


    Tick.mode = (packetSize == 44) ? MODE_QUOTE : MODE_FULL;
    Tick.lastPrice = _getNum(packet, 4, 7) / divisor;
    Tick.lastTradedQuantity = _getNum(packet, 8, 11);
    Tick.averageTradePrice = _getNum(packet, 12, 15) / divisor;
    Tick.volumeTraded = _getNum(packet, 16, 19);
    Tick.totalBuyQuantity = _getNum(packet, 20, 23);
    Tick.totalSellQuantity = _getNum(packet, 24, 27);
    Tick.OHLC.open = _getNum(packet, 28, 31) / divisor;
    Tick.OHLC.high = _getNum(packet, 32, 35) / divisor;
    Tick.OHLC.low = _getNum(packet, 36, 39) / divisor;
    Tick.OHLC.close = _getNum(packet, 40, 43) / divisor;
  • sujith
    @brijesin,
    A trade can only happen if there is both buyer and seller. So there is nothing like buy trade and sell trade.
    @tarunmi,
    There is no much computation involved, all the Kite Connect libraries are just the wrapper on top of the HTTP APIs.
  • brijesin
    thank you @sujith for kind response. i was referring kite chart where i can see volume trades(in bar) in green and red. I refer this as last buy and sell(sorry not able to attach picture here). i needed this information for my trade.

  • brijesin
    @sujith kindly check the picture. the volume trade shows red(sell) and green(buy). is it possible to get this information via api?
  • brijesin
    brijesin edited March 2021

    Tick.volumeTraded = _getNum(packet, 16, 19);
    Tick.totalBuyQuantity = _getNum(packet, 20, 23);
    Tick.totalSellQuantity = _getNum(packet, 24, 27);

    e.g. the above variables give me
    volumeTraded:50
    totalBuyQuantity:101130
    totalSellQuantity:100737

    But i don't know if it was sell or buy until i keep a counter again to store previous tBQ and tSQ.
  • sujith
    @brijesin Please create a new thread, it will help people who have the same query. Otherwise, this comment gets hidden and this thread will be hijacked.
  • brijesin
    Thanks Sujith. i'll do that and share the thread.
  • unalome
    unalome edited March 2021
    I've installed uwebsocket and openssl from deps, still getting this error while running 'cmake ..' inside build.

    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    Please set them or make sure they are set and tested correctly in the CMake files:
    UWS_LIB
    linked by target "example1" in directory ...
    linked by target "example2" in directory ...
    linked by target "example3" in directory ...
    linked by target "example4" in directory ...
    linked by target "kWSTest" in directory ...

    -- Configuring incomplete, errors occurred!

    Can Someone help me out with the same? @anonymous @brijesin
  • _bhumit
    @unalome Are you sure you've installed uwebsockets? That error means cmake cannot find it. What OS/distro are you on? Where is uwebsockets installed? Can you share the output of make install if you're on linux?
    Finally, but most importantly, are you positive you have version 0.14 of uwebsockets? I think it's this. Use deps install command provided and install the package that gets downloaded in deps folder.
  • unalome
    Yes, I've installed uwebsocket, the location is /cppkiteconnect/deps/deps/uWebSockets-0.14.8. I'm using pop-os 20.04, inside cppkiteconnect/deps/deps/uWebSockets-0.14.8, I tried running make and got output
    ***
    make `(uname -s)`
    make[1]: Entering directory '/home/unalome/arque/cppkiteconnect/deps/deps/uWebSockets-0.14.8'
    g++ -std=c++11 -O3 -I src -shared -fPIC src/Extensions.cpp src/Group.cpp src/Networking.cpp src/Hub.cpp src/Node.cpp src/WebSocket.cpp src/HTTPSocket.cpp src/Socket.cpp src/Epoll.cpp -s -o libuWS.so
    make[1]: Leaving directory '/home/unalome/arque/cppkiteconnect/deps/deps/uWebSockets-0.14.8'
    ***
    Is there any way to check the version of uwebsocket installed ? (Prior to installing it with deps, I tried using it manually and I believe the version was not correct).
  • _bhumit
    I'm no sure if you can check version of uWS installed. Try running `sudo make install` inside `/cppkiteconnect/deps/deps/uWebSockets-0.14.8`. If you're lucky, `v0.14` provided by deps will replace uWS you have installed.
    That, however, seems unlikely. You'll most likely have to remove your installation of uWS first. Find out where uWS is installed and remove components manually. IIRC, uWS installs `uWS` include folder and a uWS library. Good luck!
  • CleanSlate
    CleanSlate edited April 2021
    I installed all packages from deps, and I end up with the exact error as @unalome. It seems it missed installing UWS_LIB. I checked the cmake file and the path for it is set to not found. I am on Ubuntu 20.04.

    Can you tell the location where UWS_LIB is supposed to be installed so I can check whether it has been and update the cmake file manually?

    Is libuWS.so the UWS_LIB file?

    Update:

    So I found libuWS.so in /usr/lib64. So I set the path for UWS_LIB to /usr/lib64/libuWS.so. I was then able to run make successfully. However on running tests I get the following error (the other two tests were fine),

    Start 3: kiteWS-test

    3: Test command: /home/sourav/cppkiteconnect/build/tests/kWSTest
    3: Test timeout computed to be: 1500
    3: /home/sourav/cppkiteconnect/build/tests/kWSTest: error while loading shared libraries: libuWS.so: cannot open shared object file: No such file or directory
    3/3 Test #3: kiteWS-test ......................***Failed 0.00 sec

    67% tests passed, 1 tests failed out of 3

    Total Test time (real) = 0.02 sec

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

    It might mean that it expects libuWS.so to be located elsewhere.
  • _bhumit
    `usr/lib` is usually the place where `uws.so` is expected to be found. If not there, somewhere in PATH. If you could run `make` successfully, that means that uWS was found (version checking is not supported by CMake for manually installed libraries.). The fact that you got that error while running tests leads me to believe that there is something wrong with your uWS installation. Are you sure it is the version specified? Can you delete local repo and try again, from scratch? Did you try the following command: `make && make test ARGS='-V'`? Is it possible for you to reinstall in the following way:

    All that needs to be done on Ubuntu is, go into `deps/`, run `cmake .`. That'll download uWS. Extract it and then just do the standard `make && sudo make install` in uWS root dir.

    I checked on my Ubuntu LTS box and ^ did the trick.

    One more thing, if you are manually setting the paths, make sure you set it for `tests/CMakeLists.txt` as well.
  • CleanSlate
    @_bhumit Thanks for responding. Following up on your suggestion I was able to clear the tests by editing ../tests/CMakeFiles/kWSTest.dir/link.txt. There the call to libuWS.so was missing, so I added /usr/lib64/libuWS.so.
  • shubsri93
    Hi All,

    I have successfully build the SDK but it fails in kite-test
    Could anyone help me out

    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
  • rakeshr
    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
    Test is failing at this line of unit test. You need to check in mock_response folder, if profile.json file is present or not.
    If still facing the issue, you can raise an issue here on the GitHub page.
  • shubsri93
    @rakeshr thanks for your help, it is working now, In my mock_response there were no files. so I only download all files from github againand now it works. Once again thanks..
    Also I place one cover order successfully
Sign In or Register to comment.