CPPKiteConnect
ws.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 <cstdint>
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 kc = kiteconnect;
39 namespace rj = rapidjson;
40 namespace utils = kc::internal::utils;
41 
43 struct depthWS {
44  int16_t orders = -1;
45  int32_t quantity = -1;
46  double price = -1;
47 };
48 
50 struct tick {
51  int32_t instrumentToken = -1;
52  int32_t timestamp = -1;
53  int32_t lastTradeTime = -1;
54  int32_t lastTradedQuantity = -1;
55  int32_t totalBuyQuantity = -1;
56  int32_t totalSellQuantity = -1;
57  int32_t volumeTraded = -1;
58  int32_t oi = -1;
59  int32_t oiDayHigh = -1;
60  int32_t oiDayLow = -1;
61  string mode;
62  double lastPrice = -1;
63  double averageTradePrice = -1;
64  double netChange = -1;
65  bool isTradable;
66  struct OHLC {
67  double open = -1;
68  double high = -1;
69  double low = -1;
70  double close = -1;
71  } ohlc;
72  struct m_depth {
73  std::vector<depthWS> buy;
74  std::vector<depthWS> sell;
75  } marketDepth;
76 };
77 
79 struct postback {
80  postback() = default;
81  explicit postback(const rj::Value::Object& val) { parse(val); };
82 
83  void parse(const rj::Value::Object& val) {
84  orderId = utils::json::get<string>(val, "order_id");
85  exchangeOrderId = utils::json::get<string>(val, "exchange_order_id");
86  placedBy = utils::json::get<string>(val, "placed_by");
87  status = utils::json::get<string>(val, "status");
88  statusMessage = utils::json::get<string>(val, "status_message");
89  tradingSymbol = utils::json::get<string>(val, "tradingsymbol");
90  exchange = utils::json::get<string>(val, "exchange");
91  orderType = utils::json::get<string>(val, "order_type");
92  transactionType = utils::json::get<string>(val, "transaction_type");
93  validity = utils::json::get<string>(val, "validity");
94  product = utils::json::get<string>(val, "product");
95  averagePrice = utils::json::get<double>(val, "average_price");
96  price = utils::json::get<double>(val, "price");
97  quantity = utils::json::get<int>(val, "quantity");
98  filledQuantity = utils::json::get<int>(val, "filled_quantity");
99  unfilledQuantity = utils::json::get<int>(val, "unfilled_quantity");
100  triggerPrice = utils::json::get<double>(val, "trigger_price");
101  userId = utils::json::get<string>(val, "user_id");
102  orderTimestamp = utils::json::get<string>(val, "order_timestamp");
103  exchangeTimestamp = utils::json::get<string>(val, "exchange_timestamp");
104  checksum = utils::json::get<string>(val, "checksum");
105  };
106 
107  int quantity = -1;
108  int filledQuantity = -1;
109  int unfilledQuantity = -1;
110  double averagePrice = -1;
111  double price = -1;
112  double triggerPrice = -1;
113  string orderId;
114  string exchangeOrderId;
115  string placedBy;
116  string status;
117  string statusMessage;
118  string tradingSymbol;
119  string exchange;
120  string orderType;
121  string transactionType;
122  string validity;
123  string product;
124  string userId;
125  string orderTimestamp;
126  string exchangeTimestamp;
127  string checksum;
128 };
129 
130 } // namespace kiteconnect
kiteconnect::depthWS
Represents a single entry in market depth returned by ticker.
Definition: ws.hpp:43
kiteconnect::postback
Represents a postback.
Definition: ws.hpp:79
kiteconnect::tick
Represents a single market data tick.
Definition: ws.hpp:50
kiteconnect::ohlc
Represents OHLC information of an instrument.
Definition: market.hpp:44
kiteconnect::tick::m_depth
Definition: ws.hpp:72
kiteconnect::tick::OHLC
Definition: ws.hpp:66