CPPKiteConnect
gtt.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 
28 #include <string>
29 
30 #include "../utils.hpp"
31 #include "order.hpp"
32 #include "rapidjson/include/rapidjson/document.h"
33 #include "rapidjson/include/rapidjson/rapidjson.h"
34 
35 namespace kiteconnect {
36 
37 using std::string;
38 namespace rj = rapidjson;
39 namespace kc = kiteconnect;
40 namespace utils = kc::internal::utils;
41 
43 struct gttParams {
44  GENERATE_FLUENT_METHOD(gttParams, int, quantity, Quantity);
45  GENERATE_FLUENT_METHOD(gttParams, double, price, Price);
46  GENERATE_FLUENT_METHOD(
47  gttParams, const string&, transactionType, TransactionType);
48  GENERATE_FLUENT_METHOD(gttParams, const string&, orderType, OrderType);
49  GENERATE_FLUENT_METHOD(gttParams, const string&, product, Product);
50 
51  int quantity = -1;
52  double price = -1;
53  string transactionType;
54  string orderType;
55  string product;
56 };
57 
59 struct GTTCondition {
60  GTTCondition() = default;
61  explicit GTTCondition(const rj::Value::Object& val) { parse(val); };
62 
63  void parse(const rj::Value::Object& val) {
64  exchange = utils::json::get<string>(val, "exchange");
65  tradingsymbol = utils::json::get<string>(val, "tradingsymbol");
66  lastPrice = utils::json::get<double>(val, "last_price");
67  triggerValues =
68  utils::json::get<std::vector<double>>(val, "trigger_values");
69  };
70 
71  double lastPrice = -1;
72  string exchange;
73  string tradingsymbol;
74  std::vector<double> triggerValues;
75 };
76 
79  GENERATE_FLUENT_METHOD(placeGttParams, double, lastPrice, LastPrice);
80  GENERATE_FLUENT_METHOD(
81  placeGttParams, const string&, triggerType, TriggerType);
82  GENERATE_FLUENT_METHOD(placeGttParams, const string&, symbol, Symbol);
83  GENERATE_FLUENT_METHOD(placeGttParams, const string&, exchange, Exchange);
84  GENERATE_FLUENT_METHOD(placeGttParams, const std::vector<double>&,
85  triggerValues, TriggerValues);
86  GENERATE_FLUENT_METHOD(placeGttParams, const std::vector<gttParams>&,
87  gttParamsList, GttParamsList);
88 
89  double lastPrice = -1;
90  string triggerType;
91  string symbol;
92  string exchange;
93  std::vector<double> triggerValues;
94  std::vector<gttParams> gttParamsList;
95 };
96 
99  GENERATE_FLUENT_METHOD(modifyGttParams, int, triggerId, TriggerId);
100  GENERATE_FLUENT_METHOD(modifyGttParams, double, lastPrice, LastPrice);
101  GENERATE_FLUENT_METHOD(
102  modifyGttParams, const string&, triggerType, TriggerType);
103  GENERATE_FLUENT_METHOD(modifyGttParams, const string&, symbol, Symbol);
104  GENERATE_FLUENT_METHOD(modifyGttParams, const string&, exchange, Exchange);
105  GENERATE_FLUENT_METHOD(modifyGttParams, const std::vector<double>&,
106  triggerValues, TriggerValues);
107  GENERATE_FLUENT_METHOD(modifyGttParams, const std::vector<gttParams>&,
108  gttParamsList, GttParamsList);
109 
110  int triggerId;
111  double lastPrice;
112  string triggerType;
113  string symbol;
114  string exchange;
115  std::vector<double> triggerValues;
116  std::vector<gttParams> gttParamsList;
117 };
118 
120 struct GTT {
121  GTT() = default;
122  explicit GTT(const rj::Value::Object& val) { parse(val); };
123 
124  void parse(const rj::Value::Object& val) {
125  ID = utils::json::get<int>(val, "id");
126  userID = utils::json::get<string>(val, "user_id");
127  type = utils::json::get<string>(val, "type");
128  createdAt = utils::json::get<string>(val, "created_at");
129  updatedAt = utils::json::get<string>(val, "updated_at");
130  expiresAt = utils::json::get<string>(val, "expires_at");
131  status = utils::json::get<string>(val, "status");
132  condition = utils::json::get<utils::json::JsonObject, GTTCondition>(
133  val, "condition");
134 
135  rj::Value ordersBuffer(rj::kArrayType);
136  utils::json::get<utils::json::JsonArray>(val, ordersBuffer, "orders");
137  for (auto& v : ordersBuffer.GetArray()) {
138  orders.emplace_back(v.GetObject());
139  };
140  };
141 
142  int ID = -1;
143  string userID;
144  string type;
145  string createdAt;
146  string updatedAt;
147  string expiresAt;
148  string status;
149  GTTCondition condition;
150  std::vector<order> orders;
151 };
152 } // namespace kiteconnect
kiteconnect::modifyGttParams
Parameters required for the modifyGtt method.
Definition: gtt.hpp:98
kiteconnect::GTT
GTT represents a single GTT order.
Definition: gtt.hpp:120
kiteconnect::gttParams
Represents parameters of a single GTT.
Definition: gtt.hpp:43
kiteconnect::GTTCondition
Represents 'condition' for a single gtt.
Definition: gtt.hpp:59
kiteconnect::placeGttParams
Parameters required for the placeGtt method.
Definition: gtt.hpp:78