TinkoffInvestSDK
ordersstreamservice.h
1 #ifndef ORDERSSTREAMSERVICE_H
2 #define ORDERSSTREAMSERVICE_H
3 
4 #include <thread>
5 #include "customservice.h"
6 #include <grpcpp/grpcpp.h>
7 #include "orders.grpc.pb.h"
8 #include "servicereply.h"
9 
10 using grpc::ClientAsyncReader;
11 using grpc::Channel;
12 using grpc::CompletionQueue;
13 
14 using namespace tinkoff::public_::invest::api::contract::v1;
15 
22 {
23 
24 public:
25  OrdersStream(std::shared_ptr<Channel> channel, const std::string &token);
26  ~OrdersStream();
27 
29  void TradesStream(const std::vector<std::string> &accounts, std::function<void(ServiceReply)> callback);
31  void TradesStreamAsync(const std::vector<std::string> &accounts, std::function<void(ServiceReply)> callback);
32  void AsyncCompleteRpc();
33 
34 private:
35 
36  class AsyncClientCall
37  {
38 
39  public:
40  AsyncClientCall(const TradesStreamRequest& request, CompletionQueue& cq_, std::unique_ptr<OrdersStreamService::Stub>& stub_, std::string token, std::function<void(ServiceReply)> callback);
41  ~AsyncClientCall(){}
42 
43  ClientContext context;
44  TradesStreamResponse reply;
45  enum CallStatus {CREATE, PROCESS, FINISH};
46  CallStatus callStatus;
47  Status status;
48 
49  void Proceed(bool ok = true);
50 
51  private:
52  std::unique_ptr<ClientAsyncReader<TradesStreamResponse> > responder;
53  std::function<void(ServiceReply)> callback;
54 
55  };
56 
57  std::unique_ptr<OrdersStreamService::Stub> m_ordersStreamService;
58  std::unique_ptr<std::thread> m_grpcThread;
59  CompletionQueue m_cq;
60 
61 };
62 
63 #endif // ORDERSSTREAMSERVICE_H
CustomService
Родительский класс для всех сервисов
Definition: customservice.h:14
ServiceReply
Класс-обертка над proto-ответами сервисов
Definition: servicereply.h:17
OrdersStream
Сервис торговых поручений в режиме стриминга
Definition: ordersstreamservice.h:21