Longbridge OpenAPI C++ SDK
trade_context.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "async_result.hpp"
4 #include "callback.hpp"
5 #include "config.hpp"
6 #include "push.hpp"
7 #include "types.hpp"
8 
10 
11 namespace longbridge {
12 namespace trade {
13 
16 {
17 private:
18  const lb_trade_context_t* ctx_;
19 
20 public:
26 
28 
29  size_t ref_count() const;
30 
31  static TradeContext create(const Config& config);
32 
34  void subscribe(const std::vector<TopicType>& topics,
35  AsyncCallback<TradeContext, void> callback) const;
36 
38  void unsubscribe(const std::vector<TopicType>& topics,
39  AsyncCallback<TradeContext, void> callback) const;
40 
45 
48  const std::optional<GetHistoryExecutionsOptions>& opts,
49  AsyncCallback<TradeContext, std::vector<Execution>> callback) const;
50 
53  const std::optional<GetTodayExecutionsOptions>& opts,
54  AsyncCallback<TradeContext, std::vector<Execution>> callback) const;
55 
58  const std::optional<GetAllExecutionsOptions>& opts,
60 
63  const std::optional<GetHistoryOrdersOptions>& opts,
64  AsyncCallback<TradeContext, std::vector<Order>> callback) const;
65 
68  const std::optional<GetTodayOrdersOptions>& opts,
69  AsyncCallback<TradeContext, std::vector<Order>> callback) const;
70 
73  AsyncCallback<TradeContext, void> callback) const;
74 
77  const SubmitOrderOptions& opts,
79 
84  const SubmitMultiLegOrderOptions& opts,
86 
88  void cancel_order(const std::string& order_id,
90  bool is_attached = false) const;
91 
94  const std::string& currency,
95  AsyncCallback<TradeContext, std::vector<AccountBalance>> callback) const;
96 
99  AsyncCallback<TradeContext, std::vector<AccountBalance>> callback) const;
100 
103  const GetCashFlowOptions& opts,
104  AsyncCallback<TradeContext, std::vector<CashFlow>> callback) const;
105 
108  const std::optional<GetFundPositionsOptions>& opts,
110 
113  const std::optional<GetStockPositionsOptions>& opts,
115 
117  void margin_ratio(const std::string& symbol,
119 
121  void order_detail(const std::string& order_id,
123 
126  const std::string& order_id,
128 
134  const;
135 
140 };
141 
142 } // namespace trade
143 } // namespace longbridge
Definition: config.hpp:16
Trade context.
Definition: trade_context.hpp:16
void history_orders(const std::optional< GetHistoryOrdersOptions > &opts, AsyncCallback< TradeContext, std::vector< Order >> callback) const
Get history orders.
void set_on_order_changed(PushCallback< TradeContext, PushOrderChanged > callback) const
void estimate_max_purchase_quantity(const EstimateMaxPurchaseQuantityOptions &opts, AsyncCallback< TradeContext, EstimateMaxPurchaseQuantityResponse > callback) const
void account_balance(const std::string &currency, AsyncCallback< TradeContext, std::vector< AccountBalance >> callback) const
Get account balance with currency.
void stock_positions(const std::optional< GetStockPositionsOptions > &opts, AsyncCallback< TradeContext, StockPositionsResponse > callback) const
Get stock positions.
TradeContext(const TradeContext &ctx)
void all_executions(const std::optional< GetAllExecutionsOptions > &opts, AsyncCallback< TradeContext, AllExecutionsResponse > callback) const
Get all executions.
void history_executions(const std::optional< GetHistoryExecutionsOptions > &opts, AsyncCallback< TradeContext, std::vector< Execution >> callback) const
Get history executions.
void unsubscribe(const std::vector< TopicType > &topics, AsyncCallback< TradeContext, void > callback) const
Unsubscribe.
void account_balance(const GetCashFlowOptions &opts, AsyncCallback< TradeContext, std::vector< CashFlow >> callback) const
Get cash flow.
TradeContext & operator=(const TradeContext &ctx)
void account_balance(AsyncCallback< TradeContext, std::vector< AccountBalance >> callback) const
Get account balance.
void margin_ratio(const std::string &symbol, AsyncCallback< TradeContext, MarginRatio > callback) const
Get margin ratio.
TradeContext(TradeContext &&ctx)
TradeContext(const lb_trade_context_t *ctx)
void subscribe(const std::vector< TopicType > &topics, AsyncCallback< TradeContext, void > callback) const
Subscribe.
void submit_order(const SubmitOrderOptions &opts, AsyncCallback< TradeContext, SubmitOrderResponse > callback) const
Submit order.
void submit_multileg(const SubmitMultiLegOrderOptions &opts, AsyncCallback< TradeContext, SubmitOrderResponse > callback) const
void order_detail_attached(const std::string &order_id, AsyncCallback< TradeContext, OrderDetail > callback) const
Get order detail with attached orders.
void today_orders(const std::optional< GetTodayOrdersOptions > &opts, AsyncCallback< TradeContext, std::vector< Order >> callback) const
Get history orders.
void cancel_order(const std::string &order_id, AsyncCallback< TradeContext, void > callback, bool is_attached=false) const
Cancel order.
void set_on_grid_order_changed(PushCallback< TradeContext, PushGridOrderChanged > callback) const
void fund_positions(const std::optional< GetFundPositionsOptions > &opts, AsyncCallback< TradeContext, FundPositionsResponse > callback) const
Get fund positions.
void today_executions(const std::optional< GetTodayExecutionsOptions > &opts, AsyncCallback< TradeContext, std::vector< Execution >> callback) const
Get today executions.
static TradeContext create(const Config &config)
void order_detail(const std::string &order_id, AsyncCallback< TradeContext, OrderDetail > callback) const
Get order detail.
void replace_order(const ReplaceOrderOptions &opts, AsyncCallback< TradeContext, void > callback) const
Replace order.
Definition: agent_context.hpp:13
std::function< void(PushEvent< Ctx, T >)> PushCallback
Definition: push.hpp:27
std::function< void(AsyncResult< Ctx, T >)> AsyncCallback
Definition: async_result.hpp:48
Options for estimate maximum purchase quantity.
Definition: types.hpp:2420
Options for submit order request.
Definition: types.hpp:2135
Options for replace order request.
Definition: types.hpp:1924
Options for submit multi-leg order request.
Definition: types.hpp:2016
Options for submit order request.
Definition: types.hpp:1953
struct lb_trade_context_t lb_trade_context_t
Definition: trade_context.hpp:9