hikyuu2/hikyuu_cpp/hikyuu_server/main.cpp

48 lines
1.1 KiB
C++
Raw Normal View History

2021-02-28 01:05:03 +08:00
/*
* Copyright(C) 2021 hikyuu.org
*
* Create on: 2021-02-26
* Author: fasiondog
*/
2021-04-09 01:09:30 +08:00
#include <hikyuu/utilities/os.h>
2021-02-28 01:05:03 +08:00
#include "http/HttpServer.h"
2021-03-29 00:47:55 +08:00
#include "service/account/AccountService.h"
2021-03-22 01:38:03 +08:00
#include "service/assist/AssistService.h"
2021-03-30 01:01:38 +08:00
#include "service/trade/TradeService.h"
2021-03-04 01:17:21 +08:00
2021-02-28 01:05:03 +08:00
using namespace hku;
2021-03-22 01:38:03 +08:00
#define HKU_SERVICE_API(name) "/hku/" #name "/v1"
2021-02-28 01:05:03 +08:00
int main(int argc, char* argv[]) {
2021-03-12 01:39:24 +08:00
init_server_logger();
LOG_INFO("start server ... You can press Ctrl-C stop");
2021-03-04 01:17:21 +08:00
2021-03-28 00:53:51 +08:00
HttpServer server("http://*", 9001);
2021-03-07 01:17:40 +08:00
2021-04-09 01:09:30 +08:00
try {
AccountService login(HKU_SERVICE_API(account));
login.bind(&server);
2021-02-28 01:05:03 +08:00
2021-04-09 01:09:30 +08:00
AssistService assist(HKU_SERVICE_API(assist));
assist.bind(&server);
2021-03-22 01:38:03 +08:00
2021-04-09 01:09:30 +08:00
TradeService trade(HKU_SERVICE_API(trade),
fmt::format("{}/.hikyuu/trade.ini", getUserHome()));
trade.bind(&server);
server.start();
} catch (std::exception& e) {
LOG_FATAL(e.what());
server.stop();
} catch (...) {
LOG_FATAL("Unknow error!");
server.stop();
}
2021-03-30 01:01:38 +08:00
2021-02-28 01:05:03 +08:00
return 0;
}