| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #pragma once
- #include <memory>
- #include <mutex>
- #include <thread>
- #include <ScopeGuard.hpp>
- #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 <log/logger.h>
- #include "Misc.h"
- 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 CManagerExtension
- : public IMTManagerSink
- , public IMTOrderSink
- , public IMTDealerSink
- , public IMTDealSink
- {
- //--- constants
- enum
- {
- CONNECTION_TIMEOUT = 30000,
- };
- private:
- CMTManagerAPIFactory m_factory; // Manager API factory
- IMTManagerAPI *m_manager; // Manager interface
- IMTManagerAPI *m_manager_pumping; // Manager interface(pumping mode)
- //IMTAdminAPI *m_admin; // Administrator API
- public:
- CManagerExtension();
- ~CManagerExtension();
- //--- init and shutdown
- bool Initialize();
- void Shutdown();
- //--- connect, disconnect
- bool Connect(const CMTStr &server, const UINT64 login, const CMTStr &password);
- void Disconnect();
- //virtual void OnOrderAdd(const IMTOrder* order);
- virtual void OnOrderDelete(const IMTOrder* order);
- virtual void OnConnect();
- virtual void OnDisconnect();
- virtual void OnDealPerform(const IMTDeal* deal, IMTAccount* account, IMTPosition* position);
- void SetTrader(const UINT64 trader);
- void SetGroups(const std::string& groups);
- void SetStep(const int step);
- void SetTolerance(const int tolerance);
- void SetRedisServer(const std::string& server);
- void SetRedisPort(const int port);
- void SetRedisPassword(const std::string& password);
- void SetLogger(const std::shared_ptr<tools::logger>& logger);
- void LogOut(const tools::logger::log_level level, const char* log, ...);
- private:
- std::shared_ptr<tools::logger> m_logger;
- std::mutex m_lock;
- std::atomic<bool> m_run;
- 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_password;
- int m_redis_port;
- std::string m_groups;
- //std::wstring m_logins;
- UINT64 m_trader;
- int m_step;
- int m_tolerance;
- std::vector<UINT64> m_logins;
- MTAPIRES LoadLogins();
- UINT64 m_dealer_login;
- };
|