// MT5MonkMAM.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <iostream>

#include <ini/Settings.h>

int main()
{

	Settings set("MT5MonkMAM.ini");
	Dictionary dict = set.GetSection("MT5");
	std::string server = dict.GetString("Server");
	UINT64 login = dict.GetInt("Login");
	std::string password = dict.GetString("Password");

	dict = set.GetSection("MAM");
	UINT64 trader = dict.GetInt("Trader");
	std::string groups = dict.GetString("Groups");
	UINT step = dict.GetInt("Step");
	UINT tolerance = dict.GetInt("Tolerance");

	dict = set.GetSection("Redis");
	std::string redis_server = dict.GetString("Server");
	UINT64 redis_port = dict.GetInt("Port");
	std::string redis_password = dict.GetString("Password");

	dict = set.GetSection("Log");
	int log_channel = dict.GetInt("Channel");
	int log_level = dict.GetInt("Level");

	std::shared_ptr<tools::logger> logger(new tools::logger("MT5MonkMAM.log", tools::logger::FILE | tools::logger::SCREEN));
	logger->set_level(tools::logger::LVERROR);

	if (log_channel == 1 || log_channel == 2 || log_channel == 3)
	{
		logger->set_handler(log_channel);
	}

	if (log_level > 0)
	{
		logger->set_level(tools::logger::log_level(log_level));
	}


	CManagerExtension manager;
	manager.SetTrader(trader);
	manager.SetGroups(groups);
	manager.SetStep(step);
	manager.SetTolerance(tolerance);

	manager.SetRedisServer(redis_server);
	manager.SetRedisPort(redis_port);
	manager.SetRedisPassword(redis_password);

	manager.SetLogger(logger);

	CMTStr128 srv;
	CMTStr128 pass;
	srv.Assign(s2ws(server).c_str());
	pass.Assign(s2ws(password).c_str());
	manager.Initialize();
	manager.Connect(srv, login, pass);

	//std::cout << "Connected" << std::endl;

	getchar();

	return 0;
}

