algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::kiwoom::KiwoomBlockingClient Class Reference

A blocking Kiwoom client: each call runs a KiwoomClient request on a private event loop and returns its result. Not thread-safe. Order references work with either client. More...

#include <algotradelib/src/brokers/kiwoom/client.hpp>

Public Member Functions

 KiwoomBlockingClient (ssl::context &context, KiwoomConfig config, network::HttpClientOptions options={}, std::shared_ptr< network::TokenStore > store=nullptr)
 Constructs a client.
Result< QuoteSnapshot > quote (InstrumentId instrument)
 Returns the current normalized quote or a structured error.
Result< PriceLimits > price_limits (InstrumentId instrument)
 Returns today's upper and lower price bound.
Result< DepthSnapshot > depth (InstrumentId instrument)
 Returns the resting orders on both sides of the book.
Result< std::vector< TradePrint > > trades (InstrumentId instrument, int count)
 Returns recent executions, newest first.
Result< Instrument > instrument (InstrumentId subject)
 Returns static reference data for one instrument.
Result< BarSeries > bars (BarQuery query)
 Returns bars; see KiwoomClient::async_bars.
const KiwoomConfig & config () const noexcept
 Returns the configuration; see KiwoomClient::config.
Result< HoldingsSnapshot > holdings (KiwoomAccount account)
 Returns the holdings for KiwoomConfig::holdings_venue_; see KiwoomClient::async_holdings.
Result< BuyingPower > buying_power (Currency currency, KiwoomAccount account)
 Returns what the bound credential's account may spend.
Result< KiwoomDeposit > deposit ()
 Returns Kiwoom's own fuller deposit detail.
Result< KiwoomOrderableAmount > orderable_amount (InstrumentId instrument, OrderSide side, std::optional< Decimal64 > price=std::nullopt)
 Returns what may be ordered of one instrument, per margin tier.
Result< std::vector< KiwoomAccountInfo > > accounts ()
 Returns the one account the bound credential drives.
Result< KiwoomOrderAck > place_order (KiwoomAccount account, OrderRequest order)
 Submits a new order. The outcome can be unknown after an error; see KiwoomClient::async_place_order.
Result< KiwoomOrderAck > replace_order (KiwoomAccount account, KiwoomAmendment amendment)
 Modifies an existing order. The outcome can be unknown after an error; see KiwoomClient::async_replace_order.
Result< KiwoomOrderAck > cancel_order (KiwoomAccount account, KiwoomAmendment amendment)
 Cancels an existing order. The outcome can be unknown after an error; see KiwoomClient::async_cancel_order.
Result< KiwoomOpenOrderPage > open_orders (KiwoomAccount account)
 Returns every order still open to amendment.
Result< OrderPage > order_history (KiwoomAccount account, KiwoomHistoryQuery query)
 Returns one day of order history.
void close ()
 Closes the client for good; see KiwoomClient::close.
const network::RateLimitStats * rate_limit_stats () const
 Returns the rate limiter's statistics.
KiwoomRest token () const
 Returns the access token; see KiwoomClient::token.
bool adopt_token (KiwoomRest token)
 Uses a token issued earlier; see KiwoomClient::adopt_token.

Friends

struct KiwoomClientTestAccess

Detailed Description

A blocking Kiwoom client: each call runs a KiwoomClient request on a private event loop and returns its result. Not thread-safe. Order references work with either client.

A call whose loop stops before the request completes returns a TRANSPORT error (event_loop_stopped).

With a token store, clients on one key and environment share one token, in this process or others (network::TokenStore); a Kiwoom token is bound to the address that requested it, so share it on one machine only. 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 Kiwoom issued a token and before it was stored leaves the old one stored until Kiwoom refuses it.

Definition at line 3644 of file client.hpp.

Constructor & Destructor Documentation

◆ KiwoomBlockingClient()

