#ifndef SERVICE_H #define SERVICE_H #include #include #include #include #include #include #include #include #include #include namespace beast = boost::beast; namespace http = beast::http; namespace net = boost::asio; using tcp = boost::asio::ip::tcp; struct PlatformData { double price; double deviationCompensation; bool isOpenLong; bool isOpenShort; std::vector pricesHistory; // 用于存储历史价格以计算平均值 }; class MyService { public: MyService(unsigned short port); void start(); private: void doHttpSession(tcp::socket socket); void doWebSocketSession(tcp::socket socket); void onHttpRequest(http::request req); void onWebSocketMessage(const std::string& message); void updatePrice(const std::string &platform, double price); void adjustDecimalPoints(); void checkDeviationCompensation(); void calculateAveragePrices(); void calculateDeviationPercentage(); void determinePosition(); unsigned short port_; std::map platforms_; // 存储每个平台的数据 std::chrono::time_point lastCompensationTime_; std::mutex dataMutex_; const int compensationIntervalMinutes = 120; // 默认2小时 const int averagePeriodMinutes = 15; // 默认15分钟 const double entryThresholdPercentage = 0.01; // 示例开仓条件百分比 }; #endif // SERVICE_H