PluginInstance.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #include <string>
  3. #include <mutex>
  4. #include <memory>
  5. #include <thread>
  6. #include <functional>
  7. #include <cpp_redis/cpp_redis>
  8. #include <WinSock2.h>
  9. #pragma comment(lib, "ws2_32.lib")
  10. #pragma comment(lib, "tacopie.lib")
  11. #pragma comment(lib, "cpp_redis.lib")
  12. #include <ScopeGuard.hpp>
  13. struct position_context
  14. {
  15. UINT64 level;
  16. UINT64 position_id;
  17. UINT64 request_id;
  18. UINT64 cur_ord;
  19. UINT64 volume; // Õý±íʾbuy£¬¸º±íʾsell
  20. };
  21. struct request_cache
  22. {
  23. UINT64 request;
  24. UINT64 orig_position;
  25. //UINT64 dest_position;
  26. UINT64 login;
  27. };
  28. class CPluginInstance
  29. : public IMTServerPlugin
  30. , public IMTConPluginSink
  31. //, public IMTOrderSink
  32. , public IMTTradeSink
  33. {
  34. public:
  35. CPluginInstance();
  36. virtual ~CPluginInstance();
  37. virtual void Release();
  38. virtual MTAPIRES Start(IMTServerAPI* server);
  39. virtual MTAPIRES Stop();
  40. virtual void OnPluginUpdate(const IMTConPlugin* plugin);
  41. //virtual void OnOrderAdd(const IMTOrder* order);
  42. //virtual void OnOrderUpdate(const IMTOrder* order);
  43. //virtual void OnOrderDelete(const IMTOrder* order);
  44. //virtual void OnOrderClean(const UINT64 login);
  45. //virtual void OnDealAdd(const IMTDeal* deal);
  46. //virtual void OnDealUpdate(const IMTDeal* deal);
  47. //virtual void OnDealDelete(const IMTDeal* deal);
  48. //virtual void OnDealClean(const UINT64 login);
  49. //virtual void OnDealPerform(const IMTDeal* deal, IMTAccount* account, IMTPosition* position);
  50. virtual void OnTradeRequestProcess(const IMTRequest* request, const IMTConfirm* confirm, const IMTConGroup* group,
  51. const IMTConSymbol* symbol, const IMTPosition* position, const IMTOrder* order, const IMTDeal* deal);
  52. template<typename ...Args>
  53. void DebugOut(const UINT code, LPCWSTR msg, Args... args)
  54. {
  55. if (m_debug_mode)
  56. {
  57. m_api->LoggerOut(code, msg, args...);
  58. }
  59. }
  60. protected:
  61. virtual MTAPIRES LoadParam();
  62. private:
  63. IMTServerAPI* m_api;
  64. IMTConPlugin* m_config;
  65. MTServerInfo m_info;
  66. std::mutex m_lock;
  67. bool m_enable;
  68. MTAPIRES LoadLogins();
  69. std::vector<UINT64> m_followers;
  70. std::shared_ptr<cpp_redis::client> m_redis_client;
  71. bool m_redis_conn;
  72. bool start_redis();
  73. void stop_redis();
  74. void keep_alive();
  75. bool m_redis_error_notified;
  76. std::thread m_work_thread;
  77. std::string m_redis_server;
  78. //std::string m_redis_user;
  79. std::string m_redis_password;
  80. int m_redis_port;
  81. wchar_t m_groups[1024];
  82. //std::wstring m_logins;
  83. UINT64 m_trader;
  84. UINT64 m_dealer;
  85. //int m_step;
  86. //int m_tolerance;
  87. int m_debug_mode;
  88. };