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 = true;
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&) { return std::nullopt; }
150
156 static Result<PlacedOrder<tossinvest::Broker>> normalize_place(Result<OrderAck> raw) {
157 if (!raw) {
158 return Result<PlacedOrder<tossinvest::Broker>>(std::move(raw.error()));
159 }
161 placed.ref_ = make_ref(raw.value().order_id_);
162 placed.ack_ = std::move(raw.value());
163 return Result<PlacedOrder<tossinvest::Broker>>(std::move(placed));
164 }
165
172 static Result<WorkingOrders<tossinvest::Broker>> normalize_working_orders(
174 ) {
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(
204 const Ref& ref,
205 const AmendInstruction& instruction
206 ) {
207 // Toss's `OrderModifyRequest` carries `orderType`, `quantity`, `price` and
208 // the high-value flag, and **no validity field at all**: a modification
209 // cannot change the condition or the session, and Toss cannot refuse a
210 // request to. So this refuses on Toss's behalf, and the question is not
211 // whether the requested value is one Toss supports -- it can place a
212 // closing-auction order -- but whether it *differs* from what the order
213 // already is.
214 //
215 // Which means the original has to be known. An unset `resting_` is refused
216 // rather than assumed to match: a hand-built instruction naming DAY/REGULAR
217 // against a resting CLS order compared equal to a defaulted original and was
218 // sent, and the order stayed CLS while the caller was told it had moved.
219 if (!instruction.resting_) {
220 BrokerError error;
222 error.reached_broker_ = false;
223 error.broker_code_ = "unknown_resting_shape";
224 error.message_ =
225 "Toss cannot change an order's validity condition or session by amending it, and this "
226 "instruction does not say what the order's are, so neither can be verified; build the "
227 "instruction with reprice() or replace_with() from the working order";
228 return Result<tossinvest::TossAmendment>(std::move(error));
229 }
230 // An unset field on the shape asks for no change, which is always safe here.
231 if (instruction.shape_.time_in_force_ &&
232 *instruction.shape_.time_in_force_ != instruction.resting_->time_in_force_) {
233 BrokerError error;
235 error.reached_broker_ = false;
236 error.broker_code_ = "unsupported_time_in_force";
237 error.message_ =
238 "Toss cannot change an order's validity condition by amending it; cancel the order and "
239 "place a new one instead";
240 return Result<tossinvest::TossAmendment>(std::move(error));
241 }
242 if (instruction.shape_.session_ &&
243 *instruction.shape_.session_ != instruction.resting_->session_) {
244 BrokerError error;
246 error.reached_broker_ = false;
247 error.broker_code_ = "unsupported_session";
248 error.message_ =
249 "Toss cannot move an order to another trading session by amending it; cancel the order "
250 "and place a new one instead";
251 return Result<tossinvest::TossAmendment>(std::move(error));
252 }
253
255 amendment.order_id_ = ref.primary_;
256 amendment.type_ = instruction.shape_.type_;
257 amendment.quantity_ = instruction.quantity_;
258 amendment.price_ = instruction.shape_.price_;
259 amendment.confirm_high_value_ = instruction.confirm_high_value_;
260 return Result<tossinvest::TossAmendment>(std::move(amendment));
261 }
262
272 static Result<tossinvest::TossAmendment> to_cancellation(
273 const Ref& ref,
274 const AmendInstruction& instruction
275 ) {
276 if (!instruction.all_remaining_) {
277 BrokerError error;
279 error.reached_broker_ = false;
280 error.broker_code_ = "partial_cancel_unsupported";
281 error.message_ =
282 "Toss cancels an order in full; use cancel_all() or modify the order to a smaller "
283 "quantity instead of cancelling part of it";
284 return Result<tossinvest::TossAmendment>(std::move(error));
285 }
287 amendment.order_id_ = ref.primary_;
288 return Result<tossinvest::TossAmendment>(std::move(amendment));
289 }
290
298 static Result<tossinvest::TossOrderQuery> to_history_query(
299 std::int64_t account_sequence,
300 const OrderHistoryQuery& query
301 ) {
303 converted.account_sequence_ = account_sequence;
305 converted.symbol_ = query.symbol_;
306 converted.from_ = query.from_;
307 converted.to_ = query.to_;
308 converted.cursor_ = query.cursor_;
309 converted.limit_ = query.limit_;
310 return Result<tossinvest::TossOrderQuery>(std::move(converted));
311 }
312
318 static tossinvest::TossOrderQuery open_query(std::int64_t account_sequence) {
320 query.account_sequence_ = account_sequence;
322 return query;
323 }
324
330 static std::int64_t selector_of(const tossinvest::TossAccount& account) {
331 return account.sequence_;
332 }
333
339 static std::string display_of(const tossinvest::TossAccount& account) {
340 return account.account_number_;
341 }
342
348 static std::string type_of(const tossinvest::TossAccount& account) {
349 return account.account_type_;
350 }
351};
352
354struct Capabilities {
356 static constexpr bool has_account_discovery = true;
357
359 static constexpr bool has_client_order_id = true;
360
365 static constexpr bool has_trigger_price = false;
366
368 static constexpr bool data_only = false;
369
374 static constexpr bool has_working_orders = true;
375
377 static constexpr bool has_amendable_quantity = false;
378
383 static constexpr bool working_orders_state_terminal = false;
384
386 static constexpr bool has_order_by_id = true;
387
389 static constexpr bool has_partial_cancel = false;
390
392 static constexpr bool history_requires_range = false;
393
395 static constexpr bool has_history_cursor = true;
396
398 static constexpr bool has_history_limit = true;
399
401 static constexpr bool has_history_symbol_filter = true;
402};
403
404} // namespace traits_detail
405} // namespace tossinvest
406
408template <>
409struct BrokerTraits<tossinvest::TossClient>
410: tossinvest::traits_detail::Normalizers, tossinvest::traits_detail::Capabilities {
419 static constexpr Venue effective_route(Venue) noexcept { return Venue::UNSPECIFIED; }
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(
606 Client& client,
607 const Account& account,
609 Token&& token
610 ) {
611 return client.async_sellable_quantity(std::move(instrument), account, std::forward<Token>(token));
612 }
613
622 template <typename Token>
623 static auto commissions(Client& client, const Account& account, Token&& token) {
624 return client.async_commissions(account, std::forward<Token>(token));
625 }
626
635 template <typename Token>
636 static auto holdings(Client& client, const Account& account, Token&& token) {
637 return client.async_holdings(account, std::forward<Token>(token));
638 }
639
649 template <typename Token>
650 static auto place_order(Client& client, const Account& account, OrderRequest order, Token&& token) {
651 return client.async_place_order(account, std::move(order), std::forward<Token>(token));
652 }
653
663 template <typename Token>
664 static auto replace_order(
665 Client& client,
666 const Account& account,
667 Amendment amendment,
668 Token&& token
669 ) {
670 return client.async_replace_order(account, std::move(amendment), std::forward<Token>(token));
671 }
672
682 template <typename Token>
683 static auto cancel_order(
684 Client& client,
685 const Account& account,
686 Amendment amendment,
687 Token&& token
688 ) {
689 return client.async_cancel_order(
690 account, std::move(amendment.order_id_), std::forward<Token>(token)
691 );
692 }
693
702 template <typename Token>
703 static auto working_orders(Client& client, const Account& account, Token&& token) {
704 return client.async_orders(open_query(account), std::forward<Token>(token));
705 }
706
716 template <typename Token>
717 static auto order_history(
718 Client& client,
719 const Account& account,
720 HistoryQuery query,
721 Token&& token
722 ) {
723 static_cast<void>(account);
724 return client.async_orders(std::move(query), std::forward<Token>(token));
725 }
726
736 template <typename Token>
737 static auto order_by_id(
738 Client& client,
739 const Account& account,
740 std::string order_id,
741 Token&& token
742 ) {
743 return client.async_order(account, std::move(order_id), std::forward<Token>(token));
744 }
745};
746
748template <>
749struct BrokerTraits<tossinvest::TossBlockingClient>
750: tossinvest::traits_detail::Normalizers, tossinvest::traits_detail::Capabilities {
759 static constexpr Venue effective_route(Venue) noexcept { return Venue::UNSPECIFIED; }
760
763
766
768 using Account = std::int64_t;
769
772
775
778
781
784
787
789 static constexpr std::string_view name = tossinvest::Broker::name;
790
792 static constexpr bool blocking = true;
793
799 static const network::RateLimitStats* rate_limit_stats(const Client& client) {
800 return client.rate_limit_stats();
801 }
802
810 return client.instrument(std::move(subject));
811 }
812
820 static Result<TradingCalendar> calendar(Client& client, Country country, std::optional<Date> from) {
821 return client.calendar(country, from);
822 }
823
831 return client.price_limits(std::move(instrument));
832 }
833
842 Client& client,
844 int count
845 ) {
846 return client.trades(std::move(instrument), count);
847 }
848
856 Client& client,
857 std::vector<InstrumentId> instruments
858 ) {
859 return client.prices(std::move(instruments));
860 }
861
869 return client.depth(std::move(instrument));
870 }
871
878 static Result<BarSeries> bars(Client& client, BarQuery query) {
879 return client.bars(std::move(query));
880 }
881
889 return client.quote(std::move(instrument));
890 }
891
898 return client.accounts();
899 }
900
907 static Result<HoldingsSnapshot> holdings(Client& client, const Account& account) {
908 return client.holdings(account);
909 }
910
919 Client& client,
920 const Account& account,
921 Currency currency
922 ) {
923 return client.buying_power(currency, account);
924 }
925
934 Client& client,
935 const Account& account,
937 ) {
938 return client.sellable_quantity(std::move(instrument), account);
939 }
940
947 static Result<CommissionSchedule> commissions(Client& client, const Account& account) {
948 return client.commissions(account);
949 }
950
958 static Result<PlaceAck> place_order(Client& client, const Account& account, OrderRequest order) {
959 return client.place_order(account, std::move(order));
960 }
961
970 Client& client,
971 const Account& account,
972 Amendment amendment
973 ) {
974 return client.replace_order(account, std::move(amendment));
975 }
976
985 Client& client,
986 const Account& account,
987 Amendment amendment
988 ) {
989 return client.cancel_order(account, std::move(amendment.order_id_));
990 }
991
999 return client.orders(open_query(account));
1000 }
1001
1010 Client& client,
1011 const Account& account,
1012 HistoryQuery query
1013 ) {
1014 static_cast<void>(account);
1015 return client.orders(std::move(query));
1016 }
1017
1027 Client& client,
1028 const Account& account,
1029 std::string order_id
1030 ) {
1031 return client.order(account, std::move(order_id));
1032 }
1033};
1034
1035} // namespace algotradelib
A three-letter currency code, such as KRW or USD (ISO 4217 style).
Definition types.hpp:234
Either a value or a BrokerError.
Definition types.hpp:797
BrokerError & error()
Returns the error.
Definition types.hpp:842
T & value()
Returns the value.
Definition types.hpp:828
Blocking facade that drives TossClient on a private event loop.
Definition client.hpp:3994
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:4203
Result< BuyingPower > buying_power(Currency currency, std::int64_t account_sequence)
Returns what the account may spend in currency.
Definition client.hpp:4140
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics (safe to read between calls).
Definition client.hpp:4259
Result< Decimal64 > sellable_quantity(InstrumentId instrument, std::int64_t account_sequence)
Returns how much of instrument the account may sell.
Definition client.hpp:4155
Result< OrderPage > orders(TossOrderQuery query)
Returns one page of orders; see TossClient::async_orders for which orders are listed.
Definition client.hpp:4233
Result< Instrument > instrument(InstrumentId subject)
Returns static reference data for one instrument.
Definition client.hpp:4039
Result< OrderAck > place_order(std::int64_t account_sequence, OrderRequest order)
Places an order; see TossClient::async_place_order.
Definition client.hpp:4187
Result< DepthSnapshot > depth(InstrumentId instrument)
Returns the resting orders on both sides of the book.
Definition client.hpp:4103
Result< HoldingsSnapshot > holdings(std::int64_t account_sequence)
Returns normalized positions and per-currency totals for one account.
Definition client.hpp:4127
Result< std::vector< QuoteSnapshot > > prices(std::vector< InstrumentId > instruments)
Returns a quote for every instrument in one request.
Definition client.hpp:4091
Result< QuoteSnapshot > quote(InstrumentId instrument)
Returns a quote for a Korean instrument (a US instrument is refused; use prices).
Definition client.hpp:4016
Result< CommissionSchedule > commissions(std::int64_t account_sequence)
Returns the commission rates in force for the account.
Definition client.hpp:4169
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:4219
Result< PriceLimits > price_limits(InstrumentId instrument)
Returns today's upper and lower price bound.
Definition client.hpp:4064
Result< std::vector< TradePrint > > trades(InstrumentId instrument, int count)
Returns recent executions for one instrument.
Definition client.hpp:4077
Result< std::vector< TossAccount > > accounts()
Discovers the brokerage accounts available to the current credentials.
Definition client.hpp:4027
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:4246
Result< BarSeries > bars(BarQuery query)
Returns up to count_ bars; see TossClient::async_bars.
Definition client.hpp:4115
Result< TradingCalendar > calendar(Country country, std::optional< Date > from=std::nullopt)
Returns the trading calendar around from for one market.
Definition client.hpp:4052
The asynchronous Toss Securities REST client: market data, accounts and orders.
Definition client.hpp:146
auto async_commissions(std::int64_t account_sequence, CompletionToken &&token)
Requests the commission rates in force for the account.
Definition client.hpp:516
auto async_instrument(InstrumentId instrument, CompletionToken &&token)
Requests static reference data for one instrument.
Definition client.hpp:274
auto async_orders(TossOrderQuery query, CompletionToken &&token)
Requests a page of orders.
Definition client.hpp:706
auto async_trades(InstrumentId instrument, int count, CompletionToken &&token)
Requests recent executions for one instrument, newest first.
Definition client.hpp:331
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:414
auto async_bars(BarQuery query, CompletionToken &&token)
Requests up to count_ bars, oldest first.
Definition client.hpp:225
auto async_holdings(std::int64_t account_sequence, CompletionToken &&token)
Requests and normalizes holdings for one discovered account sequence.
Definition client.hpp:539
auto async_accounts(CompletionToken &&token)
Discovers the brokerage accounts available to the current credentials.
Definition client.hpp:436
auto async_cancel_order(std::int64_t account_sequence, std::string order_id, CompletionToken &&token)
Cancels an open order.
Definition client.hpp:664
auto async_place_order(std::int64_t account_sequence, OrderRequest order, CompletionToken &&token)
Places an order.
Definition client.hpp:578
auto async_depth(InstrumentId instrument, CompletionToken &&token)
Requests and normalizes the resting orders on both sides of the book.
Definition client.hpp:390
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:460
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics.
Definition client.hpp:765
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:251
auto async_prices(std::vector< InstrumentId > instruments, CompletionToken &&token)
Quotes up to 200 instruments in one request.
Definition client.hpp:366
auto async_price_limits(InstrumentId instrument, CompletionToken &&token)
Requests today's upper and lower price bound for one instrument.
Definition client.hpp:302
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:735
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:484
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:621
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:123
@ CLOSED
Ended orders (including a partly filled order that ended).
Definition client.hpp:45
@ OPEN
Open orders: pending, partly filled, or with an amendment or cancellation pending.
Definition client.hpp:43
The library: broker-neutral types (core), and the modules below.
SellableSource
Where the library gets a broker's sellable quantity.
Definition types.hpp:1092
@ INQUIRY
From a per-instrument inquiry, made only where the snapshot has no figure.
Definition types.hpp:1096
@ INVALID_ARGUMENT
The request was invalid, refused by the client before sending or by the broker.
Definition types.hpp:713
Country
A country (market) the library supports.
Definition types.hpp:30
Venue
A trading venue: an exchange, or the combined view across exchanges.
Definition types.hpp:43
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:1212
A modification or cancellation of a working order.
Definition types.hpp:2240
bool confirm_high_value_
Confirms a high-value amendment, where the broker asks for that confirmation.
Definition types.hpp:2254
std::optional< OrderShape > resting_
The shape the order has now, or unset if unknown.
Definition types.hpp:2261
std::optional< Decimal64 > quantity_
The quantity affected; never substituted if a broker needs one and it is missing.
Definition types.hpp:2250
OrderShape shape_
The shape the order should have afterwards.
Definition types.hpp:2242
bool all_remaining_
Whether the whole remaining quantity is affected, rather than quantity_.
Definition types.hpp:2252
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:742
std::string message_
A human-readable description, for logs; do not parse it.
Definition types.hpp:772
ErrorCategory category_
The kind of failure; the field to branch on.
Definition types.hpp:744
std::string broker_code_
The broker's own error code, verbatim (for example KIS's EGW00201).
Definition types.hpp:761
bool reached_broker_
Whether a request was sent before this error.
Definition types.hpp:753
static Result< OrderPage > order_history(Client &client, const Account &account, HistoryQuery query)
Returns the CLOSED listing for the bound account.
Definition traits.hpp:1009
static Result< PriceLimits > price_limits(Client &client, InstrumentId instrument)
Returns today's price bounds.
Definition traits.hpp:830
static Result< TradingCalendar > calendar(Client &client, Country country, std::optional< Date > from)
Returns the calendar for one market.
Definition traits.hpp:820
static Result< CommissionSchedule > commissions(Client &client, const Account &account)
Returns the commission rates in force for the bound account.
Definition traits.hpp:947
tossinvest::TossBlockingClient Client
The client type.
Definition traits.hpp:762
static Result< HoldingsSnapshot > holdings(Client &client, const Account &account)
Returns holdings for the bound account.
Definition traits.hpp:907
static Result< DepthSnapshot > depth(Client &client, InstrumentId instrument)
Returns the order book.
Definition traits.hpp:868
static Result< BarSeries > bars(Client &client, BarQuery query)
Returns bars, paging inside the client.
Definition traits.hpp:878
static constexpr bool blocking
true: requests return their result directly.
Definition traits.hpp:792
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:984
tossinvest::TossOrderQuery HistoryQuery
The order-history query type.
Definition traits.hpp:780
OrderPage WorkingOrdersResult
The working-order result type.
Definition traits.hpp:783
OrderAck PlaceAck
The order acknowledgement type.
Definition traits.hpp:774
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:759
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:799
static Result< PlaceAck > replace_order(Client &client, const Account &account, Amendment amendment)
Modifies an order for the bound account.
Definition traits.hpp:969
tossinvest::TossConfig Config
The configuration type.
Definition traits.hpp:765
tossinvest::TossAmendment Amendment
The amendment type.
Definition traits.hpp:777
static Result< std::vector< AccountListItem > > accounts(Client &client)
Returns the broker's own account listing.
Definition traits.hpp:897
static Result< std::vector< TradePrint > > trades(Client &client, InstrumentId instrument, int count)
Returns recent executions.
Definition traits.hpp:841
static Result< Instrument > instrument(Client &client, InstrumentId subject)
Returns static reference data for one instrument.
Definition traits.hpp:809
static Result< PlaceAck > place_order(Client &client, const Account &account, OrderRequest order)
Submits an order for the bound account.
Definition traits.hpp:958
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:1026
static Result< std::vector< QuoteSnapshot > > prices(Client &client, std::vector< InstrumentId > instruments)
Returns a quote for every instrument in one request.
Definition traits.hpp:855
std::int64_t Account
The account type: the account sequence.
Definition traits.hpp:768
static constexpr std::string_view name
The broker's name.
Definition traits.hpp:789
static Result< BuyingPower > buying_power(Client &client, const Account &account, Currency currency)
Returns what the bound account may spend in currency.
Definition traits.hpp:918
tossinvest::TossAccount AccountListItem
The account-listing item type.
Definition traits.hpp:786
static Result< WorkingOrdersResult > working_orders(Client &client, const Account &account)
Returns the OPEN listing for the bound account.
Definition traits.hpp:998
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:933
static Result< QuoteSnapshot > quote(Client &client, InstrumentId instrument)
Returns a quote.
Definition traits.hpp:888
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:636
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:419
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:683
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:717
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:737
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:650
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:703
static auto replace_order(Client &client, const Account &account, Amendment amendment, Token &&token)
Forwards an order modification for the bound account.
Definition traits.hpp:664
static auto commissions(Client &client, const Account &account, Token &&token)
Forwards a commission-schedule request for the bound account.
Definition traits.hpp:623
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:78
The broker's acknowledgement that it accepted an instruction.
Definition types.hpp:2092
The filter for an order-history inquiry.
Definition types.hpp:2325
std::optional< std::string > symbol_
Only this symbol, where the broker supports the filter.
Definition types.hpp:2331
std::optional< int > limit_
The most rows to return, where the broker supports a limit.
Definition types.hpp:2335
std::optional< std::string > cursor_
A previous page's next_cursor_, passed back unchanged.
Definition types.hpp:2333
std::optional< Date > from_
The first date to include; required where BrokerCaps::history_requires_range.
Definition types.hpp:2327
std::optional< Date > to_
The last date to include.
Definition types.hpp:2329
One page of an order listing.
Definition types.hpp:2078
A broker's reference to one order, used to amend or cancel it.
Definition types.hpp:2111
std::string primary_
The order number or id.
Definition types.hpp:2113
An order to place, in broker-neutral form.
Definition types.hpp:1925
std::optional< TimeInForce > time_in_force_
The time in force; unset means "keep the resting order's".
Definition types.hpp:2223
std::optional< Decimal64 > price_
The price, for a basis that takes one.
Definition types.hpp:2207
std::optional< OrderSession > session_
The session; unset means "keep the resting order's".
Definition types.hpp:2230
OrderType type_
The price basis.
Definition types.hpp:2205
An accepted order: the acknowledgement and the reference to address it with.
Definition types.hpp:2165
OrderRef< Broker > ref_
The reference to amend or cancel the order with.
Definition types.hpp:2169
OrderAck ack_
The acknowledgement.
Definition types.hpp:2167
What a sellable quantity covers, and how RiskGuard must treat resting sells against it.
Definition types.hpp:918
@ WHOLE_HOLDING
Every share held of the instrument, whatever venue or lot.
Definition types.hpp:924
@ DEDUCT
Subtract every resting sell from the figure.
Definition types.hpp:942
An order still open to modification or cancellation.
Definition types.hpp:2290
OrderRef< Broker > ref_
The reference to amend or cancel the order with.
Definition types.hpp:2294
OrderSnapshot order_
The order's state.
Definition types.hpp:2292
The orders open to modification or cancellation at one point in time.
Definition types.hpp:2312
std::vector< WorkingOrder< Broker > > orders_
The open orders.
Definition types.hpp:2314
std::chrono::system_clock::time_point received_at_
When the listing was received, on this machine's clock.
Definition types.hpp:2316
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:29
std::int64_t sequence_
Toss's account sequence, which every account request names.
Definition client.hpp:33
std::string account_type_
The account type as Toss reports it, for display.
Definition client.hpp:35
std::string account_number_
The account number as Toss reports it (accountNo): the full number, not masked.
Definition client.hpp:31
An amendment of a Toss order: a new price, and for a Korean order a new quantity.
Definition client.hpp:78
std::string order_id_
Toss's order id.
Definition client.hpp:80
bool confirm_high_value_
Confirms a high-value order, which Toss otherwise refuses.
Definition client.hpp:88
std::optional< Decimal64 > price_
The new price.
Definition client.hpp:86
std::optional< Decimal64 > quantity_
The new quantity: required for a Korean order, empty for a US one.
Definition client.hpp:84
OrderType type_
The order type it should have.
Definition client.hpp:82
Toss Securities credentials (client id and secret). Toss has no demo environment.
Definition config.hpp:24
A Toss order-listing query.
Definition client.hpp:55
std::optional< Date > to_
The last order date to include; before from_ is refused.
Definition client.hpp:65
std::optional< Date > from_
The first order date to include (Korean date; any scope).
Definition client.hpp:63
std::optional< std::string > symbol_
Only this symbol, if set.
Definition client.hpp:61
std::int64_t account_sequence_
The account (TossAccount::sequence_).
Definition client.hpp:57
std::optional< std::string > cursor_
The cursor from a previous page (OrderPage::next_cursor_); ignored for OPEN.
Definition client.hpp:67
TossOrderScope scope_
Open or closed orders.
Definition client.hpp:59
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:69