30 #include <unordered_map>
33 #include "cpp-httplib/httplib.h"
35 #include "responses/responses.hpp"
38 namespace kiteconnect {
41 namespace kc = kiteconnect;
42 namespace utils = kc::internal::utils;
56 explicit kite(
string apikey);
114 const string& requestToken,
const string& apiSecret);
224 string cancelOrder(
const string& variety,
const string& orderId,
237 const string& parentOrderId =
"");
247 std::vector<order>
orders();
269 std::vector<trade>
trades();
281 std::vector<trade>
orderTrades(
const string& orderId);
392 std::vector<instrument>
getInstruments(
const string& exchange =
"");
409 std::unordered_map<string, quote>
getQuote(
410 const std::vector<string>& symbols);
427 std::unordered_map<string, ohlcQuote>
getOhlc(
428 const std::vector<string>& symbols);
445 std::unordered_map<string, ltpQuote>
getLtp(
446 const std::vector<string>& symbols);
601 const std::vector<marginsParams>& params);
616 const std::vector<marginsParams>& params,
bool considerPositions);
619 static string encodeSymbolsList(
const std::vector<string>& symbols);
621 string getAuth()
const;
623 template <
class Res,
class Data,
bool UseCustomParser = false>
624 inline Res callApi(
const string& service,
625 const utils::http::Params& body = {},
626 const utils::FmtArgs& fmtArgs = {},
627 utils::json::CustomParser<Res, Data, UseCustomParser>
630 const string version =
"3";
631 const string root =
"https://api.kite.trade";
632 const string loginUrlFmt =
633 "https://kite.zerodha.com/connect/login?v=3&api_key={api_key}";
634 const std::unordered_map<string, utils::http::endpoint> endpoints {
636 {
"api.token", { utils::http::METHOD::POST,
"/session/token" } },
637 {
"api.token.invalidate",
638 { utils::http::METHOD::DEL,
639 "/session/token?api_key={0}&access_token={1}" } },
641 {
"user.profile", { utils::http::METHOD::GET,
"/user/profile" } },
642 {
"user.margins", { utils::http::METHOD::GET,
"/user/margins" } },
643 {
"user.margins.segment",
644 { utils::http::METHOD::GET,
"/user/margins/{0}" } },
646 {
"order.info", { utils::http::METHOD::GET,
"/orders/{0}" } },
647 {
"order.place", { utils::http::METHOD::POST,
"/orders/{0}" } },
648 {
"order.modify", { utils::http::METHOD::PUT,
"/orders/{0}/{1}" } },
649 {
"order.cancel", { utils::http::METHOD::DEL,
"/orders/{0}/{1}" } },
650 {
"order.cancel.bo", { utils::http::METHOD::DEL,
651 "/orders/{0}/{1}?parent_order_id={1}" } },
652 {
"order.trades", { utils::http::METHOD::GET,
"/orders/{0}/trades" } },
653 {
"orders", { utils::http::METHOD::GET,
"/orders" } },
654 {
"trades", { utils::http::METHOD::GET,
"/trades" } },
656 {
"gtt", { utils::http::METHOD::GET,
"/gtt/triggers" } },
657 {
"gtt.place", { utils::http::METHOD::POST,
"/gtt/triggers" } },
658 {
"gtt.info", { utils::http::METHOD::GET,
"/gtt/triggers/{0}" } },
659 {
"gtt.modify", { utils::http::METHOD::PUT,
"/gtt/triggers/{0}" } },
660 {
"gtt.delete", { utils::http::METHOD::DEL,
"/gtt/triggers/{0}" } },
662 {
"mf.orders", { utils::http::METHOD::GET,
"/mf/orders" } },
663 {
"mf.order.info", { utils::http::METHOD::GET,
"/mf/orders/{0}" } },
664 {
"mf.order.place", { utils::http::METHOD::POST,
"/mf/orders" } },
665 {
"mf.order.cancel", { utils::http::METHOD::DEL,
"/mf/orders/{0}" } },
666 {
"mf.holdings", { utils::http::METHOD::GET,
"/mf/holdings" } },
667 {
"mf.instruments", { utils::http::METHOD::GET,
"/mf/instruments",
668 utils::http::CONTENT_TYPE::NON_JSON,
669 utils::http::CONTENT_TYPE::NON_JSON } },
670 {
"mf.sips", { utils::http::METHOD::GET,
"/mf/sips" } },
671 {
"mf.sip.info", { utils::http::METHOD::GET,
"/mf/sips/{0}" } },
672 {
"mf.sip.place", { utils::http::METHOD::POST,
"/mf/sips" } },
673 {
"mf.sip.modify", { utils::http::METHOD::PUT,
"/mf/sips/{0}" } },
674 {
"mf.sip.cancel", { utils::http::METHOD::DEL,
"/mf/sips/{0}" } },
676 {
"portfolio.holdings",
677 { utils::http::METHOD::GET,
"/portfolio/holdings" } },
678 {
"portfolio.positions",
679 { utils::http::METHOD::GET,
"/portfolio/positions" } },
680 {
"portfolio.positions.convert",
681 { utils::http::METHOD::PUT,
"/portfolio/positions" } },
683 {
"market.instruments.all", { utils::http::METHOD::GET,
"/instruments",
684 utils::http::CONTENT_TYPE::NON_JSON,
685 utils::http::CONTENT_TYPE::NON_JSON } },
686 {
"market.instruments", { utils::http::METHOD::GET,
"/instruments/{0}",
687 utils::http::CONTENT_TYPE::NON_JSON,
688 utils::http::CONTENT_TYPE::NON_JSON } },
689 {
"market.margins", { utils::http::METHOD::GET,
"/margins/{0}" } },
690 {
"market.historical",
691 { utils::http::METHOD::GET,
692 "/instruments/historical/{0}/"
693 "{1}?from={2}&to={3}&continuous={4}&oi={5}" } },
694 {
"market.trigger_range",
695 { utils::http::METHOD::GET,
"/instruments/trigger_range/{9}" } },
696 {
"market.quote", { utils::http::METHOD::GET,
"/quote?{0}" } },
697 {
"market.quote.ohlc",
698 { utils::http::METHOD::GET,
"/quote/ohlc?{0}" } },
699 {
"market.quote.ltp", { utils::http::METHOD::GET,
"/quote/ltp?{0}" } },
701 {
"margins.orders", { utils::http::METHOD::POST,
"/margins/orders",
702 utils::http::CONTENT_TYPE::JSON } },
703 {
"margins.basket", { utils::http::METHOD::POST,
704 "/margins/basket?consider_positions={0}",
705 utils::http::CONTENT_TYPE::JSON } },
709 string authorization;
710 httplib::Client client;
713 #ifdef KITE_UNIT_TEST
714 virtual utils::http::response
sendReq(
const utils::http::endpoint& endpoint,
715 const utils::http::Params& body,
const utils::FmtArgs& fmtArgs);
717 utils::http::response
sendReq(
const utils::http::endpoint& endpoint,
726 const utils::http::Params& body,
const utils::FmtArgs& fmtArgs);