ticker wraps around the websocket API provided by KiteConnect and provides a native interface.
More...
#include <ws.hpp>
|
| ticker (string Key, unsigned int ConnectTimeout=DEFAULT_CONNECT_TIMEOUT, bool EnableReconnect=false, unsigned int MaxReconnectDelay=DEFAULT_MAX_RECONNECT_DELAY, unsigned int MaxReconnectTries=DEFAULT_MAX_RECONNECT_TRIES) |
| Construct a new kiteWS object. More...
|
|
void | setApiKey (const string &key) |
| Set the API key. More...
|
|
string | getApiKey () const |
| Get API key set at the moment. More...
|
|
void | setAccessToken (const string &token) |
| Set the access token. More...
|
|
string | getAccessToken () const |
| Get access token set at the moment. More...
|
|
void | connect () |
| Connect to the websocket server.
|
|
bool | isConnected () const |
| Check if client is connected.
|
|
std::chrono::time_point< std::chrono::system_clock > | getLastBeatTime () const |
| Get the last time heartbeat was received. Should be used in conjunction with the isConnected() method. More...
|
|
void | run () |
| Start the client. Should always be called after connect() .
|
|
void | stop () |
| Stop the client. Closes the connection if connected. Should be the last method that is called.
|
|
void | subscribe (const std::vector< int > &instrumentTokens) |
| Subscribe to a list of instrument tokens. More...
|
|
void | unsubscribe (const std::vector< int > &instrumentTokens) |
| Unsubscribe. More...
|
|
void | setMode (const string &mode, const std::vector< int > &instrumentTokens) |
| Set the subscription mode for a list of instrument tokens. More...
|
|
|
std::function< void(ticker *ws)> | onConnect |
| Called on successful connect.
|
|
std::function< void(ticker *ws, const std::vector< kc::tick > &ticks)> | onTicks |
| Called when ticks are received.
|
|
std::function< void(ticker *ws, const kc::postback &postback)> | onOrderUpdate |
| Called when an order update is received.
|
|
std::function< void(ticker *ws, const string &message)> | onMessage |
| Called when a message is received.
|
|
std::function< void(ticker *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(ticker *ws)> | onConnectError |
| Called when an error occures while trying to connect.
|
|
std::function< void(ticker *ws, unsigned int attemptCount)> | onTryReconnect |
| Called when reconnection is being attempted. More...
|
|
std::function< void(ticker *ws)> | onReconnectFail |
| Called when reconnect attempts exceed maximum reconnect attempts set by user i.e., when ticker is unable to reconnect.
|
|
std::function< void(ticker *ws, int code, const string &message)> | onClose |
| Called when connection is closed.
|
|
|
class | tickerTest_binaryParsingTest_Test |
|
ticker wraps around the websocket API provided by KiteConnect and provides a native interface.
◆ ticker()
kiteconnect::ticker::ticker |
( |
string |
Key, |
|
|
unsigned int |
ConnectTimeout = DEFAULT_CONNECT_TIMEOUT , |
|
|
bool |
EnableReconnect = false , |
|
|
unsigned int |
MaxReconnectDelay = DEFAULT_MAX_RECONNECT_DELAY , |
|
|
unsigned int |
MaxReconnectTries = DEFAULT_MAX_RECONNECT_TRIES |
|
) |
| |
|
inlineexplicit |
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. |
Construct a new ticker object. All durations are in seconds.
- Parameters
-
Key | API key |
ConnectTimeout | connection timeout |
EnableReconnect | auto reconnect is enabled if EnableReconnect is set to true |
MaxReconnectDelay | Maximum delay after which subsequent reconnection interval will become constant |
MaxReconnectTries | Maximum number of retries before ticker quits trying to reconnect. |
◆ getAccessToken()
string kiteconnect::ticker::getAccessToken |
( |
| ) |
const |
|
inline |
Get access token set at the moment.
- Returns
- string access token
◆ getApiKey()
string kiteconnect::ticker::getApiKey |
( |
| ) |
const |
|
inline |
Get API key set at the moment.
- Returns
- string API key
◆ getLastBeatTime()
std::chrono::time_point< std::chrono::system_clock > kiteconnect::ticker::getLastBeatTime |
( |
| ) |
const |
|
inline |
Get the last time heartbeat was received. Should be used in conjunction with the isConnected()
method.
- Returns
- std::chrono::time_point<std::chrono::system_clock> time
◆ setAccessToken()
void kiteconnect::ticker::setAccessToken |
( |
const string & |
token | ) |
|
|
inline |
Set the access token.
- Parameters
-
token | access token is set to token. |
example
◆ setApiKey()
void kiteconnect::ticker::setApiKey |
( |
const string & |
key | ) |
|
|
inline |
Set the API key.
- Parameters
-
◆ setMode()
void kiteconnect::ticker::setMode |
( |
const string & |
mode, |
|
|
const std::vector< int > & |
instrumentTokens |
|
) |
| |
|
inline |
Set the subscription mode for a list of instrument tokens.
- Parameters
-
mode | mode to set |
instrumentTokens | list of instrument tokens whose mode should be set |
◆ subscribe()
void kiteconnect::ticker::subscribe |
( |
const std::vector< int > & |
instrumentTokens | ) |
|
|
inline |
Subscribe to a list of instrument tokens.
- Parameters
-
instrumentTokens | list of instrument tokens that should be subscribed |
◆ unsubscribe()
void kiteconnect::ticker::unsubscribe |
( |
const std::vector< int > & |
instrumentTokens | ) |
|
|
inline |
Unsubscribe.
- Parameters
-
instrumentTokens | list of instrument tokens that should be unsubscribed |
◆ onTryReconnect
std::function<void(ticker* ws, unsigned int attemptCount)> kiteconnect::ticker::onTryReconnect |
Called when reconnection is being attempted.
- Note
- Auto reconnection: Auto reconnection is disabled by default and can be enabled by setting
EnableReconnect
to true
in ticker
'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 tweak the alogrithm. MaxReconnectDelay is the maximum delay after which subsequent reconnection interval will become constant and MaxReconnectTries is maximum number of retries before ticker
quits trying to reconnect.
The documentation for this class was generated from the following files:
- /builds/kite/infra/cppkiteconnect-docs/cppkiteconnect/include/kitepp/ticker/ws.hpp
- /builds/kite/infra/cppkiteconnect-docs/cppkiteconnect/include/kitepp/ticker/internal.hpp