algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
traits.hpp
1#pragma once
2
8#define ATL_BROKER_ADAPTER_PRESENT 1
9
10#include "./client.hpp"
11
12#include "../../core/broker_session.hpp"
13#include "../../core/broker_traits.hpp"
14
15#include <cstdint>
16#include <optional>
17#include <string>
18#include <utility>
19
20namespace algotradelib {
21
22namespace tossinvest {
23
28struct Broker {
30 static constexpr std::string_view name = "tossinvest";
31};
32
33namespace traits_detail {
34
37
39struct Normalizers {
41 static constexpr bool has_depth = true;
42
44 static constexpr bool has_price_limits = true;
45
47 static constexpr bool has_trade_prints = true;
48
50 static constexpr bool has_batch_prices = true;
51
53 static constexpr bool has_buying_power = true;
54
56 static constexpr bool has_buying_power_quantity = false;
57
62 static constexpr SellableSource sellable_source = SellableSource::INQUIRY;
63
72 static constexpr SellableBasis sellable_inquiry_basis{
75 false,
76 };
77
79 static constexpr bool has_commission_schedule = true;
80
82 static constexpr bool has_reference_data = true;
83
85 static constexpr bool has_batch_reference_data = true;
86
88 static constexpr bool has_calendar = true;
89
91 static constexpr bool has_calendar_range = false;
92
94 static constexpr bool has_calendar_sessions = false;
95
101 static std::optional<BrokerError> validate_calendar(Country, std::optional<Date> from) {
102 if (!from || is_valid_date(*from)) {
103 return std::nullopt;
104 }
105 BrokerError error;
107 error.reached_broker_ = false;
108 error.broker_code_ = "invalid_date";
109 error.message_ = "calendar request requires a valid Gregorian date";
110 return error;
111 }
112
118 static constexpr bool supports_interval(BarInterval interval) {
119 static_cast<void>(interval);
120 return interval == BarInterval::ONE_MINUTE || interval == BarInterval::ONE_DAY;
121 }
122
128 static std::optional<BrokerError> validate_bars(const BarQuery& query) {
130 }
131
137 static Ref make_ref(std::string order_id) {
138 Ref ref;
139 ref.primary_ = std::move(order_id);
140 return ref;
141 }
142
149 static std::optional<BrokerError> validate_place(const OrderRequest&) {
150 return std::nullopt;
151 }
152
158 static Result<PlacedOrder<tossinvest::Broker>> normalize_place(Result<OrderAck> raw) {
159 if (!raw) {
160 return Result<PlacedOrder<tossinvest::Broker>>(std::move(raw.error()));
161 }
163 placed.ref_ = make_ref(raw.value().order_id_);
164 placed.ack_ = std::move(raw.value());
165 return Result<PlacedOrder<tossinvest::Broker>>(std::move(placed));
166 }
167
174 static Result<WorkingOrders<tossinvest::Broker>> normalize_working_orders(Result<OrderPage> raw) {
175 if (!raw) {
176 return Result<WorkingOrders<tossinvest::Broker>>(std::move(raw.error()));
177 }
179 orders.received_at_ = raw.value().received_at_;
180 orders.orders_.reserve(raw.value().orders_.size());
181 for (auto& order : raw.value().orders_) {
183 working.ref_ = make_ref(order.order_id_);
184 working.order_ = std::move(order);
185 orders.orders_.push_back(std::move(working));
186 }
187 return Result<WorkingOrders<tossinvest::Broker>>(std::move(orders));
188 }
189
203 static Result<tossinvest::TossAmendment> to_replacement(const Ref& ref, const AmendInstruction& instruction) {
204 // Toss's `OrderModifyRequest` carries `orderType`, `quantity`, `price` and
205 // the high-value flag, and **no validity field at all**: a modification
206 // cannot change the condition or the session, and Toss cannot refuse a
207 // request to. So this refuses on Toss's behalf, and the question is not
208 // whether the requested value is one Toss supports -- it can place a
209 // closing-auction order -- but whether it *differs* from what the order
210 // already is.
211 //
212 // Which means the original has to be known. An unset `resting_` is refused
213 // rather than assumed to match: a hand-built instruction naming DAY/REGULAR
214 // against a resting CLS order compared equal to a defaulted original and was
215 // sent, and the order stayed CLS while the caller was told it had moved.
216 if (!instruction.resting_) {
217 BrokerError error;
219 error.reached_broker_ = false;
220 error.broker_code_ = "unknown_resting_shape";
221 error.message_ =
222 "Toss cannot change an order's validity condition or session by amending it, and this "
223 "instruction does not say what the order's are, so neither can be verified; build the "
224 "instruction with reprice() or replace_with() from the working order";
225 return Result<tossinvest::TossAmendment>(std::move(error));
226 }
227 // An unset field on the shape asks for no change, which is always safe here.
228 if (
229 instruction.shape_.time_in_force_ && *instruction.shape_.time_in_force_ != instruction.resting_->time_in_force_
230 ) {
231 BrokerError error;
233 error.reached_broker_ = false;
234 error.broker_code_ = "unsupported_time_in_force";
235 error.message_ =
236 "Toss cannot change an order's validity condition by amending it; cancel the order and "
237 "place a new one instead";
238 return Result<tossinvest::TossAmendment>(std::move(error));
239 }
240 if (instruction.shape_.session_ && *instruction.shape_.session_ != instruction.resting_->session_) {
241 BrokerError error;
243 error.reached_broker_ = false;
244 error.broker_code_ = "unsupported_session";
245 error.message_ =
246 "Toss cannot move an order to another trading session by amending it; cancel the order "
247 "and place a new one instead";
248 return Result<tossinvest::TossAmendment>(std::move(error));
249 }
250
252 amendment.order_id_ = ref.primary_;
253 amendment.type_ = instruction.shape_.type_;
254 amendment.quantity_ = instruction.quantity_;
255 amendment.price_ = instruction.shape_.price_;
256 amendment.confirm_high_value_ = instruction.confirm_high_value_;
257 return Result<tossinvest::TossAmendment>(std::move(amendment));
258 }
259
269 static Result<tossinvest::TossAmendment> to_cancellation(const Ref& ref, const AmendInstruction& instruction) {
270 if (!instruction.all_remaining_) {
271 BrokerError error;
273 error.reached_broker_ = false;
274 error.broker_code_ = "partial_cancel_unsupported";
275 error.message_ =
276 "Toss cancels an order in full; use cancel_all() or modify the order to a smaller "
277 "quantity instead of cancelling part of it";
278 return Result<tossinvest::TossAmendment>(std::move(error));
279 }
281 amendment.order_id_ = ref.primary_;
282 return Result<tossinvest::TossAmendment>(std::move(amendment));
283 }
284
292 static Result<tossinvest::TossOrderQuery> to_history_query(
293 std::int64_t account_sequence, const OrderHistoryQuery& query
294 ) {
296 converted.account_sequence_ = account_sequence;
298 converted.symbol_ = query.symbol_;
299 converted.from_ = query.from_;
300 converted.to_ = query.to_;
301 converted.cursor_ = query.cursor_;
302 converted.limit_ = query.limit_;
303 return Result<tossinvest::TossOrderQuery>(std::move(converted));
304 }
305
311 static tossinvest::TossOrderQuery open_query(std::int64_t account_sequence) {
313 query.account_sequence_ = account_sequence;
315 return query;
316 }
317
323 static std::int64_t selector_of(const tossinvest::TossAccount& account) {
324 return account.sequence_;
325 }
326
332 static std::string display_of(const tossinvest::TossAccount& account) {
333 return account.account_number_;
334 }
335
341 static std::string type_of(const tossinvest::TossAccount& account) {
342 return account.account_type_;
343 }
344
346 static std::int64_t no_account() {
347 return 0;
348 }
349};
350
352struct Capabilities {
354 static constexpr bool has_account_discovery = true;
355
357 static constexpr bool has_client_order_id = true;
358
363 static constexpr bool has_trigger_price = false;
364
366 static constexpr bool data_only = false;
367
372 static constexpr bool has_working_orders = true;
373
375 static constexpr bool has_amendable_quantity = false;
376
381 static constexpr bool working_orders_state_terminal = false;
382
384 static constexpr bool has_order_by_id = true;
385
387 static constexpr bool has_partial_cancel = false;
388
390 static constexpr bool history_requires_range = false;
391
393 static constexpr bool has_history_cursor = true;
394
396 static constexpr bool has_history_limit = true;
397
399 static constexpr bool has_history_symbol_filter = true;
400};
401
402} // namespace traits_detail
403} // namespace tossinvest
404
406template <>
407struct BrokerTraits<tossinvest::TossClient>
408: tossinvest::traits_detail::Normalizers, tossinvest::traits_detail::Capabilities {
417 static constexpr Venue effective_route(Venue) noexcept {
418 return Venue::UNSPECIFIED;
419 }
420
423
426
428 using Account = std::int64_t;
429
432
435
438
441
444
447
449 static constexpr std::string_view name = tossinvest::Broker::name;
450
452 static constexpr bool blocking = false;
453
459 static const network::RateLimitStats* rate_limit_stats(const Client& client) {
460 return client.rate_limit_stats();
461 }
462
471 template <typename Token>
472 static auto instrument(Client& client, InstrumentId subject, Token&& token) {
473 return client.async_instrument(std::move(subject), std::forward<Token>(token));
474 }
475
485 template <typename Token>
486 static auto calendar(Client& client, Country country, std::optional<Date> from, Token&& token) {
487 return client.async_calendar(country, from, std::forward<Token>(token));
488 }
489
498 template <typename Token>
499 static auto price_limits(Client& client, InstrumentId instrument, Token&& token) {
500 return client.async_price_limits(std::move(instrument), std::forward<Token>(token));
501 }
502
512 template <typename Token>
513 static auto trades(Client& client, InstrumentId instrument, int count, Token&& token) {
514 return client.async_trades(std::move(instrument), count, std::forward<Token>(token));
515 }
516
525 template <typename Token>
526 static auto prices(Client& client, std::vector<InstrumentId> instruments, Token&& token) {
527 return client.async_prices(std::move(instruments), std::forward<Token>(token));
528 }
529
538 template <typename Token>
539 static auto depth(Client& client, InstrumentId instrument, Token&& token) {
540 return client.async_depth(std::move(instrument), std::forward<Token>(token));
541 }
542
551 template <typename Token>
552 static auto bars(Client& client, BarQuery query, Token&& token) {
553 return client.async_bars(std::move(query), std::forward<Token>(token));
554 }
555
564 template <typename Token>
565 static auto quote(Client& client, InstrumentId instrument, Token&& token) {
566 return client.async_quote(std::move(instrument), std::forward<Token>(token));
567 }
568
576 template <typename Token>
577 static auto accounts(Client& client, Token&& token) {
578 return client.async_accounts(std::forward<Token>(token));
579 }
580
590 template <typename Token>
591 static auto buying_power(Client& client, const Account& account, Currency currency, Token&& token) {
592 return client.async_buying_power(currency, account, std::forward<Token>(token));
593 }
594
604 template <typename Token>
605 static auto sellable_quantity(Client& client, const Account& account, InstrumentId instrument, Token&& token) {
606 return client.async_sellable_quantity(std::move(instrument), account, std::forward<Token>(token));
607 }
608
617 template <typename Token>
618 static auto commissions(Client& client, const Account& account, Token&& token) {
619 return client.async_commissions(account, std::forward<Token>(token));
620 }
621
630 template <typename Token>
631 static auto holdings(Client& client, const Account& account, Token&& token) {
632 return client.async_holdings(account, std::forward<Token>(token));
633 }
634
644 template <typename Token>
645 static auto place_order(Client& client, const Account& account, OrderRequest order, Token&& token) {
646 return client.async_place_order(account, std::move(order), std::forward<Token>(token));
647 }
648
658 template <typename Token>
659 static auto replace_order(Client& client, const Account& account, Amendment amendment, Token&& token) {
660 return client.async_replace_order(account, std::move(amendment), std::forward<Token>(token));
661 }
662
672 template <typename Token>
673 static auto cancel_order(Client& client, const Account& account, Amendment amendment, Token&& token) {
674 return client.async_cancel_order(account, std::move(amendment.order_id_), std::forward<Token>(token));
675 }
676
685 template <typename Token>
686 static auto working_orders(Client& client, const Account& account, Token&& token) {
687 return client.async_orders(open_query(account), std::forward<Token>(token));
688 }
689
699 template <typename Token>
700 static auto order_history(Client& client, const Account& account, HistoryQuery query, Token&& token) {
701 static_cast<void>(account);
702 return client.async_orders(std::move(query), std::forward<Token>(token));
703 }
704
714 template <typename Token>
715 static auto order_by_id(Client& client, const Account& account, std::string order_id, Token&& token) {
716 return client.async_order(account, std::move(order_id), std::forward<Token>(token));
717 }
718};
719
721template <>
722struct BrokerTraits<tossinvest::TossBlockingClient>
723: tossinvest::traits_detail::Normalizers, tossinvest::traits_detail::Capabilities {
732 static constexpr Venue effective_route(Venue) noexcept {
733 return Venue::UNSPECIFIED;
734 }
735
738
741
743 using Account = std::int64_t;
744
747
750
753
756
759
762
764 static constexpr std::string_view name = tossinvest::Broker::name;
765
767 static constexpr bool blocking = true;
768
774 static const network::RateLimitStats* rate_limit_stats(const Client& client) {
775 return client.rate_limit_stats();
776 }
777
785 return client.instrument(std::move(subject));
786 }
787
795 static Result<TradingCalendar> calendar(Client& client, Country country, std::optional<Date> from) {
796 return client.calendar(country, from);
797 }
798
806 return client.price_limits(std::move(instrument));
807 }
808
817 return client.trades(std::move(instrument), count);
818 }
819
826 static Result<std::vector<QuoteSnapshot>> prices(Client& client, std::vector<InstrumentId> instruments) {
827 return client.prices(std::move(instruments));
828 }
829
837 return client.depth(std::move(instrument));
838 }
839
846 static Result<BarSeries> bars(Client& client, BarQuery query) {
847 return client.bars(std::move(query));
848 }
849
857 return client.quote(std::move(instrument));
858 }
859
866 return client.accounts();
867 }
868
875 static Result<HoldingsSnapshot> holdings(Client& client, const Account& account) {
876 return client.holdings(account);
877 }
878
886 static Result<BuyingPower> buying_power(Client& client, const Account& account, Currency currency) {
887 return client.buying_power(currency, account);
888 }
889
898 return client.sellable_quantity(std::move(instrument), account);
899 }
900
907 static Result<CommissionSchedule> commissions(Client& client, const Account& account) {
908 return client.commissions(account);
909 }
910
918 static Result<PlaceAck> place_order(Client& client, const Account& account, OrderRequest order) {
919 return client.place_order(account, std::move(order));
920 }
921
929 static Result<PlaceAck> replace_order(Client& client, const Account& account, Amendment amendment) {
930 return client.replace_order(account, std::move(amendment));
931 }
932
940 static Result<PlaceAck> cancel_order(Client& client, const Account& account, Amendment amendment) {
941 return client.cancel_order(account, std::move(amendment.order_id_));
942 }
943
951 return client.orders(open_query(account));
952 }
953
961 static Result<OrderPage> order_history(Client& client, const Account& account, HistoryQuery query) {
962 static_cast<void>(account);
963 return client.orders(std::move(query));
964 }
965
974 static Result<OrderSnapshot> order_by_id(Client& client, const Account& account, std::string order_id) {
975 return client.order(account, std::move(order_id));
976 }
977};
978
979} // namespace algotradelib
A three-letter currency code, such as KRW or USD (ISO 4217 style).
Definition types.hpp:374
Either a value or a BrokerError.
Definition types.hpp:1058
BrokerError & error()
Returns the error.
Definition types.hpp:1111
T & value()
Returns the value.
Definition types.hpp:1093
Blocking facade that drives TossClient on a private event loop.
Definition client.hpp:3689
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...
Definition client.hpp:3920
Result< BuyingPower > buying_power(Currency currency, std::int64_t account_sequence)
Returns what the account may spend in currency.
Definition client.hpp:3855
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics (safe to read between calls).
Definition client.hpp:3978
Result< Decimal64 > sellable_quantity(InstrumentId instrument, std::int64_t account_sequence)
Returns how much of instrument the account may sell.
Definition client.hpp:3870
Result< OrderPage > orders(TossOrderQuery query)
Returns one page of orders; see TossClient::async_orders for which orders are listed.
Definition client.hpp:3950
Result< Instrument > instrument(InstrumentId subject)
Returns static reference data for one instrument.
Definition client.hpp:3740
Result< OrderAck > place_order(std::int64_t account_sequence, OrderRequest order)
Places an order; see TossClient::async_place_order.
Definition client.hpp:3904
Result< DepthSnapshot > depth(InstrumentId instrument)
Returns the resting orders on both sides of the book.
Definition client.hpp:3812
Result< HoldingsSnapshot > holdings(std::int64_t account_sequence)
Returns normalized positions and per-currency totals for one account.
Definition client.hpp:3840
Result< std::vector< QuoteSnapshot > > prices(std::vector< InstrumentId > instruments)
Returns a quote for every instrument in one request.
Definition client.hpp:3798
Result< QuoteSnapshot > quote(InstrumentId instrument)
Returns a quote for a Korean instrument (a US instrument is refused; use prices).
Definition client.hpp:3713
Result< CommissionSchedule > commissions(std::int64_t account_sequence)
Returns the commission rates in force for the account.
Definition client.hpp:3884
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 i...
Definition client.hpp:3936
Result< PriceLimits > price_limits(InstrumentId instrument)
Returns today's upper and lower price bound.
Definition client.hpp:3769
Result< std::vector< TradePrint > > trades(InstrumentId instrument, int count)
Returns recent executions for one instrument.
Definition client.hpp:3784
Result< std::vector< TossAccount > > accounts()
Discovers the brokerage accounts available to the current credentials.
Definition client.hpp:3726
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.
Definition client.hpp:3965
Result< BarSeries > bars(BarQuery query)
Returns up to count_ bars; see TossClient::async_bars.
Definition client.hpp:3826
Result< TradingCalendar > calendar(Country country, std::optional< Date > from=std::nullopt)
Returns the trading calendar around from for one market.
Definition client.hpp:3755
The asynchronous Toss Securities REST client: market data, accounts and orders.
Definition client.hpp:149
auto async_commissions(std::int64_t account_sequence, CompletionToken &&token)
Requests the commission rates in force for the account.
Definition client.hpp:480
auto async_instrument(InstrumentId instrument, CompletionToken &&token)
Requests static reference data for one instrument.
Definition client.hpp:270
auto async_orders(TossOrderQuery query, CompletionToken &&token)
Requests a page of orders.
Definition client.hpp:629
auto async_trades(InstrumentId instrument, int count, CompletionToken &&token)
Requests recent executions for one instrument, newest first.
Definition client.hpp:319
auto async_quote(InstrumentId instrument, CompletionToken &&token)
Requests a quote for a Korean instrument (a US instrument is refused before sending; use async_prices...
Definition client.hpp:394
auto async_bars(BarQuery query, CompletionToken &&token)
Requests up to count_ bars, oldest first.
Definition client.hpp:227
auto async_holdings(std::int64_t account_sequence, CompletionToken &&token)
Requests and normalizes holdings for one discovered account sequence.
Definition client.hpp:500
auto async_accounts(CompletionToken &&token)
Discovers the brokerage accounts available to the current credentials.
Definition client.hpp:415
auto async_cancel_order(std::int64_t account_sequence, std::string order_id, CompletionToken &&token)
Cancels an open order.
Definition client.hpp:598
auto async_place_order(std::int64_t account_sequence, OrderRequest order, CompletionToken &&token)
Places an order.
Definition client.hpp:536
auto async_depth(InstrumentId instrument, CompletionToken &&token)
Requests and normalizes the resting orders on both sides of the book.
Definition client.hpp:371
auto async_buying_power(Currency currency, std::int64_t account_sequence, CompletionToken &&token)
Requests the account's buying power in a currency.
Definition client.hpp:436
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics.
Definition client.hpp:678
auto async_calendar(Country country, std::optional< Date > from, CompletionToken &&token)
Requests the trading calendar around a date: that date and the business days either side of it (three...
Definition client.hpp:250
auto async_prices(std::vector< InstrumentId > instruments, CompletionToken &&token)
Quotes up to 200 instruments in one request.
Definition client.hpp:349
auto async_price_limits(InstrumentId instrument, CompletionToken &&token)
Requests today's upper and lower price bound for one instrument.
Definition client.hpp:294
auto async_order(std::int64_t account_sequence, std::string order_id, CompletionToken &&token)
Requests one order by id, in any state.
Definition client.hpp:655
auto async_sellable_quantity(InstrumentId instrument, std::int64_t account_sequence, CompletionToken &&token)
Requests how much of one instrument the account may sell.
Definition client.hpp:457
auto async_replace_order(std::int64_t account_sequence, TossAmendment amendment, CompletionToken &&token)
Amends an open order's price, and for a Korean order its quantity.
Definition client.hpp:568
Placeholder types and the refusal used by DataOnlyTraits.
The Toss Securities Open API client.
Definition auth.hpp:9
std::optional< BrokerError > unsupported_bar_interval(BarInterval interval)
Refuses a bar interval Toss does not publish (it publishes one-minute and one-day bars only; nothing ...
Definition client.hpp:124
@ CLOSED
Ended orders (including a partly filled order that ended).
Definition client.hpp:46
@ OPEN
Open orders: pending, partly filled, or with an amendment or cancellation pending.
Definition client.hpp:44
The library: broker-neutral types (core), and the modules below.
SellableSource
Where the library gets a broker's sellable quantity.
Definition types.hpp:1362
@ INQUIRY
From a per-instrument inquiry, made only where the snapshot has no figure.
Definition types.hpp:1366
@ INVALID_ARGUMENT
The request was invalid, refused by the client before sending or by the broker.
Definition types.hpp:974
Country
A country (market) the library supports.
Definition types.hpp:32
Venue
A trading venue: an exchange, or the combined view across exchanges.
Definition types.hpp:45
BarInterval
The period one bar covers.
bool is_valid_date(const Date &date)
Tests whether a date exists in the Gregorian calendar, in years 1 to 9999.
Definition types.hpp:1480
A modification or cancellation of a working order.
Definition types.hpp:2532
bool confirm_high_value_
Confirms a high-value amendment, where the broker asks for that confirmation.
Definition types.hpp:2546
std::optional< OrderShape > resting_
The shape the order has now, or unset if unknown.
Definition types.hpp:2553
std::optional< Decimal64 > quantity_
The quantity affected; never substituted if a broker needs one and it is missing.
Definition types.hpp:2542
OrderShape shape_
The shape the order should have afterwards.
Definition types.hpp:2534
bool all_remaining_
Whether the whole remaining quantity is affected, rather than quantity_.
Definition types.hpp:2544
What bars to fetch.
BarInterval interval_
The period of each bar; an interval the broker does not publish is refused.
The error a broker or transport operation returns.
Definition types.hpp:1003
std::string message_
A human-readable description, for logs; do not parse it.
Definition types.hpp:1033
ErrorCategory category_
The kind of failure; the field to branch on.
Definition types.hpp:1005
std::string broker_code_
The broker's own error code, verbatim (for example KIS's EGW00201).
Definition types.hpp:1022
bool reached_broker_
Whether a request was sent before this error.
Definition types.hpp:1014
static Result< OrderPage > order_history(Client &client, const Account &account, HistoryQuery query)
Returns the CLOSED listing for the bound account.
Definition traits.hpp:961
static Result< PriceLimits > price_limits(Client &client, InstrumentId instrument)
Returns today's price bounds.
Definition traits.hpp:805
static Result< TradingCalendar > calendar(Client &client, Country country, std::optional< Date > from)
Returns the calendar for one market.
Definition traits.hpp:795
static Result< CommissionSchedule > commissions(Client &client, const Account &account)
Returns the commission rates in force for the bound account.
Definition traits.hpp:907
tossinvest::TossBlockingClient Client
The client type.
Definition traits.hpp:737
static Result< HoldingsSnapshot > holdings(Client &client, const Account &account)
Returns holdings for the bound account.
Definition traits.hpp:875
static Result< DepthSnapshot > depth(Client &client, InstrumentId instrument)
Returns the order book.
Definition traits.hpp:836
static Result< BarSeries > bars(Client &client, BarQuery query)
Returns bars, paging inside the client.
Definition traits.hpp:846
static constexpr bool blocking
true: requests return their result directly.
Definition traits.hpp:767
static Result< PlaceAck > cancel_order(Client &client, const Account &account, Amendment amendment)
Cancels an order for the bound account, transmitting the identifier only.
Definition traits.hpp:940
tossinvest::TossOrderQuery HistoryQuery
The order-history query type.
Definition traits.hpp:755
OrderPage WorkingOrdersResult
The working-order result type.
Definition traits.hpp:758
OrderAck PlaceAck
The order acknowledgement type.
Definition traits.hpp:749
static constexpr Venue effective_route(Venue) noexcept
Returns the venue a Toss order reaches: none in particular (Toss does not route by venue,...
Definition traits.hpp:732
static const network::RateLimitStats * rate_limit_stats(const Client &client)
Returns this client's pacing statistics, or null when it is unpaced.
Definition traits.hpp:774
static Result< PlaceAck > replace_order(Client &client, const Account &account, Amendment amendment)
Modifies an order for the bound account.
Definition traits.hpp:929
tossinvest::TossConfig Config
The configuration type.
Definition traits.hpp:740
tossinvest::TossAmendment Amendment
The amendment type.
Definition traits.hpp:752
static Result< std::vector< AccountListItem > > accounts(Client &client)
Returns the broker's own account listing.
Definition traits.hpp:865
static Result< std::vector< TradePrint > > trades(Client &client, InstrumentId instrument, int count)
Returns recent executions.
Definition traits.hpp:816
static Result< Instrument > instrument(Client &client, InstrumentId subject)
Returns static reference data for one instrument.
Definition traits.hpp:784
static Result< PlaceAck > place_order(Client &client, const Account &account, OrderRequest order)
Submits an order for the bound account.
Definition traits.hpp:918
static Result< OrderSnapshot > order_by_id(Client &client, const Account &account, std::string order_id)
Returns one order by id for the bound account; see TossClient::async_order for which orders can be re...
Definition traits.hpp:974
static Result< std::vector< QuoteSnapshot > > prices(Client &client, std::vector< InstrumentId > instruments)
Returns a quote for every instrument in one request.
Definition traits.hpp:826
std::int64_t Account
The account type: the account sequence.
Definition traits.hpp:743
static constexpr std::string_view name
The broker's name.
Definition traits.hpp:764
static Result< BuyingPower > buying_power(Client &client, const Account &account, Currency currency)
Returns what the bound account may spend in currency.
Definition traits.hpp:886
tossinvest::TossAccount AccountListItem
The account-listing item type.
Definition traits.hpp:761
static Result< WorkingOrdersResult > working_orders(Client &client, const Account &account)
Returns the OPEN listing for the bound account.
Definition traits.hpp:950
static Result< Decimal64 > sellable_quantity(Client &client, const Account &account, InstrumentId instrument)
Returns how much of instrument the bound account may sell.
Definition traits.hpp:897
static Result< QuoteSnapshot > quote(Client &client, InstrumentId instrument)
Returns a quote.
Definition traits.hpp:856
static auto trades(Client &client, InstrumentId instrument, int count, Token &&token)
Forwards a recent-execution request.
Definition traits.hpp:513
static auto depth(Client &client, InstrumentId instrument, Token &&token)
Forwards an order book request.
Definition traits.hpp:539
static const network::RateLimitStats * rate_limit_stats(const Client &client)
Returns this client's pacing statistics, or null when it is unpaced.
Definition traits.hpp:459
tossinvest::TossOrderQuery HistoryQuery
The order-history query type.
Definition traits.hpp:440
tossinvest::TossClient Client
The client type.
Definition traits.hpp:422
static auto holdings(Client &client, const Account &account, Token &&token)
Forwards a holdings request for the bound account.
Definition traits.hpp:631
static constexpr Venue effective_route(Venue) noexcept
Returns the venue a Toss order reaches: none in particular (Toss does not route by venue,...
Definition traits.hpp:417
tossinvest::TossAmendment Amendment
The amendment type.
Definition traits.hpp:437
OrderPage WorkingOrdersResult
The working-order result type.
Definition traits.hpp:443
static auto accounts(Client &client, Token &&token)
Forwards an account listing request.
Definition traits.hpp:577
static auto bars(Client &client, BarQuery query, Token &&token)
Forwards a bar request.
Definition traits.hpp:552
tossinvest::Broker BrokerTag
The broker tag.
Definition traits.hpp:431
tossinvest::TossAccount AccountListItem
The account-listing item type.
Definition traits.hpp:446
static auto cancel_order(Client &client, const Account &account, Amendment amendment, Token &&token)
Forwards an order cancellation, which transmits the identifier only.
Definition traits.hpp:673
static auto quote(Client &client, InstrumentId instrument, Token &&token)
Forwards a quote request.
Definition traits.hpp:565
static auto order_history(Client &client, const Account &account, HistoryQuery query, Token &&token)
Forwards a CLOSED listing for the bound account.
Definition traits.hpp:700
static auto order_by_id(Client &client, const Account &account, std::string order_id, Token &&token)
Forwards a single-order inquiry for the bound account.
Definition traits.hpp:715
std::int64_t Account
The account type: the account sequence.
Definition traits.hpp:428
static auto price_limits(Client &client, InstrumentId instrument, Token &&token)
Forwards a price-bound request.
Definition traits.hpp:499
static auto place_order(Client &client, const Account &account, OrderRequest order, Token &&token)
Forwards an order submission for the bound account.
Definition traits.hpp:645
static auto calendar(Client &client, Country country, std::optional< Date > from, Token &&token)
Forwards a calendar request.
Definition traits.hpp:486
static auto sellable_quantity(Client &client, const Account &account, InstrumentId instrument, Token &&token)
Forwards a sellable-quantity request for one instrument.
Definition traits.hpp:605
static auto prices(Client &client, std::vector< InstrumentId > instruments, Token &&token)
Forwards a batch quote request.
Definition traits.hpp:526
static constexpr bool blocking
false: requests complete through a completion token.
Definition traits.hpp:452
tossinvest::TossConfig Config
The configuration type.
Definition traits.hpp:425
static auto buying_power(Client &client, const Account &account, Currency currency, Token &&token)
Forwards a buying-power request for the bound account.
Definition traits.hpp:591
static constexpr std::string_view name
The broker's name.
Definition traits.hpp:449
static auto instrument(Client &client, InstrumentId subject, Token &&token)
Forwards a reference-data request.
Definition traits.hpp:472
static auto working_orders(Client &client, const Account &account, Token &&token)
Forwards an OPEN listing for the bound account.
Definition traits.hpp:686
static auto replace_order(Client &client, const Account &account, Amendment amendment, Token &&token)
Forwards an order modification for the bound account.
Definition traits.hpp:659
static auto commissions(Client &client, const Account &account, Token &&token)
Forwards a commission-schedule request for the bound account.
Definition traits.hpp:618
OrderAck PlaceAck
The order acknowledgement type.
Definition traits.hpp:434
Describes one broker client to the library: its types, capabilities, call thunks and normalizers.
Identifies an instrument: its country, venue and symbol.
Definition types.hpp:85
The broker's acknowledgement that it accepted an instruction.
Definition types.hpp:2383
The filter for an order-history inquiry.
Definition types.hpp:2617
std::optional< std::string > symbol_
Only this symbol, where the broker supports the filter.
Definition types.hpp:2623
std::optional< int > limit_
The most rows to return, where the broker supports a limit.
Definition types.hpp:2627
std::optional< std::string > cursor_
A previous page's next_cursor_, passed back unchanged.
Definition types.hpp:2625
std::optional< Date > from_
The first date to include; required where BrokerCaps::history_requires_range.
Definition types.hpp:2619
std::optional< Date > to_
The last date to include.
Definition types.hpp:2621
One page of an order listing.
Definition types.hpp:2369
A broker's reference to one order, used to amend or cancel it.
Definition types.hpp:2402
std::string primary_
The order number or id.
Definition types.hpp:2404
An order to place, in broker-neutral form.
Definition types.hpp:2216
std::optional< TimeInForce > time_in_force_
The time in force; unset means "keep the resting order's".
Definition types.hpp:2515
std::optional< Decimal64 > price_
The price, for a basis that takes one.
Definition types.hpp:2499
std::optional< OrderSession > session_
The session; unset means "keep the resting order's".
Definition types.hpp:2522
OrderType type_
The price basis.
Definition types.hpp:2497
An accepted order: the acknowledgement and the reference to address it with.
Definition types.hpp:2460
OrderRef< Broker > ref_
The reference to amend or cancel the order with.
Definition types.hpp:2464
OrderAck ack_
The acknowledgement.
Definition types.hpp:2462
What a sellable quantity covers, and how RiskGuard must treat resting sells against it.
Definition types.hpp:1191
@ WHOLE_HOLDING
Every share held of the instrument, whatever venue or lot.
Definition types.hpp:1197
@ DEDUCT
Subtract every resting sell from the figure.
Definition types.hpp:1215
An order still open to modification or cancellation.
Definition types.hpp:2582
OrderRef< Broker > ref_
The reference to amend or cancel the order with.
Definition types.hpp:2586
OrderSnapshot order_
The order's state.
Definition types.hpp:2584
The orders open to modification or cancellation at one point in time.
Definition types.hpp:2604
std::vector< WorkingOrder< Broker > > orders_
The open orders.
Definition types.hpp:2606
std::chrono::system_clock::time_point received_at_
When the listing was received, on this machine's clock.
Definition types.hpp:2608
A rate limiter's counters per traffic class, its current budget, and the broker's refusals (from Rate...
The Toss Securities broker tag: order references are typed by it, so a Toss reference works with both...
Definition traits.hpp:28
static constexpr std::string_view name
The broker's name, "tossinvest".
Definition traits.hpp:30
A Toss account, as account discovery (async_accounts) returns it.
Definition client.hpp:30
std::int64_t sequence_
Toss's account sequence, which every account request names.
Definition client.hpp:34
std::string account_type_
The account type as Toss reports it, for display.
Definition client.hpp:36
std::string account_number_
The account number as Toss reports it (accountNo): the full number, not masked.
Definition client.hpp:32
An amendment of a Toss order: a new price, and for a Korean order a new quantity.
Definition client.hpp:79
std::string order_id_
Toss's order id.
Definition client.hpp:81
bool confirm_high_value_
Confirms a high-value order, which Toss otherwise refuses.
Definition client.hpp:89
std::optional< Decimal64 > price_
The new price.
Definition client.hpp:87
std::optional< Decimal64 > quantity_
The new quantity: required for a Korean order, empty for a US one.
Definition client.hpp:85
OrderType type_
The order type it should have.
Definition client.hpp:83
Toss Securities credentials (client id and secret). Toss has no demo environment.
Definition config.hpp:27
A Toss order-listing query.
Definition client.hpp:56
std::optional< Date > to_
The last order date to include; before from_ is refused.
Definition client.hpp:66
std::optional< Date > from_
The first order date to include (Korean date; any scope).
Definition client.hpp:64
std::optional< std::string > symbol_
Only this symbol, if set.
Definition client.hpp:62
std::int64_t account_sequence_
The account (TossAccount::sequence_).
Definition client.hpp:58
std::optional< std::string > cursor_
The cursor from a previous page (OrderPage::next_cursor_); ignored for OPEN.
Definition client.hpp:68
TossOrderScope scope_
Open or closed orders.
Definition client.hpp:60
std::optional< int > limit_
The most rows to return, 1 to 100 (outside that range is refused, even for OPEN); not sent for OPEN.
Definition client.hpp:70