TinkoffInvestSDK
marketdatastreamservice.h
1 #ifndef MARKETDATASTREAMSERVICE_H
2 #define MARKETDATASTREAMSERVICE_H
3 
4 #include <vector>
5 #include <set>
6 #include <thread>
7 #include <grpcpp/grpcpp.h>
8 #include "customservice.h"
9 #include "marketdata.grpc.pb.h"
10 #include "servicereply.h"
11 #include "rpchandler.h"
12 
13 using grpc::Channel;
14 using grpc::ClientAsyncReaderWriter;
15 using grpc::CompletionQueue;
16 
17 using namespace tinkoff::public_::invest::api::contract::v1;
18 
19 using CallbackFunc = std::function<void (ServiceReply)>;
20 
31 {
32 
33 public:
34  MarketDataStream(std::shared_ptr<Channel> channel, const std::string &token);
36 
38  void SubscribeCandles(const std::vector<std::pair<std::string, SubscriptionInterval>> &candleInstruments, CallbackFunc callback);
40  void SubscribeOrderBook(const std::string &figi, int32_t depth, CallbackFunc callback);
42  void SubscribeTrades(const std::vector<std::string> &figis, CallbackFunc callback);
44  void SubscribeInfo(const std::vector<std::string> &figis, CallbackFunc callback);
46  void SubscribeLastPrice(const std::vector<std::string> &figis, CallbackFunc callback);
47 
49  void SubscribeCandlesAsync(const std::vector<std::pair<std::string, SubscriptionInterval>> &candleInstruments, CallbackFunc callback);
51  void SubscribeOrderBookAsync(const std::string &figi, int32_t depth, CallbackFunc callback);
53  void SubscribeTradesAsync(const std::vector<std::string> &figis, CallbackFunc callback);
55  void SubscribeInfoAsync(const std::vector<std::string> &figis, CallbackFunc callback);
57  void SubscribeLastPriceAsync(const std::vector<std::string> &figis, CallbackFunc callback);
58 
60  void UnSubscribeCandles();
62  void UnSubscribeOrderBook();
64  void UnSubscribeTrades();
66  void UnSubscribeLastPrice();
68  void UnSubscribeInfo();
69 
70 private:
71  CompletionQueue m_cq;
72  std::unique_ptr<MarketDataStreamService::Stub> m_marketDataStreamService;
73  std::unique_ptr<std::thread> m_grpcThread;
74  std::set<std::shared_ptr<MarketDataHandler>> m_currentHandlers;
75 
76  void SendRequest(const MarketDataRequest &request, CallbackFunc callback);
77 
78 };
79 
80 #endif // MARKETDATASTREAMSERVICE_H
MarketDataStream
Сервис получения биржевой информации в режиме стриминга
Definition: marketdatastreamservice.h:30
CustomService
Родительский класс для всех сервисов
Definition: customservice.h:14
ServiceReply
Класс-обертка над proto-ответами сервисов
Definition: servicereply.h:17