29 #include <type_traits>
31 #include "kitepp/exceptions.hpp"
32 #include "uri-parser/include/parser.hpp"
34 #include "../kite.hpp"
35 #include "../utils.hpp"
37 namespace kiteconnect {
39 inline string kite::getAuth()
const {
return authorization; }
41 inline string kite::encodeSymbolsList(
const std::vector<string>& symbols) {
43 for (
const auto& symbol : symbols) {
44 size_t colonPos = symbol.find_first_of(
':');
45 if (colonPos == std::string::npos) {
46 throw libException(
"invalid symbol");
48 string exchange = symbol.substr(0, colonPos);
49 string ticker = symbol.substr(colonPos + 1);
52 FMT(
"i={0}:{1}&", exchange, parser::encodeUrl(ticker)));
55 if (!symbolsList.empty()) { symbolsList.pop_back(); };
62 const utils::http::endpoint& endpoint,
const utils::http::Params& body,
63 const utils::FmtArgs& fmtArgs) {
64 if (endpoint.contentType == utils::http::CONTENT_TYPE::JSON) {
65 return utils::http::request { endpoint.method, endpoint.Path(fmtArgs),
66 getAuth(), body, endpoint.contentType, endpoint.responseType,
67 body.begin()->second }
70 return utils::http::request { endpoint.method, endpoint.Path(fmtArgs),
71 getAuth(), body, endpoint.contentType, endpoint.responseType }
75 template <
class Res,
class Data,
bool UseCustomParser>
76 inline Res kite::callApi(
const string& service,
const utils::http::Params& body,
77 const utils::FmtArgs& fmtArgs,
78 utils::json::CustomParser<Res, Data, UseCustomParser> customParser) {
79 utils::http::response res =
sendReq(endpoints.at(service), body, fmtArgs);
81 kiteconnect::internal::throwException(
82 res.errorType, res.code, res.message);
84 return utils::json::parse<Res, Data, UseCustomParser>(
85 res.data, customParser);