algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::network::TokenStore Class Referenceabstract

Where blocking broker clients on one key share its access token, across threads and processes. More...

#include <algotradelib/src/network/token_store.hpp>

Inheritance diagram for algotradelib::network::TokenStore:

Classes

class  Lock
 Held while one caller works on one identity; destroying it releases the lock. More...

Public Member Functions

virtual Result< std::unique_ptr< Lock > > lock (const std::string &identity)=0
 Takes the lock of one identity, waiting a bounded time for another holder.
virtual Result< std::optional< StoredToken > > load (const std::string &identity)=0
 Reads the token stored for an identity.
virtual std::optional< BrokerError > publish (const std::string &identity, const StoredToken &token)=0
 Stores a token for an identity, unless the stored one expires later.
virtual std::optional< BrokerError > discard (const std::string &identity, const std::string &access_token)=0
 Removes an identity's token if it is the given one.
virtual std::optional< BrokerError > remove (const std::string &identity)=0
 Removes an identity's token, whatever it is.

Detailed Description

Where blocking broker clients on one key share its access token, across threads and processes.

Give one to a blocking client (KisBlockingClient, KiwoomBlockingClient, TossBlockingClient). Before a call, a client whose token is missing or within five minutes of its expiry takes the lock of its identity, adopts the stored token if it is valid, and otherwise requests one and publishes it before sending anything else. When the broker refuses the token a call carried, the client discards it from the store, if the store still holds that token.

Each identity (a broker configuration's token_identity()) has its own lock. Call load, publish, discard and remove while holding the object lock returned for that identity. Each function returns filesystem and parse failures, rather than throwing them, as an AUTHENTICATION error with reached_broker_ false, broker code token_store and a fixed message (an allocation can still throw). An implementation must allow calls from several threads at once.

Definition at line 40 of file token_store.hpp.

Member Function Documentation

◆ discard()

virtual std::optional< BrokerError > algotradelib::network::TokenStore::discard ( const std::string & identity,
const std::string & access_token )
pure virtual

Removes an identity's token if it is the given one.

Parameters
identityThe identity.
access_tokenThe token the broker refused.
Returns
The store's error, or nothing.

Implemented in algotradelib::network::FileTokenStore.

◆ load()

virtual Result< std::optional< StoredToken > > algotradelib::network::TokenStore::load ( const std::string & identity)
pure virtual

Reads the token stored for an identity.

Parameters
identityThe identity.
Returns
The token, nothing if none is stored, or the store's error.

Implemented in algotradelib::network::FileTokenStore.

◆ lock()

virtual Result< std::unique_ptr< Lock > > algotradelib::network::TokenStore::lock ( const std::string & identity)
pure virtual

Takes the lock of one identity, waiting a bounded time for another holder.

Parameters
identityThe identity.
Returns
The held lock, or the store's error.

Implemented in algotradelib::network::FileTokenStore.

◆ publish()

virtual std::optional< BrokerError > algotradelib::network::TokenStore::publish ( const std::string & identity,
const StoredToken & token )
pure virtual

Stores a token for an identity, unless the stored one expires later.

Parameters
identityThe identity.
tokenThe token.
Returns
The store's error, or nothing.

Implemented in algotradelib::network::FileTokenStore.

◆ remove()

virtual std::optional< BrokerError > algotradelib::network::TokenStore::remove ( const std::string & identity)
pure virtual

Removes an identity's token, whatever it is.

Parameters
identityThe identity.
Returns
The store's error, or nothing.

Implemented in algotradelib::network::FileTokenStore.


The documentation for this class was generated from the following file: