CPPKiteConnect
portfolio.hpp
1 /*
2  * Licensed under the MIT License <http://opensource.org/licenses/MIT>.
3  * SPDX-License-Identifier: MIT
4  *
5  * Copyright (c) 2020-2022 Bhumit Attarde
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
20  * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
22  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23  * USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #pragma once
27 #pragma clang diagnostic ignored "-Wundefined-inline"
28 
29 #include <vector>
30 
31 #include "../kite.hpp"
32 #include "../utils.hpp"
33 
34 namespace kiteconnect {
35 inline std::vector<holding> kite::holdings() {
36  return callApi<std::vector<holding>, utils::json::JsonArray, true>(
37  "portfolio.holdings", {}, {}, [](utils::json::JsonArray& data) {
38  std::vector<holding> Holdings;
39  for (auto& i : data) { Holdings.emplace_back(i.GetObject()); }
40  return Holdings;
41  });
42 };
43 
45  return callApi<positions, utils::json::JsonObject>("portfolio.positions");
46 };
47 
48 inline bool kite::convertPosition(const convertPositionParams& params) {
49  utils::http::Params bodyParams = {
50  { "exchange", params.exchange },
51  { "tradingsymbol", params.symbol },
52  { "transaction_type", params.transactionType },
53  { "position_type", params.positionType },
54  { "quantity", std::to_string(params.quantity) },
55  { "old_product", params.oldProduct },
56  { "new_product", params.newProduct },
57  };
58  return callApi<bool, bool>("portfolio.positions.convert", bodyParams);
59 };
60 }; // namespace kiteconnect
kiteconnect::positions
Represents response of the getPositions() method.
Definition: portfolio.hpp:155
kiteconnect::kite::holdings
std::vector< holding > holdings()
Get holdings.
Definition: portfolio.hpp:35
kiteconnect::kite::getPositions
positions getPositions()
Get positions.
Definition: portfolio.hpp:44
kiteconnect::kite::convertPosition
bool convertPosition(const convertPositionParams &params)
Convert an open position to a different product type.
Definition: portfolio.hpp:48
kiteconnect::convertPositionParams
Parameters required for the convertPosition() method.
Definition: portfolio.hpp:174