algotradelib::kiwoom::KiwoomBlockingClient::KiwoomBlockingClient ( ssl::context & context,
KiwoomConfig config,
network::HttpClientOptions options = {},
std::shared_ptr< network::TokenStore > store = nullptr )
inline

Constructs a client.

Parameters
contextThe TLS context; borrowed, and must outlive the client.
configThe credentials and environment.
optionsHTTP options.
storeWhere to share the access token (network::TokenStore), or null to keep it to this client.

Definition at line 3653 of file client.hpp.

Member Function Documentation

◆ accounts()

Result< std::vector< KiwoomAccountInfo > > algotradelib::kiwoom::KiwoomBlockingClient::accounts ( )
inline

Returns the one account the bound credential drives.

Returns
The result, or an error.

Definition at line 3820 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::accounts().

◆ adopt_token()

bool algotradelib::kiwoom::KiwoomBlockingClient::adopt_token ( KiwoomRest token)
inline

Uses a token issued earlier; see KiwoomClient::adopt_token.

Parameters
tokenThe token.
Returns
false if the token is empty or expires within five minutes.

Definition at line 3936 of file client.hpp.

◆ bars()

Result< BarSeries > algotradelib::kiwoom::KiwoomBlockingClient::bars ( BarQuery query)
inline

Returns bars; see KiwoomClient::async_bars.

Parameters
queryThe query.
Returns
The result, or an error.

Definition at line 3739 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::bars().

◆ buying_power()

Result< BuyingPower > algotradelib::kiwoom::KiwoomBlockingClient::buying_power ( Currency currency,
KiwoomAccount account )
inline

Returns what the bound credential's account may spend.

Parameters
currencyThe currency; anything but KRW is refused before sending.
accountThe bound account.
Returns
The result, or an error.

Definition at line 3776 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::buying_power().

◆ cancel_order()

Result< KiwoomOrderAck > algotradelib::kiwoom::KiwoomBlockingClient::cancel_order ( KiwoomAccount account,
KiwoomAmendment amendment )
inline

Cancels an existing order. The outcome can be unknown after an error; see KiwoomClient::async_cancel_order.

Parameters
accountThe bound account.
amendmentThe amendment.
Returns
The result, or an error.

Definition at line 3868 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::cancel_order().

◆ close()

void algotradelib::kiwoom::KiwoomBlockingClient::close ( )
inline

Closes the client for good; see KiwoomClient::close.

Definition at line 3907 of file client.hpp.

◆ config()

const KiwoomConfig & algotradelib::kiwoom::KiwoomBlockingClient::config ( ) const
inlinenoexcept

Returns the configuration; see KiwoomClient::config.

Returns
The configuration.

Definition at line 3752 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::holdings(), and KiwoomBlockingClient().

◆ deposit()

Result< KiwoomDeposit > algotradelib::kiwoom::KiwoomBlockingClient::deposit ( )
inline

Returns Kiwoom's own fuller deposit detail.

Returns
The result, or an error.

Definition at line 3789 of file client.hpp.

◆ depth()

Result< DepthSnapshot > algotradelib::kiwoom::KiwoomBlockingClient::depth ( InstrumentId instrument)
inline

Returns the resting orders on both sides of the book.

Parameters
instrumentThe instrument.
Returns
The result, or an error.

Definition at line 3696 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::depth().

◆ holdings()

Result< HoldingsSnapshot > algotradelib::kiwoom::KiwoomBlockingClient::holdings ( KiwoomAccount account)
inline

Returns the holdings for KiwoomConfig::holdings_venue_; see KiwoomClient::async_holdings.

Parameters
accountThe account (empty).
Returns
The result, or an error.

Definition at line 3761 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::holdings().

◆ instrument()

Result< Instrument > algotradelib::kiwoom::KiwoomBlockingClient::instrument ( InstrumentId subject)
inline

Returns static reference data for one instrument.

Parameters
subjectThe instrument.
Returns
The result, or an error.

Definition at line 3725 of file client.hpp.

Referenced by depth(), algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::instrument(), orderable_amount(), price_limits(), quote(), and trades().

