![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
A blocking KIS client: each call runs a KisClient request on a private event loop and returns its result. Not thread-safe. More...
#include <algotradelib/src/brokers/kis/client.hpp>
Public Member Functions | |
| KisBlockingClient (ssl::context &context, KisConfig config, network::HttpClientOptions options={}, std::shared_ptr< network::TokenStore > store=nullptr, std::shared_ptr< network::CalendarCache > calendars=nullptr) | |
| Constructs a client. | |
| Result< QuoteSnapshot > | quote (InstrumentId instrument) |
| Returns a quote; see KisClient::async_quote. | |
| Result< Instrument > | instrument (InstrumentId subject) |
| Returns an instrument's reference data. | |
| Result< TradingCalendar > | calendar (Date from, bool refresh=false) |
| Returns the trading calendar from a date on; see KisClient::async_calendar (cached). | |
| Result< PriceLimits > | price_limits (InstrumentId instrument) |
| Returns an instrument's price band for today. | |
| Result< std::vector< TradePrint > > | trades (InstrumentId instrument, int count) |
| Returns an instrument's recent trades. | |
| Result< DepthSnapshot > | depth (InstrumentId instrument) |
| Returns the order book (ten levels a side). | |
| Result< BarSeries > | bars (BarQuery query) |
| Returns bars; see KisClient::async_bars. | |
| Result< HoldingsSnapshot > | holdings (KisAccount account) |
| Returns the account's holdings. | |
| Result< BuyingPower > | buying_power (Currency currency, KisAccount account) |
| Returns the account's buying power, in won. | |
| Result< KisOrderAck > | place_order (KisAccount account, OrderRequest order) |
| Places a cash order; see KisClient::async_place_order. | |
| Result< KisOrderAck > | replace_order (KisAccount account, KisAmendment amendment) |
| Amends an order's price or quantity; the outcome can be unknown after an error (see KisClient::async_replace_order). | |
| Result< KisOrderAck > | cancel_order (KisAccount account, KisAmendment amendment) |
| Cancels an order; the outcome can be unknown after an error, and the order may still rest (see KisClient::async_cancel_order). | |
| Result< KisOpenOrderPage > | open_orders (KisAccount account) |
| Returns the orders that can still be amended or cancelled; see KisClient::async_open_orders (including how demo accounts are answered). | |
| Result< OrderPage > | order_history (KisAccount account, KisHistoryRange range) |
| Returns the orders placed over a date range, with their fills. | |
| const network::RateLimitStats * | rate_limit_stats () const |
| Returns the rate limiter's statistics (safe to read between calls). | |
| KisRest | token () const |
| Returns the access token; see KisClient::token. | |
| bool | adopt_token (KisRest token) |
| Uses a token issued earlier; see KisClient::adopt_token. | |
Friends | |
| struct | KisClientTestAccess |
A blocking KIS client: each call runs a KisClient request on a private event loop and returns its result. Not thread-safe.
A call whose loop stops before the request completes returns a TRANSPORT error (event_loop_stopped).
With a token store, clients on one app key and environment share one token, in this process or others (network::TokenStore): KIS issues one token per key per minute (EGW00133). Every token is then requested under the store's lock before a call, and none during it: a call whose token stops being usable while it runs returns token_unusable (AUTHENTICATION, not sent), and the next call prepares one. A request authorized just before another program replaced the token can still be refused; it is not sent again. A program stopped after KIS issued a token and before it was stored leaves the old one stored until KIS refuses it.
With a calendar cache, clients share KIS's trading calendar for the day, in this process or others (network::CalendarCache, see calendar): KIS asks that its holiday inquiry be made at most once a day.
Definition at line 4270 of file client.hpp.
|
inline |
Constructs a client.
| context | The TLS context; borrowed, and must outlive the client. |
| config | The credentials and environment. |
| options | HTTP options. |
| store | Where to share the access token (network::TokenStore), or null to keep it to this client. |
| calendars | Where to share the trading calendar (network::CalendarCache), or null to keep it to this client. |
Definition at line 4280 of file client.hpp.
|
inline |
Uses a token issued earlier; see KisClient::adopt_token.
| token | The token. |
Definition at line 4551 of file client.hpp.
Returns bars; see KisClient::async_bars.
| query | The query. |
Definition at line 4411 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::bars().
|
inline |
Returns the account's buying power, in won.
| currency | The currency; anything but KRW is refused before sending. |
| account | The account. |
Definition at line 4440 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::buying_power().
|
inline |
Returns the trading calendar from a date on; see KisClient::async_calendar (cached).
With a calendar cache, unless refresh, a calendar the client holds that covers from is returned first, and then one the cache holds under kis-kr that is for KR, was received on today's date in Seoul and covers from; neither needs a token. Otherwise KIS is asked, and its calendar is stored in the cache if it was received on the date in Seoul the request started on. A cache that cannot be read or written changes nothing else: KIS is asked, or its calendar returned. KIS's own error is returned as it is, never a stored calendar. Clients that start together can each ask KIS; a correction KIS makes during the day is seen only with refresh.
| from | The first date; an invalid date is refused (invalid_date) before sending. |
| refresh | true to request again even if the cache covers from. |
Definition at line 4332 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::calendar().
|
inline |
Cancels an order; the outcome can be unknown after an error, and the order may still rest (see KisClient::async_cancel_order).
| account | The account. |
| amendment | The order and quantity. |
Definition at line 4491 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::cancel_order().
|
inline |
Returns the order book (ten levels a side).
| instrument | The instrument. |
Definition at line 4397 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::depth().
|
inline |
Returns the account's holdings.
| account | The account. |
Definition at line 4425 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::holdings().
|
inline |
Returns an instrument's reference data.
| subject | The instrument. |
Definition at line 4310 of file client.hpp.
Referenced by depth(), algotradelib::BrokerTraits< kis::KisBlockingClient >::instrument(), price_limits(), quote(), and trades().
|
inline |
Returns the orders that can still be amended or cancelled; see KisClient::async_open_orders (including how demo accounts are answered).
| account | The account. |
Definition at line 4506 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::working_orders().
|
inline |
Returns the orders placed over a date range, with their fills.
| account | The account. |
| range | The dates (an invalid range, or to_ before from_, is refused before sending). |
Definition at line 4521 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::order_history().
|
inline |
Places a cash order; see KisClient::async_place_order.
Never resent. After an error of unknown outcome (see KisClient::async_place_order), read open_orders() or order_history() before placing again.
| account | The account. |
| order | The order. |
Definition at line 4459 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::place_order().
|
inline |
Returns an instrument's price band for today.
| instrument | The instrument. |
Definition at line 4368 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::price_limits().
|
inline |
Returns a quote; see KisClient::async_quote.
| instrument | The instrument. |
Definition at line 4296 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::quote().
|
inline |
Returns the rate limiter's statistics (safe to read between calls).
Definition at line 4534 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::rate_limit_stats().
|
inline |
Amends an order's price or quantity; the outcome can be unknown after an error (see KisClient::async_replace_order).
| account | The account. |
| amendment | The amendment. |
Definition at line 4475 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::replace_order().
|
inline |
Returns the access token; see KisClient::token.
Definition at line 4542 of file client.hpp.
Referenced by adopt_token().
|
inline |
Returns an instrument's recent trades.
| instrument | The instrument. |
| count | The most trades to return (zero or less: the whole window). |
Definition at line 4383 of file client.hpp.
Referenced by algotradelib::BrokerTraits< kis::KisBlockingClient >::trades().
|
friend |
Definition at line 4556 of file client.hpp.