CPPKiteConnect
order.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 <optional>
29 #include <string>
30 
31 #include "../utils.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 
44  GENERATE_FLUENT_METHOD(placeOrderParams, int, quantity, Quantity);
45  GENERATE_FLUENT_METHOD(
46  placeOrderParams, int, disclosedQuantity, DisclosedQuantity);
47  GENERATE_FLUENT_METHOD(placeOrderParams, int, validityTtl, ValidityTtl);
48  GENERATE_FLUENT_METHOD(placeOrderParams, int, icebergLegs, IcebergLegs);
49  GENERATE_FLUENT_METHOD(
50  placeOrderParams, int, icebergQuantity, IcebergQuantity);
51  GENERATE_FLUENT_METHOD(placeOrderParams, double, price, Price);
52  GENERATE_FLUENT_METHOD(
53  placeOrderParams, double, triggerPrice, TriggerPrice);
54  GENERATE_FLUENT_METHOD(placeOrderParams, double, squareOff, SquareOff);
55  GENERATE_FLUENT_METHOD(placeOrderParams, double, stopLoss, StopLoss);
56  GENERATE_FLUENT_METHOD(
57  placeOrderParams, double, trailingStopLoss, TrailingStopLoss);
58  GENERATE_FLUENT_METHOD(placeOrderParams, const string&, variety, Variety);
59  GENERATE_FLUENT_METHOD(placeOrderParams, const string&, exchange, Exchange);
60  GENERATE_FLUENT_METHOD(placeOrderParams, const string&, symbol, Symbol);
61  GENERATE_FLUENT_METHOD(
62  placeOrderParams, const string&, transactionType, TransactionType);
63  GENERATE_FLUENT_METHOD(placeOrderParams, const string&, product, Product);
64  GENERATE_FLUENT_METHOD(
65  placeOrderParams, const string&, orderType, OrderType);
66  GENERATE_FLUENT_METHOD(placeOrderParams, const string&, validity, Validity);
67  GENERATE_FLUENT_METHOD(placeOrderParams, const string&, tag, Tag);
68 
69  int quantity;
70  std::optional<int> disclosedQuantity;
71  std::optional<int> validityTtl;
72  std::optional<int> icebergLegs;
73  std::optional<int> icebergQuantity;
74  std::optional<double> price;
75  std::optional<double> triggerPrice;
76  std::optional<double> squareOff;
77  std::optional<double> stopLoss;
78  std::optional<double> trailingStopLoss;
79  string variety;
80  string exchange;
81  string symbol;
82  string transactionType;
83  string product;
84  string orderType;
85  std::optional<string> validity;
86  std::optional<string> tag;
87 };
88 
91  GENERATE_FLUENT_METHOD(modifyOrderParams, int, quantity, Quantity);
92  GENERATE_FLUENT_METHOD(
93  modifyOrderParams, int, disclosedQuantity, DisclosedQuantity);
94  GENERATE_FLUENT_METHOD(modifyOrderParams, double, price, Price);
95  GENERATE_FLUENT_METHOD(
96  modifyOrderParams, double, triggerPrice, TriggerPrice);
97  GENERATE_FLUENT_METHOD(modifyOrderParams, const string&, variety, Variety);
98  GENERATE_FLUENT_METHOD(
99  modifyOrderParams, const string&, orderType, OrderType);
100  GENERATE_FLUENT_METHOD(
101  modifyOrderParams, const string&, validity, Validity);
102  GENERATE_FLUENT_METHOD(modifyOrderParams, const string&, orderId, OrderId);
103  GENERATE_FLUENT_METHOD(
104  modifyOrderParams, const string&, parentOrderId, ParentOrderId);
105 
106  std::optional<int> quantity;
107  std::optional<int> disclosedQuantity;
108  std::optional<double> price;
109  std::optional<double> triggerPrice;
110  string variety;
111  string orderId;
112  std::optional<string> parentOrderId;
113  std::optional<string> orderType;
114  std::optional<string> validity;
115 };
116 
118 struct order {
119  order() = default;
120  explicit order(const rj::Value::Object& val) { parse(val); };
121 
122  void parse(const rj::Value::Object& val) {
123  accountID = utils::json::get<string>(val, "account_id");
124  placedBy = utils::json::get<string>(val, "placed_by");
125  orderID = utils::json::get<string>(val, "order_id");
126  exchangeOrderID = utils::json::get<string>(val, "exchange_order_id");
127  parentOrderID = utils::json::get<string>(val, "parent_order_id");
128  status = utils::json::get<string>(val, "status");
129  statusMessage = utils::json::get<string>(val, "status_message");
130  orderTimestamp = utils::json::get<string>(val, "order_timestamp");
131  exchangeUpdateTimestamp =
132  utils::json::get<string>(val, "exchange_update_timestamp");
133  exchangeTimestamp = utils::json::get<string>(val, "exchange_timestamp");
134  rejectedBy = utils::json::get<string>(val, "rejected_by");
135  variety = utils::json::get<string>(val, "variety");
136  exchange = utils::json::get<string>(val, "exchange");
137  tradingsymbol = utils::json::get<string>(val, "tradingsymbol");
138  instrumentToken = utils::json::get<uint32_t>(val, "instrument_token");
139  orderType = utils::json::get<string>(val, "order_type");
140  transactionType = utils::json::get<string>(val, "transaction_type");
141  validity = utils::json::get<string>(val, "validity");
142  product = utils::json::get<string>(val, "product");
143  quantity = utils::json::get<int>(val, "quantity");
144  disclosedQuantity = utils::json::get<int>(val, "disclosed_quantity");
145  validityTtl = utils::json::get<int>(val, "validity_ttl");
146  price = utils::json::get<double>(val, "price");
147  triggerPrice = utils::json::get<double>(val, "trigger_price");
148  averagePrice = utils::json::get<double>(val, "average_price");
149  filledQuantity = utils::json::get<int>(val, "filled_quantity");
150  pendingQuantity = utils::json::get<int>(val, "pending_quantity");
151  cancelledQuantity = utils::json::get<int>(val, "cancelled_quantity");
152  };
153 
154  uint32_t instrumentToken = 0;
155  int quantity = -1;
156  int disclosedQuantity = -1;
157  int filledQuantity = -1;
158  int pendingQuantity = -1;
159  int cancelledQuantity = -1;
160  int validityTtl = -1;
161  double price = -1.0;
162  double triggerPrice = -1.0;
163  double averagePrice = -1.0;
164  string accountID;
165  string placedBy;
166  string orderID;
167  string exchangeOrderID;
168  string parentOrderID;
169  string status;
170  string statusMessage;
171  string orderTimestamp;
172  string exchangeUpdateTimestamp;
173  string exchangeTimestamp;
174  string rejectedBy;
175  string variety;
176  string exchange;
177  string tradingsymbol;
178  string orderType;
179  string transactionType;
180  string validity;
181  string product;
182 };
183 
185 struct trade {
186  trade() = default;
187  explicit trade(const rj::Value::Object& val) { parse(val); };
188 
189  void parse(const rj::Value::Object& val) {
190  averagePrice = utils::json::get<double>(val, "average_price");
191  quantity = utils::json::get<double>(val, "quantity");
192  tradeID = utils::json::get<string>(val, "trade_id");
193  product = utils::json::get<string>(val, "product");
194  fillTimestamp = utils::json::get<string>(val, "fill_timestamp");
195  exchangeTimestamp = utils::json::get<string>(val, "exchange_timestamp");
196  exchangeOrderID = utils::json::get<string>(val, "exchange_order_id");
197  orderID = utils::json::get<string>(val, "order_id");
198  transactionType = utils::json::get<string>(val, "transaction_type");
199  tradingSymbol = utils::json::get<string>(val, "tradingsymbol");
200  exchange = utils::json::get<string>(val, "exchange");
201  instrumentToken = utils::json::get<uint32_t>(val, "instrument_token");
202  };
203 
204  uint32_t instrumentToken = 0;
205  double averagePrice = -1.0;
206  double quantity = -1.0;
207  string tradeID;
208  string product;
209  string fillTimestamp;
210  string exchangeTimestamp;
211  string exchangeOrderID;
212  string orderID;
213  string transactionType;
214  string tradingSymbol;
215  string exchange;
216 };
217 
218 } // namespace kiteconnect
kiteconnect::order
Represents information of an order.
Definition: order.hpp:118
kiteconnect::placeOrderParams
Parameters required for the placeOrder method.
Definition: order.hpp:43
kiteconnect::trade
Represents information of a trade.
Definition: order.hpp:185
kiteconnect::modifyOrderParams
Parameters required for the modifyOrder method.
Definition: order.hpp:90