![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
Where blocking broker clients on one key share its access token, across threads and processes. More...
#include <algotradelib/src/network/token_store.hpp>
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. | |
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.
|
pure virtual |
Removes an identity's token if it is the given one.
| identity | The identity. |
| access_token | The token the broker refused. |
Implemented in algotradelib::network::FileTokenStore.
|
pure virtual |
Reads the token stored for an identity.
| identity | The identity. |
Implemented in algotradelib::network::FileTokenStore.
|
pure virtual |
Takes the lock of one identity, waiting a bounded time for another holder.
| identity | The identity. |
Implemented in algotradelib::network::FileTokenStore.
|
pure virtual |
Stores a token for an identity, unless the stored one expires later.
| identity | The identity. |
| token | The token. |
Implemented in algotradelib::network::FileTokenStore.
|
pure virtual |
Removes an identity's token, whatever it is.
| identity | The identity. |
Implemented in algotradelib::network::FileTokenStore.