◆ open_orders()

Result< KiwoomOpenOrderPage > algotradelib::kiwoom::KiwoomBlockingClient::open_orders ( KiwoomAccount account)
inline

Returns every order still open to amendment.

Parameters
accountThe bound account.
Returns
The result, or an error.

Definition at line 3882 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::working_orders().

◆ order_history()

Result< OrderPage > algotradelib::kiwoom::KiwoomBlockingClient::order_history ( KiwoomAccount account,
KiwoomHistoryQuery query )
inline

Returns one day of order history.

Parameters
accountThe bound account.
queryThe query.
Returns
The result, or an error.

Definition at line 3897 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::order_history().

◆ orderable_amount()

Result< KiwoomOrderableAmount > algotradelib::kiwoom::KiwoomBlockingClient::orderable_amount ( InstrumentId instrument,
OrderSide side,
std::optional< Decimal64 > price = std::nullopt )
inline

Returns what may be ordered of one instrument, per margin tier.

Parameters
instrumentThe instrument.
sideThe side.
priceThe unit price to evaluate at (uv), or empty to send none.
Returns
The result, or an error.

Definition at line 3805 of file client.hpp.

◆ place_order()

Result< KiwoomOrderAck > algotradelib::kiwoom::KiwoomBlockingClient::place_order ( KiwoomAccount account,
OrderRequest order )
inline

Submits a new order. The outcome can be unknown after an error; see KiwoomClient::async_place_order.

Parameters
accountThe bound account.
orderThe order.
Returns
The result, or an error.

Definition at line 3836 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::place_order().

◆ price_limits()

Result< PriceLimits > algotradelib::kiwoom::KiwoomBlockingClient::price_limits ( InstrumentId instrument)
inline

Returns today's upper and lower price bound.

Parameters
instrumentThe instrument.
Returns
The result, or an error.

Definition at line 3682 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::price_limits().

◆ quote()

Result< QuoteSnapshot > algotradelib::kiwoom::KiwoomBlockingClient::quote ( InstrumentId instrument)
inline

Returns the current normalized quote or a structured error.

Parameters
instrumentThe instrument.
Returns
The result, or an error.

Definition at line 3668 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::quote().

◆ rate_limit_stats()

const network::RateLimitStats * algotradelib::kiwoom::KiwoomBlockingClient::rate_limit_stats ( ) const
inline

Returns the rate limiter's statistics.

Read them on the client's strand or while no request is in progress (between calls on the blocking client).

Returns
The statistics, or null if the client has no rate-limit budget.

Definition at line 3919 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::rate_limit_stats().

◆ replace_order()

Result< KiwoomOrderAck > algotradelib::kiwoom::KiwoomBlockingClient::replace_order ( KiwoomAccount account,
KiwoomAmendment amendment )
inline

Modifies an existing order. The outcome can be unknown after an error; see KiwoomClient::async_replace_order.

Parameters
accountThe bound account.
amendmentThe amendment.
Returns
The result, or an error.

Definition at line 3852 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::replace_order().

◆ token()

KiwoomRest algotradelib::kiwoom::KiwoomBlockingClient::token ( ) const
inline

Returns the access token; see KiwoomClient::token.

Returns
The token, empty until a request has obtained one.

Definition at line 3927 of file client.hpp.

Referenced by adopt_token().

◆ trades()

Result< std::vector< TradePrint > > algotradelib::kiwoom::KiwoomBlockingClient::trades ( InstrumentId instrument,
int count )
inline

Returns recent executions, newest first.

Parameters
instrumentThe instrument.
countThe most trades to return.
Returns
The result, or an error.

Definition at line 3711 of file client.hpp.

Referenced by algotradelib::BrokerTraits< kiwoom::KiwoomBlockingClient >::trades().

◆ KiwoomClientTestAccess

friend struct KiwoomClientTestAccess
friend

Definition at line 3941 of file client.hpp.


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