Used for accessing websocket interface of Kite API.
More...
#include <kitews.hpp>
|
| kiteWS (const string &apikey, unsigned int connecttimeout=5, bool enablereconnect=false, unsigned int maxreconnectdelay=60, unsigned int maxreconnecttries=30) |
| Construct a new kiteWS object. More...
|
|
void | setAPIKey (const string &arg) |
| Set the API key. More...
|
|
string | getAPIKey () const |
| get set API key More...
|
|
void | setAccessToken (const string &arg) |
| Set the Access Token. More...
|
|
string | getAccessToken () const |
| Get the Access Token set currently. More...
|
|
void | connect () |
| Connect to websocket server. More...
|
|
bool | isConnected () const |
| Check if client is connected at present. More...
|
|
std::chrono::time_point< std::chrono::system_clock > | getLastBeatTime () |
| Get the last time heartbeat was received. Should be used in conjunction with isConnected() method. More...
|
|
void | run () |
| Start the client. Should always be called after connect() . More...
|
|
void | stop () |
| Stop the client. Closes the connection if connected. Should be the last method to be called. More...
|
|
void | subscribe (const std::vector< int > &instrumentToks) |
| Subscribe instrument tokens. More...
|
|
void | unsubscribe (const std::vector< int > &instrumentToks) |
| unsubscribe instrument tokens. More...
|
|
void | setMode (const string &mode, const std::vector< int > &instrumentToks) |
| Set the mode of instrument tokens. More...
|
|
|
std::function< void(kiteWS *ws)> | onConnect |
| Called on successful connect.
|
|
std::function< void(kiteWS *ws, const std::vector< kc::tick > &ticks)> | onTicks |
| Called when ticks are received.
|
|
std::function< void(kiteWS *ws, const kc::postback &postback)> | onOrderUpdate |
| Called when an order update is received.
|
|
std::function< void(kiteWS *ws, const string &message)> | onMessage |
| Called when a message is received.
|
|
std::function< void(kiteWS *ws, int code, const string &message)> | onError |
| Called when connection is closed with an error or websocket server sends an error message.
|
|
std::function< void(kiteWS *ws)> | onConnectError |
| Called when an error occures while trying to connect.
|
|
std::function< void(kiteWS *ws, unsigned int attemptCount)> | onTryReconnect |
| Called when reconnection is being attempted. More...
|
|
std::function< void(kiteWS *ws)> | onReconnectFail |
| Called when reconnect attempts exceed maximum reconnect attempts set by user i.e., when client is unable to reconnect.
|
|
std::function< void(kiteWS *ws, int code, const string &message)> | onClose |
| Called when connection is closed.
|
|
|
class | kWSTest_binaryParsingTest_Test |
|
Used for accessing websocket interface of Kite API.
◆ kiteWS()
kiteconnect::kiteWS::kiteWS |
( |
const string & |
apikey, |
|
|
unsigned int |
connecttimeout = 5 , |
|
|
bool |
enablereconnect = false , |
|
|
unsigned int |
maxreconnectdelay = 60 , |
|
|
unsigned int |
maxreconnecttries = 30 |
|
) |
| |
|
inline |
Construct a new kiteWS object.
- Parameters
-
apikey | API key |
connecttimeout | Connection timeout |
enablereconnect | Should be set to true for enabling reconnection |
maxreconnectdelay | Maximum reconnect delay for reconnection |
maxreconnecttries | Maximum reconnection attempts after which onReconnectFail will be called and no further attempt to reconnect will be made. |
◆ connect()
void kiteconnect::kiteWS::connect |
( |
| ) |
|
|
inline |
Connect to websocket server.
◆ getAccessToken()
string kiteconnect::kiteWS::getAccessToken |
( |
| ) |
const |
|
inline |
Get the Access Token set currently.
- Returns
- string
◆ getAPIKey()
string kiteconnect::kiteWS::getAPIKey |
( |
| ) |
const |
|
inline |
get set API key
- Returns
- string
◆ getLastBeatTime()
std::chrono::time_point<std::chrono::system_clock> kiteconnect::kiteWS::getLastBeatTime |
( |
| ) |
|
|
inline |
Get the last time heartbeat was received. Should be used in conjunction with isConnected()
method.
- Returns
- std::chrono::time_point<std::chrono::system_clock>
◆ isConnected()
bool kiteconnect::kiteWS::isConnected |
( |
| ) |
const |
|
inline |
Check if client is connected at present.
◆ run()
void kiteconnect::kiteWS::run |
( |
| ) |
|
|
inline |
Start the client. Should always be called after connect()
.
◆ setAccessToken()
void kiteconnect::kiteWS::setAccessToken |
( |
const string & |
arg | ) |
|
|
inline |
Set the Access Token.
- Parameters
-
arg | the string you want to set as access token |
Example
Kite.setAccessToken(accessToken);
◆ setAPIKey()
void kiteconnect::kiteWS::setAPIKey |
( |
const string & |
arg | ) |
|
|
inline |
Set the API key.
- Parameters
-
◆ setMode()
void kiteconnect::kiteWS::setMode |
( |
const string & |
mode, |
|
|
const std::vector< int > & |
instrumentToks |
|
) |
| |
|
inline |
Set the mode of instrument tokens.
- Parameters
-
mode | mode |
instrumentToks | vector of instrument tokens. |
◆ stop()
void kiteconnect::kiteWS::stop |
( |
| ) |
|
|
inline |
Stop the client. Closes the connection if connected. Should be the last method to be called.
◆ subscribe()
void kiteconnect::kiteWS::subscribe |
( |
const std::vector< int > & |
instrumentToks | ) |
|
|
inline |
Subscribe instrument tokens.
- Parameters
-
instrumentToks | vector of instrument tokens to be subscribed. |
◆ unsubscribe()
void kiteconnect::kiteWS::unsubscribe |
( |
const std::vector< int > & |
instrumentToks | ) |
|
|
inline |
unsubscribe instrument tokens.
- Parameters
-
instrumentToks | vector of instrument tokens to be unsubscribed. |
◆ onTryReconnect
std::function<void(kiteWS* ws, unsigned int attemptCount)> kiteconnect::kiteWS::onTryReconnect |
Called when reconnection is being attempted.
Auto reconnection:
Auto reconnection is disabled by default and can be enabled by setting enablereconnect
to true
in kiteWS
's constructor. Auto reonnection mechanism is based on Exponential backoff algorithm in which next retry interval will be increased exponentially. maxreconnectdelay and maxreconnecttries params can be used to tewak the alogrithm where maxreconnectdelay is the maximum delay after which subsequent reconnection interval will become constant and maxreconnecttries is maximum number of retries before its quiting reconnection.
The documentation for this class was generated from the following file:
- /builds/kite/infra/cppkiteconnect-docs/cppkiteconnect/include/kitepp/kitews.hpp