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

Blocking facade that drives TossClient on a private event loop. More...

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

Public Member Functions

 TossBlockingClient (ssl::context &context, TossConfig config, network::HttpClientOptions options={}, std::shared_ptr< network::TokenStore > store=nullptr)
 Constructs a blocking Toss Securities client.
Result< QuoteSnapshot > quote (InstrumentId instrument)
 Returns a quote for a Korean instrument (a US instrument is refused; use prices).
Result< std::vector< TossAccount > > accounts ()
 Discovers the brokerage accounts available to the current credentials.
Result< Instrument > instrument (InstrumentId subject)
 Returns static reference data for one instrument.
Result< TradingCalendar > calendar (Country country, std::optional< Date > from=std::nullopt)
 Returns the trading calendar around from for one market.
Result< PriceLimits > price_limits (InstrumentId instrument)
 Returns today's upper and lower price bound.
Result< std::vector< TradePrint > > trades (InstrumentId instrument, int count)
 Returns recent executions for one instrument.
Result< std::vector< QuoteSnapshot > > prices (std::vector< InstrumentId > instruments)
 Returns a quote for every instrument in one request.
Result< DepthSnapshot > depth (InstrumentId instrument)
 Returns the resting orders on both sides of the book.
Result< BarSeries > bars (BarQuery query)
 Returns up to count_ bars; see TossClient::async_bars.
Result< HoldingsSnapshot > holdings (std::int64_t account_sequence)
 Returns normalized positions and per-currency totals for one account.
Result< BuyingPower > buying_power (Currency currency, std::int64_t account_sequence)
 Returns what the account may spend in currency.
Result< Decimal64 > sellable_quantity (InstrumentId instrument, std::int64_t account_sequence)
 Returns how much of instrument the account may sell.
Result< CommissionSchedule > commissions (std::int64_t account_sequence)
 Returns the commission rates in force for the account.
Result< OrderAck > place_order (std::int64_t account_sequence, OrderRequest order)
 Places an order; see TossClient::async_place_order.
Result< OrderAck > replace_order (std::int64_t account_sequence, TossAmendment amendment)
 Amends an open order; the outcome can be unknown after an error. The acknowledgement carries a new id; see TossClient::async_replace_order.
Result< OrderAck > cancel_order (std::int64_t account_sequence, std::string order_id)
 Cancels an open order; the outcome can be unknown after an error. The acknowledgement carries a new id; see TossClient::async_cancel_order.
Result< OrderPage > orders (TossOrderQuery query)
 Returns one page of orders; see TossClient::async_orders for which orders are listed.
Result< OrderSnapshot > order (std::int64_t account_sequence, std::string order_id)
 Returns one order by id; see TossClient::async_order for which orders can be read.
const network::RateLimitStats * rate_limit_stats () const
 Returns the rate limiter's statistics (safe to read between calls).
TossRest token () const
 Returns the access token; see TossClient::token.
bool adopt_token (TossRest token)
 Uses a token issued earlier; see TossClient::adopt_token.

Friends

struct TossClientTestAccess

Detailed Description

Blocking facade that drives TossClient on a private event loop.

With a token store, clients on one key share one token, in this process or others (network::TokenStore): issuing a token revokes the one issued before it with the same key. 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 (Toss answers 401 token-revoked); it is not sent again. A program stopped after Toss issued a token and before it was stored leaves the old one stored until Toss refuses it.

Definition at line 3689 of file client.hpp.

Constructor & Destructor Documentation

◆ TossBlockingClient()

algotradelib::tossinvest::TossBlockingClient::TossBlockingClient ( ssl::context & context,
TossConfig config,
network::HttpClientOptions options = {},
std::shared_ptr< network::TokenStore > store = nullptr )
inline

Constructs a blocking Toss Securities client.

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

Definition at line 3698 of file client.hpp.

Member Function Documentation

◆ accounts()

Result< std::vector< TossAccount > > algotradelib::tossinvest::TossBlockingClient::accounts ( )
inline

Discovers the brokerage accounts available to the current credentials.

Returns
The result, or an error.

Definition at line 3726 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::accounts().

◆ adopt_token()

bool algotradelib::tossinvest::TossBlockingClient::adopt_token ( TossRest token)
inline

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

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

Definition at line 3995 of file client.hpp.

◆ bars()

Result< BarSeries > algotradelib::tossinvest::TossBlockingClient::bars ( BarQuery query)
inline

Returns up to count_ bars; see TossClient::async_bars.

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

Definition at line 3826 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::bars().

◆ buying_power()

Result< BuyingPower > algotradelib::tossinvest::TossBlockingClient::buying_power ( Currency currency,
std::int64_t account_sequence )
inline

Returns what the account may spend in currency.

Parameters
currencyThe currency.
account_sequenceThe account (TossAccount::sequence_).
Returns
The result, or an error.

Definition at line 3855 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::buying_power().

◆ calendar()

Result< TradingCalendar > algotradelib::tossinvest::TossBlockingClient::calendar ( Country country,
std::optional< Date > from = std::nullopt )
inline

Returns the trading calendar around from for one market.

