|
|
@@ -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)
|
|
|
{
|