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 <optional>
16#include <string>
17#include <utility>
18
19namespace algotradelib {
20
21namespace kis {
22
27struct Broker {
29 static constexpr std::string_view name = "kis";
30};
31
32namespace traits_detail {
33
35using Ref = OrderRef<kis::Broker>;
36
38struct Normalizers {
40 static constexpr bool has_depth = true;
41
43 static constexpr bool has_price_limits = true;
44
46 static constexpr bool has_trade_prints = true;
47
49 static constexpr bool has_batch_prices = false;
50
52 static constexpr bool has_buying_power = true;
53
58 static constexpr bool has_buying_power_quantity = false;
59
61 static constexpr SellableSource sellable_source = SellableSource::HOLDINGS;
62
67 static constexpr bool has_commission_schedule = false;
68
70 static constexpr bool has_reference_data = true;
71
73 static constexpr bool has_batch_reference_data = false;
74
76 static constexpr bool has_calendar = true;
77
79 static constexpr bool has_calendar_range = true;
80
82 static constexpr bool has_calendar_sessions = false;
83
91 static std::optional<BrokerError> validate_calendar(Country country, std::optional<Date> from) {
92 BrokerError error;
94 error.reached_broker_ = false;
95 if (country != Country::KR) {
96 error.broker_code_ = "unsupported_market";
97 error.message_ = "KIS publishes the domestic trading calendar only";
98 return error;
99 }
100 if (from && !is_valid_date(*from)) {
101 error.broker_code_ = "invalid_date";
102 error.message_ = "calendar request requires a valid Gregorian date";
103 return error;
104 }
105 return std::nullopt;
106 }
107
114 static constexpr bool supports_interval(BarInterval interval) {
115 return kis::publishes_bar_interval(interval);
116 }
117
123 static std::optional<BrokerError> validate_bars(const BarQuery& query) {
125 }
126
132 static Ref make_ref(const KisOrderRef& order) {
133 Ref ref;
134 ref.primary_ = order.order_number_;
135 ref.secondary_ = order.branch_number_;
136 return ref;
137 }
138
144 static KisOrderRef from_ref(const Ref& ref) {
145 KisOrderRef order;
146 order.order_number_ = ref.primary_;
147 order.branch_number_ = ref.secondary_;
148 return order;
149 }
150
157 static std::optional<BrokerError> validate_place(const OrderRequest& order) {
159 }
160
166 static Result<PlacedOrder<kis::Broker>> normalize_place(Result<KisOrderAck> raw) {
167 if (!raw) {
168 return Result<PlacedOrder<kis::Broker>>(std::move(raw.error()));
169 }
171 placed.ack_ = std::move(raw.value().ack_);
172 placed.ref_ = make_ref(raw.value().order_);
173 return Result<PlacedOrder<kis::Broker>>(std::move(placed));
174 }
175
185 static Result<WorkingOrders<kis::Broker>> normalize_working_orders(Result<KisOpenOrderPage> raw) {
186 if (!raw) {
187 return Result<WorkingOrders<kis::Broker>>(std::move(raw.error()));
188 }
190 orders.received_at_ = raw.value().received_at_;
191 orders.orders_.reserve(raw.value().orders_.size());
192 for (auto& open_order : raw.value().orders_) {
194 working.order_ = std::move(open_order.order_);
195 working.ref_ = make_ref(open_order.order_ref_);
196 working.amendable_quantity_ = open_order.amendable_quantity_;
197 orders.orders_.push_back(std::move(working));
198 }
199 return Result<WorkingOrders<kis::Broker>>(std::move(orders));
200 }
201
215 static Result<KisAmendment> to_amendment(const Ref& ref, const AmendInstruction& instruction) {
216 if (!instruction.quantity_) {
217 BrokerError error;
219 error.reached_broker_ = false;
220 error.broker_code_ = "quantity_required";
221 error.message_ =
222 "KIS requires an explicit quantity on a modification or cancellation, including a full "
223 "cancellation; read the amendable quantity from working orders first";
224 return Result<KisAmendment>(std::move(error));
225 }
226
227 KisAmendment amendment;
228 amendment.order_ = from_ref(ref);
229 // What the shape leaves unset stays as it is, which the resting shape says.
230 // KIS composes one `ORD_DVSN` from all three, so it cannot send an
231 // amendment with a condition or session it does not know -- an unset field
232 // with no resting shape to resolve it from is refused rather than defaulted,
233 // because defaulting it here is how `00` got sent for an IOC order.
234 const auto condition = instruction.shape_.time_in_force_ ?
235 instruction.shape_.time_in_force_ :
236 (instruction.resting_ ? instruction.resting_->time_in_force_ : std::nullopt);
237 const auto session = instruction.shape_.session_ ?
238 instruction.shape_.session_ :
239 (instruction.resting_ ? instruction.resting_->session_ : std::nullopt);
240 if (!condition || !session) {
241 BrokerError error;
243 error.reached_broker_ = false;
244 error.broker_code_ = "incomplete_shape";
245 error.message_ =
246 "KIS re-sends the order code on an amendment and cannot compose one without the order's "
247 "validity condition and session; state them on the shape or build the instruction with "
248 "reprice() or replace_with(), which take them from the resting order";
249 return Result<KisAmendment>(std::move(error));
250 }
251 amendment.type_ = instruction.shape_.type_;
252 amendment.time_in_force_ = *condition;
253 amendment.session_ = *session;
254 amendment.venue_ = instruction.venue_;
255 amendment.quantity_ = *instruction.quantity_;
256 amendment.price_ = instruction.shape_.price_;
257 amendment.trigger_price_ = amended_trigger_price(instruction);
258 amendment.all_remaining_ = instruction.all_remaining_;
259 return Result<KisAmendment>(std::move(amendment));
260 }
261
268 static Result<KisAmendment> to_replacement(const Ref& ref, const AmendInstruction& instruction) {
269 return to_amendment(ref, instruction);
270 }
271
278 static Result<KisAmendment> to_cancellation(const Ref& ref, const AmendInstruction& instruction) {
279 return to_amendment(ref, instruction);
280 }
281
291 static Result<KisHistoryRange> to_history_query(const KisAccount&, const OrderHistoryQuery& query) {
292 BrokerError error;
294 error.reached_broker_ = false;
295 if (!query.from_ || !query.to_) {
296 error.broker_code_ = "range_required";
297 error.message_ = "KIS order history requires an inclusive from and to calendar date";
298 return Result<KisHistoryRange>(std::move(error));
299 }
300 if (query.symbol_) {
301 error.broker_code_ = "symbol_filter_unsupported";
302 error.message_ =
303 "KIS order history is not filtered by instrument by this adapter; filter the returned "
304 "orders instead";
305 return Result<KisHistoryRange>(std::move(error));
306 }
307 if (query.cursor_) {
308 error.broker_code_ = "cursor_unsupported";
309 error.message_ = "KIS order history pages internally and exposes no cursor";
310 return Result<KisHistoryRange>(std::move(error));
311 }
312 if (query.limit_) {
313 error.broker_code_ = "limit_unsupported";
314 error.message_ = "KIS order history returns every page and cannot honor a row limit";
315 return Result<KisHistoryRange>(std::move(error));
316 }
317 return Result<KisHistoryRange>(KisHistoryRange{*query.from_, *query.to_});
318 }
319
326 static std::string display_of(const KisAccount& account) {
327 const bool valid = broker_detail::decimal_digits(account.account_number_, 8) &&
328 broker_detail::decimal_digits(account.product_code_, 2);
329 return valid ? account.account_number_ + "-" + account.product_code_ : std::string();
330 }
331
337 static KisAccount no_account() {
338 return {};
339 }
340};
341
343struct Capabilities {
345 static constexpr bool has_account_discovery = false;
346
348 static constexpr bool has_client_order_id = false;
349
351 static constexpr bool has_trigger_price = true;
352
354 static constexpr bool data_only = false;
355
357 static constexpr bool has_working_orders = true;
358
363 static constexpr bool has_amendable_quantity = true;
364
369 static constexpr bool working_orders_state_terminal = false;
370
372 static constexpr bool has_order_by_id = false;
373
375 static constexpr bool has_partial_cancel = true;
376
378 static constexpr bool history_requires_range = true;
379
381 static constexpr bool has_history_cursor = false;
382
387 static constexpr bool has_history_limit = false;
388
390 static constexpr bool has_history_symbol_filter = false;
391};
392
393} // namespace traits_detail
394} // namespace kis
395
401inline constexpr Venue kis_effective_route(Venue asked) noexcept {
402 return asked == Venue::UNSPECIFIED ? Venue::KRX : asked;
403}
404
406template <>
407struct BrokerTraits<kis::KisClient> : kis::traits_detail::Normalizers, kis::traits_detail::Capabilities {
413 static constexpr Venue effective_route(Venue asked) noexcept {
414 return kis_effective_route(asked);
415 }
416
419
422
425
428
431
434
437
440
442 static constexpr std::string_view name = kis::Broker::name;
443
445 static constexpr bool blocking = false;
446
452 static const network::RateLimitStats* rate_limit_stats(const Client& client) {
453 return client.rate_limit_stats();
454 }
455
464 template <typename Token>
465 static auto instrument(Client& client, InstrumentId subject, Token&& token) {
466 return client.async_instrument(std::move(subject), std::forward<Token>(token));
467 }
468
478 template <typename Token>
479 static auto calendar(Client& client, Country, std::optional<Date> from, Token&& token) {
480 return client.async_calendar(from ? *from : kis::today_in_seoul(), false, std::forward<Token>(token));
481 }
482
491 template <typename Token>
492 static auto price_limits(Client& client, InstrumentId instrument, Token&& token) {
493 return client.async_price_limits(std::move(instrument), std::forward<Token>(token));
494 }
495
505 template <typename Token>
506 static auto trades(Client& client, InstrumentId instrument, int count, Token&& token) {
507 return client.async_trades(std::move(instrument), count, std::forward<Token>(token));
508 }
509
518 template <typename Token>
519 static auto depth(Client& client, InstrumentId instrument, Token&& token) {
520 return client.async_depth(std::move(instrument), std::forward<Token>(token));
521 }
522
531 template <typename Token>
532 static auto bars(Client& client, BarQuery query, Token&& token) {
533 return client.async_bars(std::move(query), std::forward<Token>(token));
534 }
535
544 template <typename Token>
545 static auto quote(Client& client, InstrumentId instrument, Token&& token) {
546 return client.async_quote(std::move(instrument), std::forward<Token>(token));
547 }
548
558 template <typename Token>
559 static auto buying_power(Client& client, const Account& account, Currency currency, Token&& token) {
560 return client.async_buying_power(currency, account, std::forward<Token>(token));
561 }
562
571 template <typename Token>
572 static auto holdings(Client& client, const Account& account, Token&& token) {
573 return client.async_holdings(account, std::forward<Token>(token));
574 }
575
585 template <typename Token>
586 static auto place_order(Client& client, const Account& account, OrderRequest order, Token&& token) {
587 return client.async_place_order(account, std::move(order), std::forward<Token>(token));
588 }
589
599 template <typename Token>
600 static auto replace_order(Client& client, const Account& account, Amendment amendment, Token&& token) {
601 return client.async_replace_order(account, std::move(amendment), std::forward<Token>(token));
602 }
603
613 template <typename Token>
614 static auto cancel_order(Client& client, const Account& account, Amendment amendment, Token&& token) {
615 return client.async_cancel_order(account, std::move(amendment), std::forward<Token>(token));
616 }
617
626 template <typename Token>
627 static auto working_orders(Client& client, const Account& account, Token&& token) {
628 return client.async_open_orders(account, std::forward<Token>(token));
629 }
630
640 template <typename Token>
641 static auto order_history(Client& client, const Account& account, HistoryQuery query, Token&& token) {
642 return client.async_order_history(account, query, std::forward<Token>(token));
643 }
644};
645
647template <>
648struct BrokerTraits<kis::KisBlockingClient> : kis::traits_detail::Normalizers, kis::traits_detail::Capabilities {
654 static constexpr Venue effective_route(Venue asked) noexcept {
655 return kis_effective_route(asked);
656 }
657
660
663
666
669
672
675
678
681
683 static constexpr std::string_view name = kis::Broker::name;
684
686 static constexpr bool blocking = true;
687
693 static const network::RateLimitStats* rate_limit_stats(const Client& client) {
694 return client.rate_limit_stats();
695 }
696
704 return client.instrument(std::move(subject));
705 }
706
713 static Result<TradingCalendar> calendar(Client& client, Country, std::optional<Date> from) {
714 return client.calendar(from ? *from : kis::today_in_seoul());
715 }
716
724 return client.price_limits(std::move(instrument));
725 }
726
735 return client.trades(std::move(instrument), count);
736 }
737
745 return client.depth(std::move(instrument));
746 }
747
754 static Result<BarSeries> bars(Client& client, BarQuery query) {
755 return client.bars(std::move(query));
756 }
757
765 return client.quote(std::move(instrument));
766 }
767
774 static Result<HoldingsSnapshot> holdings(Client& client, const Account& account) {
775 return client.holdings(account);
776 }
777
785 static Result<BuyingPower> buying_power(Client& client, const Account& account, Currency currency) {
786 return client.buying_power(currency, account);
787 }
788
796 static Result<PlaceAck> place_order(Client& client, const Account& account, OrderRequest order) {
797 return client.place_order(account, std::move(order));
798 }
799
807 static Result<PlaceAck> replace_order(Client& client, const Account& account, Amendment amendment) {
808 return client.replace_order(account, std::move(amendment));
809 }
810
818 static Result<PlaceAck> cancel_order(Client& client, const Account& account, Amendment amendment) {
819 return client.cancel_order(account, std::move(amendment));
820 }
821
829 return client.open_orders(account);
830 }
831
839 static Result<OrderPage> order_history(Client& client, const Account& account, HistoryQuery query) {
840 return client.order_history(account, query);
841 }
842};
843
844} // 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
Result(T value)
Constructs a successful result.
Definition types.hpp:1064
BrokerError & error()
Returns the error.
Definition types.hpp:1111
T & value()
Returns the value.
Definition types.hpp:1093
A blocking KIS client: each call runs a KisClient request on a private event loop and returns its res...
Definition client.hpp:4270
Result< TradingCalendar > calendar(Date from, bool refresh=false)
Returns the trading calendar from a date on; see KisClient::async_calendar (cached).
Definition client.hpp:4332
Result< OrderPage > order_history(KisAccount account, KisHistoryRange range)
Returns the orders placed over a date range, with their fills.
Definition client.hpp:4521
Result< QuoteSnapshot > quote(InstrumentId instrument)
Returns a quote; see KisClient::async_quote.
Definition client.hpp:4296
Result< KisOrderAck > replace_order(KisAccount account, KisAmendment amendment)
Amends an order's price or quantity; the outcome can be unknown after an error (see KisClient::async_...
Definition client.hpp:4475
Result< BuyingPower > buying_power(Currency currency, KisAccount account)
Returns the account's buying power, in won.
Definition client.hpp:4440
Result< std::vector< TradePrint > > trades(InstrumentId instrument, int count)
Returns an instrument's recent trades.
Definition client.hpp:4383
Result< KisOpenOrderPage > open_orders(KisAccount account)
Returns the orders that can still be amended or cancelled; see KisClient::async_open_orders (includin...
Definition client.hpp:4506
Result< HoldingsSnapshot > holdings(KisAccount account)
Returns the account's holdings.
Definition client.hpp:4425
Result< Instrument > instrument(InstrumentId subject)
Returns an instrument's reference data.
Definition client.hpp:4310
Result< PriceLimits > price_limits(InstrumentId instrument)
Returns an instrument's price band for today.
Definition client.hpp:4368
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics (safe to read between calls).
Definition client.hpp:4534
Result< DepthSnapshot > depth(InstrumentId instrument)
Returns the order book (ten levels a side).
Definition client.hpp:4397
Result< BarSeries > bars(BarQuery query)
Returns bars; see KisClient::async_bars.
Definition client.hpp:4411
Result< KisOrderAck > place_order(KisAccount account, OrderRequest order)
Places a cash order; see KisClient::async_place_order.
Definition client.hpp:4459
Result< KisOrderAck > cancel_order(KisAccount account, KisAmendment amendment)
Cancels an order; the outcome can be unknown after an error, and the order may still rest (see KisCli...
Definition client.hpp:4491
The asynchronous KIS REST client: market data, account inquiries and orders for domestic stocks.
Definition client.hpp:339
auto async_place_order(KisAccount account, OrderRequest order, CompletionToken &&token)
Places a cash order.
Definition client.hpp:645
auto async_quote(InstrumentId instrument, CompletionToken &&token)
Requests a quote.
Definition client.hpp:561
auto async_calendar(Date from, bool refresh, CompletionToken &&token)
Requests the trading calendar from a date on, and caches it for the client's life.
Definition client.hpp:464
auto async_cancel_order(KisAccount account, KisAmendment amendment, CompletionToken &&token)
Cancels an order (all or part of it, as amendment says).
Definition client.hpp:708
auto async_trades(InstrumentId instrument, int count, CompletionToken &&token)
Requests an instrument's recent trades.
Definition client.hpp:511
auto async_holdings(KisAccount account, CompletionToken &&token)
Requests the account's holdings.
Definition client.hpp:606
auto async_order_history(KisAccount account, KisHistoryRange range, CompletionToken &&token)
Requests the orders placed over a date range, with their fills.
Definition client.hpp:764
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics.
Definition client.hpp:786
auto async_open_orders(KisAccount account, CompletionToken &&token)
Requests every order that can still be amended or cancelled.
Definition client.hpp:739
auto async_instrument(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's reference data.
Definition client.hpp:437
auto async_replace_order(KisAccount account, KisAmendment amendment, CompletionToken &&token)
Amends an order's price or quantity.
Definition client.hpp:672
auto async_buying_power(Currency currency, KisAccount account, CompletionToken &&token)
Requests the account's buying power (the account-level amount, in won).
Definition client.hpp:584
auto async_price_limits(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's price band for today (from its current-price inquiry).
Definition client.hpp:484
auto async_depth(InstrumentId instrument, CompletionToken &&token)
Requests the order book (ten levels a side).
Definition client.hpp:539
auto async_bars(BarQuery query, CompletionToken &&token)
Requests bars, reading KIS pages until count_ bars are collected.
Definition client.hpp:417
Placeholder types and the refusal used by DataOnlyTraits.
The Korea Investment & Securities (KIS) Open API client.
Definition auth.hpp:9
Date today_in_seoul()
Returns today's date in Korea (UTC+9), the date KIS requests are made in.
Definition client.hpp:213
std::optional< BrokerError > unsupported_client_order_id(const OrderRequest &order)
Refuses an idempotency key, which KIS does not offer to individual customers.
Definition client.hpp:269
constexpr bool publishes_bar_interval(BarInterval interval) noexcept
Tests whether KIS publishes a chart at an interval.
Definition client.hpp:289
std::optional< BrokerError > unsupported_bar_interval(BarInterval interval)
Refuses a bar interval KIS publishes no chart for (publishes_bar_interval).
Definition client.hpp:311
The library: broker-neutral types (core), and the modules below.
SellableSource
Where the library gets a broker's sellable quantity.
Definition types.hpp:1362
@ HOLDINGS
On the holdings snapshot, at no extra request.
Definition types.hpp:1364
@ 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
constexpr Venue kis_effective_route(Venue asked) noexcept
Returns the venue a KIS order actually reaches.
Definition traits.hpp:401
std::optional< Decimal64 > amended_trigger_price(const AmendInstruction &instruction)
Returns the trigger price an amendment leaves the order with.
Definition types.hpp:2563
A modification or cancellation of a working order.
Definition types.hpp:2532
Venue venue_
The venue the order rests at, for a broker whose amendment needs it (KIS).
Definition types.hpp:2540
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
kis::KisAccount Account
The account type.
Definition traits.hpp:665
static Result< DepthSnapshot > depth(Client &client, InstrumentId instrument)
Returns the order book.
Definition traits.hpp:744
static Result< BarSeries > bars(Client &client, BarQuery query)
Returns bars, paging inside the client.
Definition traits.hpp:754
kis::KisConfig Config
The configuration type.
Definition traits.hpp:662
kis::KisBlockingClient Client
The client type.
Definition traits.hpp:659
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:693
kis::KisHistoryRange HistoryQuery
The order-history query type.
Definition traits.hpp:677
static Result< TradingCalendar > calendar(Client &client, Country, std::optional< Date > from)
Returns the calendar, supplying today when no date was given.
Definition traits.hpp:713
static Result< OrderPage > order_history(Client &client, const Account &account, HistoryQuery query)
Returns order history for the bound account.
Definition traits.hpp:839
static Result< Instrument > instrument(Client &client, InstrumentId subject)
Returns static reference data for one instrument.
Definition traits.hpp:703
static Result< std::vector< TradePrint > > trades(Client &client, InstrumentId instrument, int count)
Returns recent executions.
Definition traits.hpp:734
static constexpr std::string_view name
The broker's name.
Definition traits.hpp:683
static Result< PriceLimits > price_limits(Client &client, InstrumentId instrument)
Returns today's price bounds.
Definition traits.hpp:723
static Result< BuyingPower > buying_power(Client &client, const Account &account, Currency currency)
Returns what the bound account may spend in currency.
Definition traits.hpp:785
static constexpr bool blocking
true: requests return their result directly.
Definition traits.hpp:686
static constexpr Venue effective_route(Venue asked) noexcept
Where an order carrying asked actually goes; see kis_effective_route.
Definition traits.hpp:654
kis::KisAmendment Amendment
The amendment type.
Definition traits.hpp:674
static Result< PlaceAck > cancel_order(Client &client, const Account &account, Amendment amendment)
Cancels an order for the bound account.
Definition traits.hpp:818
static Result< WorkingOrdersResult > working_orders(Client &client, const Account &account)
Returns the amendable orders for the bound account.
Definition traits.hpp:828
kis::KisOpenOrderPage WorkingOrdersResult
The working-order result type.
Definition traits.hpp:680
static Result< QuoteSnapshot > quote(Client &client, InstrumentId instrument)
Returns a quote.
Definition traits.hpp:764
static Result< PlaceAck > place_order(Client &client, const Account &account, OrderRequest order)
Submits an order for the bound account.
Definition traits.hpp:796
static Result< HoldingsSnapshot > holdings(Client &client, const Account &account)
Returns holdings for the bound account.
Definition traits.hpp:774
kis::KisOrderAck PlaceAck
The order acknowledgement type.
Definition traits.hpp:671
static Result< PlaceAck > replace_order(Client &client, const Account &account, Amendment amendment)
Modifies an order for the bound account.
Definition traits.hpp:807
kis::KisOrderAck PlaceAck
The order acknowledgement type.
Definition traits.hpp:430
static constexpr Venue effective_route(Venue asked) noexcept
Where an order carrying asked actually goes; see kis_effective_route.
Definition traits.hpp:413
static auto holdings(Client &client, const Account &account, Token &&token)
Forwards a holdings request for the bound account.
Definition traits.hpp:572
static auto replace_order(Client &client, const Account &account, Amendment amendment, Token &&token)
Forwards an order modification for the bound account.
Definition traits.hpp:600
static auto price_limits(Client &client, InstrumentId instrument, Token &&token)
Forwards a price-bound request.
Definition traits.hpp:492
static auto working_orders(Client &client, const Account &account, Token &&token)
Forwards an amendable-order inquiry for the bound account.
Definition traits.hpp:627
static auto bars(Client &client, BarQuery query, Token &&token)
Forwards a bar request.
Definition traits.hpp:532
kis::KisHistoryRange HistoryQuery
The order-history query type.
Definition traits.hpp:436
kis::KisConfig Config
The configuration type.
Definition traits.hpp:421
kis::KisOpenOrderPage WorkingOrdersResult
The working-order result type.
Definition traits.hpp:439
kis::KisClient Client
The client type.
Definition traits.hpp:418
static constexpr bool blocking
false: requests complete through a completion token.
Definition traits.hpp:445
static auto instrument(Client &client, InstrumentId subject, Token &&token)
Forwards a reference-data request for one instrument.
Definition traits.hpp:465
static auto quote(Client &client, InstrumentId instrument, Token &&token)
Forwards a quote request.
Definition traits.hpp:545
static auto trades(Client &client, InstrumentId instrument, int count, Token &&token)
Forwards a recent-execution request.
Definition traits.hpp:506
kis::Broker BrokerTag
The broker tag.
Definition traits.hpp:427
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:452
kis::KisAmendment Amendment
The amendment type.
Definition traits.hpp:433
kis::KisAccount Account
The account type.
Definition traits.hpp:424
static auto calendar(Client &client, Country, std::optional< Date > from, Token &&token)
Forwards a calendar request (the market argument is ignored; validate_calendar checks it).
Definition traits.hpp:479
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:559
static auto order_history(Client &client, const Account &account, HistoryQuery query, Token &&token)
Forwards an order-history inquiry for the bound account.
Definition traits.hpp:641
static auto depth(Client &client, InstrumentId instrument, Token &&token)
Forwards an order book request.
Definition traits.hpp:519
static constexpr std::string_view name
The broker's name.
Definition traits.hpp:442
static auto place_order(Client &client, const Account &account, OrderRequest order, Token &&token)
Forwards an order submission for the bound account.
Definition traits.hpp:586
static auto cancel_order(Client &client, const Account &account, Amendment amendment, Token &&token)
Forwards an order cancellation for the bound account.
Definition traits.hpp:614
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 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
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
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
std::optional< Decimal64 > amendable_quantity_
How much the broker says may still be amended. Empty means it stated none, not zero.
Definition types.hpp:2588
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
The KIS broker tag: order references are typed by it, so a KIS reference works with both KIS clients ...
Definition traits.hpp:27
static constexpr std::string_view name
The broker's name, "kis".
Definition traits.hpp:29
A KIS account: the account number and product code every account request names.
Definition client.hpp:31
std::string product_code_
The two-digit product code (KIS's ACNT_PRDT_CD); "01" for a cash equity account.
Definition client.hpp:35
std::string account_number_
The eight-digit account number (KIS's CANO).
Definition client.hpp:33
An amendment or cancellation of a KIS order.
Definition client.hpp:128
bool all_remaining_
Whether the whole remaining quantity is affected (KIS's QTY_ALL_ORD_YN), rather than quantity_.
Definition client.hpp:152
OrderType type_
The order type it should have.
Definition client.hpp:132
KisOrderRef order_
The order to amend or cancel.
Definition client.hpp:130
std::optional< Decimal64 > trigger_price_
The trigger price (KIS's CNDT_PRIC), for a STOP_LIMIT order.
Definition client.hpp:150
OrderSession session_
The session it should be in.
Definition client.hpp:136
Decimal64 quantity_
The quantity affected; KIS requires a positive whole number even with all_remaining_.
Definition client.hpp:140
TimeInForce time_in_force_
The execution condition it should have.
Definition client.hpp:134
std::optional< Decimal64 > price_
The price the order should have: required for an order type that takes one, on a cancellation too.
Definition client.hpp:142
Venue venue_
The venue where the order rests (the codes differ by venue).
Definition client.hpp:138
KIS credentials (app key and secret), demo or real account, and the market-data tape.
Definition config.hpp:83
The date range of a KIS order-history inquiry, both ends included (Korean dates).
Definition client.hpp:202
KIS's list of orders that can still be amended or cancelled.
Definition client.hpp:194
KIS's acknowledgement of an accepted order, amendment or cancellation.
Definition client.hpp:161
A KIS order's address: branch number and order number, both kept.
Definition client.hpp:111
std::string order_number_
The order number within that branch (KIS's ODNO).
Definition client.hpp:115
std::string branch_number_
The branch that recorded the order (KIS's KRX_FWDG_ORD_ORGNO).
Definition client.hpp:113
A rate limiter's counters per traffic class, its current budget, and the broker's refusals (from Rate...