Ver Fonte

修改登录方式相关

KarsusNeko há 6 anos atrás
pai
commit
5617210ce8

+ 0 - 1
MT5MonkPAMM/MT5MonkMAM.cpp

@@ -17,7 +17,6 @@ MTPluginParam ExtPluginDefaults[] =
 {
 	{ MTPluginParam::TYPE_STRING, L"Redis Server", L"-" },
 	{ MTPluginParam::TYPE_INT, L"Redis Port", L"-" },
-	{ MTPluginParam::TYPE_STRING, L"Redis User", L"-" },
 	{ MTPluginParam::TYPE_STRING, L"Redis Password", L"-" },
 	{ MTPluginParam::TYPE_INT, L"Trader", L"-" },
 	{ MTPluginParam::TYPE_INT, L"Step", L"-" },

+ 52 - 8
MT5MonkPAMM/PluginInstance.cpp

@@ -393,9 +393,16 @@ void CPluginInstance::OnDealPerform(const IMTDeal * deal, IMTAccount * account,
 	sprintf(order_buf, "%lld", deal->Order());
 	IMTDeal* new_deal = m_api->DealCreate();
 
-	ScopeGuard guard([new_deal]
+	std::vector<std::string>* fields = nullptr;
+
+	ScopeGuard guard([new_deal, fields]
 	{
 		new_deal->Release();
+		if (fields)
+		{
+			fields->clear();
+			delete fields;
+		}
 	});
 
 	char login_buf[128];
@@ -449,6 +456,31 @@ void CPluginInstance::OnDealPerform(const IMTDeal * deal, IMTAccount * account,
 			m_api->LoggerOut(MTLogErr, L"%lld cannot add deal [%d], original deal: #%lld", login, ret, deal->Deal());
 			continue;
 		}
+
+		if (position->Volume() == 0)
+		{
+			if (fields == nullptr)
+				fields = new(std::vector<std::string>);
+
+			fields->push_back(login_buf);
+		}
+	}
+
+	if (position->Volume() == 0)
+	{
+		// 如果平仓,则删除hash值
+		if (position->Volume() == 0)
+		{
+			auto fut = m_redis_client->hdel(order_buf, *fields);
+			m_redis_client->sync_commit();
+			auto rep = fut.get();
+			if (rep.ko())
+			{
+				// TODO 错误处理
+			}
+		}
+
+		// TODO 当position中的volume为0时,持仓被彻底平调,被跟订单是否也该检查
 	}
 }
 
@@ -489,11 +521,11 @@ MTAPIRES CPluginInstance::LoadParam()
 		return(MT_RET_ERR_PARAMS);
 	}
 	int redis_port = param->ValueInt();
-	if ((res = m_config->ParameterGet(L"Redis User", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_STRING)
-	{
-		return(MT_RET_ERR_PARAMS);
-	}
-	std::string redis_user = ws2s(param->ValueString());
+	//if ((res = m_config->ParameterGet(L"Redis User", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_STRING)
+	//{
+	//	return(MT_RET_ERR_PARAMS);
+	//}
+	//std::string redis_user = ws2s(param->ValueString());
 	if ((res = m_config->ParameterGet(L"Redis Password", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_STRING)
 	{
 		return(MT_RET_ERR_PARAMS);
@@ -502,12 +534,12 @@ MTAPIRES CPluginInstance::LoadParam()
 
 	if (m_redis_server != redis_server
 		|| m_redis_port != redis_port
-		|| m_redis_user != redis_user
+		//|| m_redis_user != redis_user
 		|| m_redis_password != redis_password)
 	{
 		m_redis_server = redis_server;
 		m_redis_port = redis_port;
-		m_redis_user = redis_user;
+		//m_redis_user = redis_user;
 		m_redis_password = redis_password;
 
 		stop_redis();
@@ -632,6 +664,18 @@ bool CPluginInstance::start_redis()
 			10000000,
 			1000
 		);
+
+		if (m_redis_password != "")
+		{
+			auto fut = m_redis_client->auth(m_redis_password);
+			m_redis_client->sync_commit();
+			auto reply = fut.get();
+			if (reply.is_error())
+			{
+				m_api->LoggerOut(MTLogErr, L"connect: authentication failed");
+				return false;
+			}
+		}
 	}
 	catch (tacopie::tacopie_error& e)
 	{

+ 1 - 1
MT5MonkPAMM/PluginInstance.h

@@ -73,7 +73,7 @@ private:
 	std::thread m_work_thread;
 
 	std::string		m_redis_server;
-	std::string		m_redis_user;
+	//std::string		m_redis_user;
 	std::string		m_redis_password;
 	int				m_redis_port;