| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #pragma once
- #include <string>
- #include <mutex>
- #include <memory>
- #include <thread>
- #include <functional>
- #include <cpp_redis/cpp_redis>
- #include <WinSock2.h>
- #pragma comment(lib, "ws2_32.lib")
- #pragma comment(lib, "tacopie.lib")
- #pragma comment(lib, "cpp_redis.lib")
- #include <ScopeGuard.hpp>
- struct position_context
- {
- UINT64 level;
- UINT64 position_id;
- UINT64 request_id;
- UINT64 cur_ord;
- UINT64 volume; // Õý±íʾbuy£¬¸º±íʾsell
- };
- struct request_cache
- {
- UINT64 request;
- UINT64 orig_position;
- //UINT64 dest_position;
- UINT64 login;
- };
- class CPluginInstance
- : public IMTServerPlugin
- , public IMTConPluginSink
- //, public IMTOrderSink
- , public IMTTradeSink
- {
- public:
- CPluginInstance();
- virtual ~CPluginInstance();
- virtual void Release();
- virtual MTAPIRES Start(IMTServerAPI* server);
- virtual MTAPIRES Stop();
- virtual void OnPluginUpdate(const IMTConPlugin* plugin);
- //virtual void OnOrderAdd(const IMTOrder* order);
- //virtual void OnOrderUpdate(const IMTOrder* order);
- //virtual void OnOrderDelete(const IMTOrder* order);
- //virtual void OnOrderClean(const UINT64 login);
- //virtual void OnDealAdd(const IMTDeal* deal);
- //virtual void OnDealUpdate(const IMTDeal* deal);
- //virtual void OnDealDelete(const IMTDeal* deal);
- //virtual void OnDealClean(const UINT64 login);
- //virtual void OnDealPerform(const IMTDeal* deal, IMTAccount* account, IMTPosition* position);
- virtual void OnTradeRequestProcess(const IMTRequest* request, const IMTConfirm* confirm, const IMTConGroup* group,
- const IMTConSymbol* symbol, const IMTPosition* position, const IMTOrder* order, const IMTDeal* deal);
- template<typename ...Args>
- void DebugOut(const UINT code, LPCWSTR msg, Args... args)
- {
- if (m_debug_mode)
- {
- m_api->LoggerOut(code, msg, args...);
- }
- }
- protected:
- virtual MTAPIRES LoadParam();
- private:
- IMTServerAPI* m_api;
- IMTConPlugin* m_config;
- MTServerInfo m_info;
- std::mutex m_lock;
- bool m_enable;
- MTAPIRES LoadLogins();
- std::vector<UINT64> m_followers;
- std::shared_ptr<cpp_redis::client> m_redis_client;
- bool m_redis_conn;
- bool start_redis();
- void stop_redis();
- void keep_alive();
- bool m_redis_error_notified;
- std::thread m_work_thread;
- std::string m_redis_server;
- //std::string m_redis_user;
- std::string m_redis_password;
- int m_redis_port;
- wchar_t m_groups[1024];
- //std::wstring m_logins;
- UINT64 m_trader;
- UINT64 m_dealer;
- //int m_step;
- //int m_tolerance;
- int m_debug_mode;
- };
|