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(
187 ) {
188 if (!raw) {
189 return Result<WorkingOrders<kis::Broker>>(std::move(raw.error()));
190 }
192 orders.received_at_ = raw.value().received_at_;
193 orders.orders_.reserve(raw.value().orders_.size());
194 for (auto& open_order : raw.value().orders_) {
196 working.order_ = std::move(open_order.order_);
197 working.ref_ = make_ref(open_order.order_ref_);
198 working.amendable_quantity_ = open_order.amendable_quantity_;
199 orders.orders_.push_back(std::move(working));
200 }
201 return Result<WorkingOrders<kis::Broker>>(std::move(orders));
202 }
203
217 static Result<KisAmendment> to_amendment(
218 const Ref& ref,
219 const AmendInstruction& instruction
220 ) {
221 if (!instruction.quantity_) {
222 BrokerError error;
224 error.reached_broker_ = false;
225 error.broker_code_ = "quantity_required";
226 error.message_ =
227 "KIS requires an explicit quantity on a modification or cancellation, including a full "
228 "cancellation; read the amendable quantity from working orders first";
229 return Result<KisAmendment>(std::move(error));
230 }
231
232 KisAmendment amendment;
233 amendment.order_ = from_ref(ref);
234 // What the shape leaves unset stays as it is, which the resting shape says.
235 // KIS composes one `ORD_DVSN` from all three, so it cannot send an
236 // amendment with a condition or session it does not know -- an unset field
237 // with no resting shape to resolve it from is refused rather than defaulted,
238 // because defaulting it here is how `00` got sent for an IOC order.
239 const auto condition = instruction.shape_.time_in_force_
240 ? instruction.shape_.time_in_force_
241 : (instruction.resting_ ? instruction.resting_->time_in_force_ : std::nullopt);
242 const auto session = instruction.shape_.session_
243 ? instruction.shape_.session_
244 : (instruction.resting_ ? instruction.resting_->session_ : std::nullopt);
245 if (!condition || !session) {
246 BrokerError error;
248 error.reached_broker_ = false;
249 error.broker_code_ = "incomplete_shape";
250 error.message_ =
251 "KIS re-sends the order code on an amendment and cannot compose one without the order's "
252 "validity condition and session; state them on the shape or build the instruction with "
253 "reprice() or replace_with(), which take them from the resting order";
254 return Result<KisAmendment>(std::move(error));
255 }
256 amendment.type_ = instruction.shape_.type_;
257 amendment.time_in_force_ = *condition;
258 amendment.session_ = *session;
259 amendment.venue_ = instruction.venue_;
260 amendment.quantity_ = *instruction.quantity_;
261 amendment.price_ = instruction.shape_.price_;
262 amendment.trigger_price_ = amended_trigger_price(instruction);
263 amendment.all_remaining_ = instruction.all_remaining_;
264 return Result<KisAmendment>(std::move(amendment));
265 }
266
273 static Result<KisAmendment> to_replacement(
274 const Ref& ref,
275 const AmendInstruction& instruction
276 ) {
277 return to_amendment(ref, instruction);
278 }
279
286 static Result<KisAmendment> to_cancellation(
287 const Ref& ref,
288 const AmendInstruction& instruction
289 ) {
290 return to_amendment(ref, instruction);
291 }
292
302 static Result<KisHistoryRange> to_history_query(
303 const KisAccount&,
304 const OrderHistoryQuery& query
305 ) {
306 BrokerError error;
308 error.reached_broker_ = false;
309 if (!query.from_ || !query.to_) {
310 error.broker_code_ = "range_required";
311 error.message_ = "KIS order history requires an inclusive from and to calendar date";
312 return Result<KisHistoryRange>(std::move(error));
313 }
314 if (query.symbol_) {
315 error.broker_code_ = "symbol_filter_unsupported";
316 error.message_ =
317 "KIS order history is not filtered by instrument by this adapter; filter the returned "
318 "orders instead";
319 return Result<KisHistoryRange>(std::move(error));
320 }
321 if (query.cursor_) {
322 error.broker_code_ = "cursor_unsupported";
323 error.message_ = "KIS order history pages internally and exposes no cursor";
324 return Result<KisHistoryRange>(std::move(error));
325 }
326 if (query.limit_) {
327 error.broker_code_ = "limit_unsupported";
328 error.message_ = "KIS order history returns every page and cannot honor a row limit";
329 return Result<KisHistoryRange>(std::move(error));
330 }
331 return Result<KisHistoryRange>(KisHistoryRange{*query.from_, *query.to_});
332 }
333};
334
336struct Capabilities {
338 static constexpr bool has_account_discovery = false;
339
341 static constexpr bool has_client_order_id = false;
342
344 static constexpr bool has_trigger_price = true;
345
347 static constexpr bool data_only = false;
348
350 static constexpr bool has_working_orders = true;
351
356 static constexpr bool has_amendable_quantity = true;
357
362 static constexpr bool working_orders_state_terminal = false;
363
365 static constexpr bool has_order_by_id = false;
366
368 static constexpr bool has_partial_cancel = true;
369
371 static constexpr bool history_requires_range = true;
372
374 static constexpr bool has_history_cursor = false;
375
380 static constexpr bool has_history_limit = false;
381
383 static constexpr bool has_history_symbol_filter = false;
384};
385
386} // namespace traits_detail
387} // namespace kis
388
394inline constexpr Venue kis_effective_route(Venue asked) noexcept {
395 return asked == Venue::UNSPECIFIED ? Venue::KRX : asked;
396}
397
399template <>
400struct BrokerTraits<kis::KisClient>
401: kis::traits_detail::Normalizers, kis::traits_detail::Capabilities {
407 static constexpr Venue effective_route(Venue asked) noexcept {
408 return kis_effective_route(asked);
409 }
410
413
416
419
422
425
428
431
434
436 static constexpr std::string_view name = kis::Broker::name;
437
439 static constexpr bool blocking = false;
440
446 static const network::RateLimitStats* rate_limit_stats(const Client& client) {
447 return client.rate_limit_stats();
448 }
449
458 template <typename Token>
459 static auto instrument(Client& client, InstrumentId subject, Token&& token) {
460 return client.async_instrument(std::move(subject), std::forward<Token>(token));
461 }
462
472 template <typename Token>
473 static auto calendar(Client& client, Country, std::optional<Date> from, Token&& token) {
474 return client.async_calendar(
475 from ? *from : kis::today_in_seoul(), false, std::forward<Token>(token)
476 );
477 }
478
487 template <typename Token>
488 static auto price_limits(Client& client, InstrumentId instrument, Token&& token) {
489 return client.async_price_limits(std::move(instrument), std::forward<Token>(token));
490 }
491
501 template <typename Token>
502 static auto trades(Client& client, InstrumentId instrument, int count, Token&& token) {
503 return client.async_trades(std::move(instrument), count, std::forward<Token>(token));
504 }
505
514 template <typename Token>
515 static auto depth(Client& client, InstrumentId instrument, Token&& token) {
516 return client.async_depth(std::move(instrument), std::forward<Token>(token));
517 }
518
527 template <typename Token>
528 static auto bars(Client& client, BarQuery query, Token&& token) {
529 return client.async_bars(std::move(query), std::forward<Token>(token));
530 }
531
540 template <typename Token>
541 static auto quote(Client& client, InstrumentId instrument, Token&& token) {
542 return client.async_quote(std::move(instrument), std::forward<Token>(token));
543 }
544
554 template <typename Token>
555 static auto buying_power(Client& client, const Account& account, Currency currency, Token&& token) {
556 return client.async_buying_power(currency, account, std::forward<Token>(token));
557 }
558
567 template <typename Token>
568 static auto holdings(Client& client, const Account& account, Token&& token) {
569 return client.async_holdings(account, std::forward<Token>(token));
570 }
571
581 template <typename Token>
582 static auto place_order(Client& client, const Account& account, OrderRequest order, Token&& token) {
583 return client.async_place_order(account, std::move(order), std::forward<Token>(token));
584 }
585
595 template <typename Token>
596 static auto replace_order(
597 Client& client,
598 const Account& account,
599 Amendment amendment,
600 Token&& token
601 ) {
602 return client.async_replace_order(account, std::move(amendment), std::forward<Token>(token));
603 }
604
614 template <typename Token>
615 static auto cancel_order(
616 Client& client,
617 const Account& account,
618 Amendment amendment,
619 Token&& token
620 ) {
621 return client.async_cancel_order(account, std::move(amendment), std::forward<Token>(token));
622 }
623
632 template <typename Token>
633 static auto working_orders(Client& client, const Account& account, Token&& token) {
634 return client.async_open_orders(account, std::forward<Token>(token));
635 }
636
646 template <typename Token>
647 static auto order_history(
648 Client& client,
649 const Account& account,
650 HistoryQuery query,
651 Token&& token
652 ) {
653 return client.async_order_history(account, query, std::forward<Token>(token));
654 }
655};
656
658template <>
659struct BrokerTraits<kis::KisBlockingClient>
660: kis::traits_detail::Normalizers, kis::traits_detail::Capabilities {
666 static constexpr Venue effective_route(Venue asked) noexcept {
667 return kis_effective_route(asked);
668 }
669
672
675
678
681
684
687
690
693
695 static constexpr std::string_view name = kis::Broker::name;
696
698 static constexpr bool blocking = true;
699
705 static const network::RateLimitStats* rate_limit_stats(const Client& client) {
706 return client.rate_limit_stats();
707 }
708
716 return client.instrument(std::move(subject));
717 }
718
725 static Result<TradingCalendar> calendar(Client& client, Country, std::optional<Date> from) {
726 return client.calendar(from ? *from : kis::today_in_seoul());
727 }
728
736 return client.price_limits(std::move(instrument));
737 }
738
747 Client& client,
749 int count
750 ) {
751 return client.trades(std::move(instrument), count);
752 }
753
761 return client.depth(std::move(instrument));
762 }
763
770 static Result<BarSeries> bars(Client& client, BarQuery query) {
771 return client.bars(std::move(query));
772 }
773
781 return client.quote(std::move(instrument));
782 }
783
790 static Result<HoldingsSnapshot> holdings(Client& client, const Account& account) {
791 return client.holdings(account);
792 }
793
802 Client& client,
803 const Account& account,
804 Currency currency
805 ) {
806 return client.buying_power(currency, account);
807 }
808
816 static Result<PlaceAck> place_order(Client& client, const Account& account, OrderRequest order) {
817 return client.place_order(account, std::move(order));
818 }
819
828 Client& client,
829 const Account& account,
830 Amendment amendment
831 ) {
832 return client.replace_order(account, std::move(amendment));
833 }
834
843 Client& client,
844 const Account& account,
845 Amendment amendment
846 ) {
847 return client.cancel_order(account, std::move(amendment));
848 }
849
857 return client.open_orders(account);
858 }
859
868 Client& client,
869 const Account& account,
870 HistoryQuery query
871 ) {
872 return client.order_history(account, query);
873 }
874};
875
876} // 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
Result(T value)
Constructs a successful result.
Definition types.hpp:803
BrokerError & error()
Returns the error.
Definition types.hpp:842
T & value()
Returns the value.
Definition types.hpp:828
A blocking KIS client: each call runs a KisClient request on a private event loop and returns its res...
Definition client.hpp:4540
Result< TradingCalendar > calendar(Date from, bool refresh=false)
Returns the trading calendar from a date on; see KisClient::async_calendar (cached).
Definition client.hpp:4585
Result< OrderPage > order_history(KisAccount account, KisHistoryRange range)
Returns the orders placed over a date range, with their fills.
Definition client.hpp:4741
Result< QuoteSnapshot > quote(InstrumentId instrument)
Returns a quote; see KisClient::async_quote.
Definition client.hpp:4560
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:4697
Result< BuyingPower > buying_power(Currency currency, KisAccount account)
Returns the account's buying power, in won.
Definition client.hpp:4661
Result< std::vector< TradePrint > > trades(InstrumentId instrument, int count)
Returns an instrument's recent trades.
Definition client.hpp:4610
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:4728
Result< HoldingsSnapshot > holdings(KisAccount account)
Returns the account's holdings.
Definition client.hpp:4648
Result< Instrument > instrument(InstrumentId subject)
Returns an instrument's reference data.
Definition client.hpp:4572
Result< PriceLimits > price_limits(InstrumentId instrument)
Returns an instrument's price band for today.
Definition client.hpp:4597
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics (safe to read between calls).
Definition client.hpp:4754
Result< DepthSnapshot > depth(InstrumentId instrument)
Returns the order book (ten levels a side).
Definition client.hpp:4624
Result< BarSeries > bars(BarQuery query)
Returns bars; see KisClient::async_bars.
Definition client.hpp:4636
Result< KisOrderAck > place_order(KisAccount account, OrderRequest order)
Places a cash order; see KisClient::async_place_order.
Definition client.hpp:4681
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:4713
The asynchronous KIS REST client: market data, account inquiries and orders for domestic stocks.
Definition client.hpp:324
auto async_place_order(KisAccount account, OrderRequest order, CompletionToken &&token)
Places a cash order.
Definition client.hpp:656
auto async_quote(InstrumentId instrument, CompletionToken &&token)
Requests a quote.
Definition client.hpp:566
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:455
auto async_cancel_order(KisAccount account, KisAmendment amendment, CompletionToken &&token)
Cancels an order (all or part of it, as amendment says).
Definition client.hpp:737
auto async_trades(InstrumentId instrument, int count, CompletionToken &&token)
Requests an instrument's recent trades.
Definition client.hpp:509
auto async_holdings(KisAccount account, CompletionToken &&token)
Requests the account's holdings.
Definition client.hpp:614
auto async_order_history(KisAccount account, KisHistoryRange range, CompletionToken &&token)
Requests the orders placed over a date range, with their fills.
Definition client.hpp:805
const network::RateLimitStats * rate_limit_stats() const
Returns the rate limiter's statistics.
Definition client.hpp:837
auto async_open_orders(KisAccount account, CompletionToken &&token)
Requests every order that can still be amended or cancelled.
Definition client.hpp:777
auto async_instrument(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's reference data.
Definition client.hpp:427
auto async_replace_order(KisAccount account, KisAmendment amendment, CompletionToken &&token)
Amends an order's price or quantity.
Definition client.hpp:692
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:590
auto async_price_limits(InstrumentId instrument, CompletionToken &&token)
Requests an instrument's price band for today (from its current-price inquiry).
Definition client.hpp:478
auto async_depth(InstrumentId instrument, CompletionToken &&token)
Requests the order book (ten levels a side).
Definition client.hpp:543
auto async_bars(BarQuery query, CompletionToken &&token)
Requests bars, reading KIS pages until count_ bars are collected.
Definition client.hpp:404
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:200
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:257
constexpr bool publishes_bar_interval(BarInterval interval) noexcept
Tests whether KIS publishes a chart at an interval.
Definition client.hpp:277
std::optional< BrokerError > unsupported_bar_interval(BarInterval interval)
Refuses a bar interval KIS publishes no chart for (publishes_bar_interval).
Definition client.hpp:299
The library: broker-neutral types (core), and the modules below.
SellableSource
Where the library gets a broker's sellable quantity.
Definition types.hpp:1092
@ HOLDINGS
On the holdings snapshot, at no extra request.
Definition types.hpp:1094
@ 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
constexpr Venue kis_effective_route(Venue asked) noexcept
Returns the venue a KIS order actually reaches.
Definition traits.hpp:394
std::optional< Decimal64 > amended_trigger_price(const AmendInstruction &instruction)
Returns the trigger price an amendment leaves the order with.
Definition types.hpp:2271
A modification or cancellation of a working order.
Definition types.hpp:2240
Venue venue_
The venue the order rests at, for a broker whose amendment needs it (KIS).
Definition types.hpp:2248
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
kis::KisAccount Account
The account type.
Definition traits.hpp:677
static Result< DepthSnapshot > depth(Client &client, InstrumentId instrument)
Returns the order book.
Definition traits.hpp:760
static Result< BarSeries > bars(Client &client, BarQuery query)
Returns bars, paging inside the client.
Definition traits.hpp:770
kis::KisConfig Config
The configuration type.
Definition traits.hpp:674
kis::KisBlockingClient Client
The client type.
Definition traits.hpp:671
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:705
kis::KisHistoryRange HistoryQuery
The order-history query type.
Definition traits.hpp:689
static Result< TradingCalendar > calendar(Client &client, Country, std::optional< Date > from)
Returns the calendar, supplying today when no date was given.
Definition traits.hpp:725
static Result< OrderPage > order_history(Client &client, const Account &account, HistoryQuery query)
Returns order history for the bound account.
Definition traits.hpp:867
static Result< Instrument > instrument(Client &client, InstrumentId subject)
Returns static reference data for one instrument.
Definition traits.hpp:715
static Result< std::vector< TradePrint > > trades(Client &client, InstrumentId instrument, int count)
Returns recent executions.
Definition traits.hpp:746
static constexpr std::string_view name
The broker's name.
Definition traits.hpp:695
static Result< PriceLimits > price_limits(Client &client, InstrumentId instrument)
Returns today's price bounds.
Definition traits.hpp:735
static Result< BuyingPower > buying_power(Client &client, const Account &account, Currency currency)
Returns what the bound account may spend in currency.
Definition traits.hpp:801
static constexpr bool blocking
true: requests return their result directly.
Definition traits.hpp:698
static constexpr Venue effective_route(Venue asked) noexcept
Where an order carrying asked actually goes; see kis_effective_route.
Definition traits.hpp:666
kis::KisAmendment Amendment
The amendment type.
Definition traits.hpp:686
static Result< PlaceAck > cancel_order(Client &client, const Account &account, Amendment amendment)
Cancels an order for the bound account.
Definition traits.hpp:842
static Result< WorkingOrdersResult > working_orders(Client &client, const Account &account)
Returns the amendable orders for the bound account.
Definition traits.hpp:856
kis::KisOpenOrderPage WorkingOrdersResult
The working-order result type.
Definition traits.hpp:692
static Result< QuoteSnapshot > quote(Client &client, InstrumentId instrument)
Returns a quote.
Definition traits.hpp:780
static Result< PlaceAck > place_order(Client &client, const Account &account, OrderRequest order)
Submits an order for the bound account.
Definition traits.hpp:816
static Result< HoldingsSnapshot > holdings(Client &client, const Account &account)
Returns holdings for the bound account.
Definition traits.hpp:790
kis::KisOrderAck PlaceAck
The order acknowledgement type.
Definition traits.hpp:683
static Result< PlaceAck > replace_order(Client &client, const Account &account, Amendment amendment)
Modifies an order for the bound account.
Definition traits.hpp:827
kis::KisOrderAck PlaceAck
The order acknowledgement type.
Definition traits.hpp:424
static constexpr Venue effective_route(Venue asked) noexcept
Where an order carrying asked actually goes; see kis_effective_route.
Definition traits.hpp:407
static auto holdings(Client &client, const Account &account, Token &&token)
Forwards a holdings request for the bound account.
Definition traits.hpp:568
static auto replace_order(Client &client, const Account &account, Amendment amendment, Token &&token)
Forwards an order modification for the bound account.
Definition traits.hpp:596
static auto price_limits(Client &client, InstrumentId instrument, Token &&token)
Forwards a price-bound request.
Definition traits.hpp:488
static auto working_orders(Client &client, const Account &account, Token &&token)
Forwards an amendable-order inquiry for the bound account.
Definition traits.hpp:633
static auto bars(Client &client, BarQuery query, Token &&token)
Forwards a bar request.
Definition traits.hpp:528
kis::KisHistoryRange HistoryQuery
The order-history query type.
Definition traits.hpp:430
kis::KisConfig Config
The configuration type.
Definition traits.hpp:415
kis::KisOpenOrderPage WorkingOrdersResult
The working-order result type.
Definition traits.hpp:433
kis::KisClient Client
The client type.
Definition traits.hpp:412
static constexpr bool blocking
false: requests complete through a completion token.
Definition traits.hpp:439
static auto instrument(Client &client, InstrumentId subject, Token &&token)
Forwards a reference-data request for one instrument.
Definition traits.hpp:459
static auto quote(Client &client, InstrumentId instrument, Token &&token)
Forwards a quote request.
Definition traits.hpp:541
static auto trades(Client &client, InstrumentId instrument, int count, Token &&token)
Forwards a recent-execution request.
Definition traits.hpp:502
kis::Broker BrokerTag
The broker tag.
Definition traits.hpp:421
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:446
kis::KisAmendment Amendment
The amendment type.
Definition traits.hpp:427
kis::KisAccount Account
The account type.
Definition traits.hpp:418
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:473
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:555
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:647
static auto depth(Client &client, InstrumentId instrument, Token &&token)
Forwards an order book request.
Definition traits.hpp:515
static constexpr std::string_view name
The broker's name.
Definition traits.hpp:436
static auto place_order(Client &client, const Account &account, OrderRequest order, Token &&token)
Forwards an order submission for the bound account.
Definition traits.hpp:582
static auto cancel_order(Client &client, const Account &account, Amendment amendment, Token &&token)
Forwards an order cancellation for the bound account.
Definition traits.hpp:615
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 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
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
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
std::optional< Decimal64 > amendable_quantity_
How much the broker says may still be amended. Empty means it stated none, not zero.
Definition types.hpp:2296
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
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:29
An amendment or cancellation of a KIS order.
Definition client.hpp:115
bool all_remaining_
Whether the whole remaining quantity is affected (KIS's QTY_ALL_ORD_YN), rather than quantity_.
Definition client.hpp:139
OrderType type_
The order type it should have.
Definition client.hpp:119
KisOrderRef order_
The order to amend or cancel.
Definition client.hpp:117
std::optional< Decimal64 > trigger_price_
The trigger price (KIS's CNDT_PRIC), for a STOP_LIMIT order.
Definition client.hpp:137
OrderSession session_
The session it should be in.
Definition client.hpp:123
Decimal64 quantity_
The quantity affected; KIS requires a positive whole number even with all_remaining_.
Definition client.hpp:127
TimeInForce time_in_force_
The execution condition it should have.
Definition client.hpp:121
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:129
Venue venue_
The venue where the order rests (the codes differ by venue).
Definition client.hpp:125
KIS credentials (app key and secret), demo or real account, and the market-data tape.
Definition config.hpp:90
The date range of a KIS order-history inquiry, both ends included (Korean dates).
Definition client.hpp:189
KIS's list of orders that can still be amended or cancelled.
Definition client.hpp:181
KIS's acknowledgement of an accepted order, amendment or cancellation.
Definition client.hpp:148
A KIS order's address: branch number and order number, both kept.
Definition client.hpp:98
std::string order_number_
The order number within that branch (KIS's ODNO).
Definition client.hpp:102
std::string branch_number_
The branch that recorded the order (KIS's KRX_FWDG_ORD_ORGNO).
Definition client.hpp:100
A rate limiter's counters per traffic class, its current budget, and the broker's refusals (from Rate...