Parameters
countryThe market.
fromThe date (empty: Toss's today).
Returns
The result, or an error.

Definition at line 3755 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::calendar().

◆ cancel_order()

Result< OrderAck > algotradelib::tossinvest::TossBlockingClient::cancel_order ( std::int64_t account_sequence,
std::string order_id )
inline

Cancels an open order; the outcome can be unknown after an error. The acknowledgement carries a new id; see TossClient::async_cancel_order.

Parameters
account_sequenceThe account (TossAccount::sequence_).
order_idToss's order id.
Returns
The result, or an error.

Definition at line 3936 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::cancel_order().

◆ commissions()

Result< CommissionSchedule > algotradelib::tossinvest::TossBlockingClient::commissions ( std::int64_t account_sequence)
inline

Returns the commission rates in force for the account.

Parameters
account_sequenceThe account (TossAccount::sequence_).
Returns
The result, or an error.

Definition at line 3884 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::commissions().

◆ depth()

Result< DepthSnapshot > algotradelib::tossinvest::TossBlockingClient::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 3812 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::depth().

◆ holdings()

Result< HoldingsSnapshot > algotradelib::tossinvest::TossBlockingClient::holdings ( std::int64_t account_sequence)
inline

Returns normalized positions and per-currency totals for one account.

Parameters
account_sequenceThe account (TossAccount::sequence_).
Returns
The result, or an error.

Definition at line 3840 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::holdings().

◆ instrument()

Result< Instrument > algotradelib::tossinvest::TossBlockingClient::instrument ( InstrumentId subject)
inline

Returns static reference data for one instrument.

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

Definition at line 3740 of file client.hpp.

Referenced by depth(), algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::instrument(), price_limits(), quote(), sellable_quantity(), and trades().

◆ order()

Result< OrderSnapshot > algotradelib::tossinvest::TossBlockingClient::order ( std::int64_t account_sequence,
std::string order_id )
inline

Returns one order by id; see TossClient::async_order for which orders can be read.

Parameters
account_sequenceThe account (TossAccount::sequence_).
order_idToss's order id.
Returns
The result, or an error.

Definition at line 3965 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::order_by_id(), and place_order().

◆ orders()

Result< OrderPage > algotradelib::tossinvest::TossBlockingClient::orders ( TossOrderQuery query)
inline

Returns one page of orders; see TossClient::async_orders for which orders are listed.

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

Definition at line 3950 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::order_history(), and algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::working_orders().

◆ place_order()

Result< OrderAck > algotradelib::tossinvest::TossBlockingClient::place_order ( std::int64_t account_sequence,
OrderRequest order )
inline

Places an order; see TossClient::async_place_order.

The outcome can be unknown after an error (see TossClient::async_place_order). With client_order_id_ set, sending the same order again within ten minutes is safe; without one, read orders() before placing again.

Parameters
account_sequenceThe account (TossAccount::sequence_).
orderThe order.
Returns
The acknowledgement or an error.

Definition at line 3904 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::place_order().

◆ price_limits()

Result< PriceLimits > algotradelib::tossinvest::TossBlockingClient::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 3769 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::price_limits().

◆ prices()

Result< std::vector< QuoteSnapshot > > algotradelib::tossinvest::TossBlockingClient::prices ( std::vector< InstrumentId > instruments)
inline

Returns a quote for every instrument in one request.

Parameters
instrumentsThe instruments.
Returns
The result, or an error.

Definition at line 3798 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::prices().

◆ quote()

Result< QuoteSnapshot > algotradelib::tossinvest::TossBlockingClient::quote ( InstrumentId instrument)
inline

Returns a quote for a Korean instrument (a US instrument is refused; use prices).

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

Definition at line 3713 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::quote().

◆ rate_limit_stats()

const network::RateLimitStats * algotradelib::tossinvest::TossBlockingClient::rate_limit_stats ( ) const
inline

Returns the rate limiter's statistics (safe to read between calls).

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

Definition at line 3978 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::rate_limit_stats().

◆ replace_order()

Result< OrderAck > algotradelib::tossinvest::TossBlockingClient::replace_order ( std::int64_t account_sequence,
TossAmendment amendment )
inline

Amends an open order; the outcome can be unknown after an error. The acknowledgement carries a new id; see TossClient::async_replace_order.

Parameters
account_sequenceThe account (TossAccount::sequence_).
amendmentThe amendment.
Returns
The result, or an error.

Definition at line 3920 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::replace_order().

◆ sellable_quantity()

Result< Decimal64 > algotradelib::tossinvest::TossBlockingClient::sellable_quantity ( InstrumentId instrument,
std::int64_t account_sequence )
inline

Returns how much of instrument the account may sell.

Parameters
instrumentThe instrument.
account_sequenceThe account (TossAccount::sequence_).
Returns
The result, or an error.

Definition at line 3870 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::sellable_quantity().

◆ token()

TossRest algotradelib::tossinvest::TossBlockingClient::token ( ) const
inline

Returns the access token; see TossClient::token.

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

Definition at line 3986 of file client.hpp.

Referenced by adopt_token().

◆ trades()

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

Returns recent executions for one instrument.

Parameters
instrumentThe instrument.
countThe most trades to return, clamped to 1-50 (today's trades only).
Returns
The result, or an error.

Definition at line 3784 of file client.hpp.

Referenced by algotradelib::BrokerTraits< tossinvest::TossBlockingClient >::trades().

◆ TossClientTestAccess

friend struct TossClientTestAccess
friend

Definition at line 4000 of file client.hpp.


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