|
|
@@ -584,6 +584,80 @@ void CPluginInstance::OnTradeRequestProcess(const IMTRequest* request, const IMT
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ UINT64 login = request->Login();
|
|
|
+ bool found = false;
|
|
|
+ for (auto follower : m_followers)
|
|
|
+ {
|
|
|
+ if (login == follower)
|
|
|
+ {
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 未找到直接退出
|
|
|
+ if (!found) return;
|
|
|
+
|
|
|
+ // 获取request cache并删除
|
|
|
+ request_cache cache;
|
|
|
+ std::string cache_key = std::string("reqid_") + std::to_string(request->ID());
|
|
|
+ auto fut = m_redis_client->get(cache_key);
|
|
|
+ m_redis_client->sync_commit();
|
|
|
+ auto reply = fut.get();
|
|
|
+
|
|
|
+ m_api->LoggerOut(MTLogOK, L"request cache, key: %s", cache_key.c_str());
|
|
|
+
|
|
|
+ if (reply.ko()) return;
|
|
|
+ if (reply.is_null()) return;
|
|
|
+
|
|
|
+ memcpy(&cache, reply.as_string().c_str(), sizeof(request_cache));
|
|
|
+
|
|
|
+ std::vector<std::string> keys = { cache_key };
|
|
|
+ m_redis_client->del(keys, [this](cpp_redis::reply& r)
|
|
|
+ {
|
|
|
+ if (r.ko())
|
|
|
+ {
|
|
|
+ m_api->LoggerOut(MTLogErr, L"redis: %s", r.error().c_str());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 获取做单上下文
|
|
|
+ position_context context;
|
|
|
+
|
|
|
+ char login_buf[128] = { 0 };
|
|
|
+ char orig_pos_buf[128] = { 0 };
|
|
|
+ sprintf(orig_pos_buf, "%lld", cache.orig_position);
|
|
|
+ sprintf(login_buf, "%lld", cache.login);
|
|
|
+
|
|
|
+ auto ctx_fut = m_redis_client->hget(orig_pos_buf, login_buf);
|
|
|
+ m_redis_client->sync_commit();
|
|
|
+ auto ctx_reply = fut.get();
|
|
|
+
|
|
|
+ m_api->LoggerOut(MTLogOK, L"request cache, key: %s", cache_key.c_str());
|
|
|
+
|
|
|
+ if (ctx_reply.ko()) return;
|
|
|
+ if (ctx_reply.is_null()) return;
|
|
|
+
|
|
|
+ memcpy(&context, ctx_reply.as_string().c_str(), sizeof(position_context));
|
|
|
+
|
|
|
+ // 修改跟单上下文
|
|
|
+ int direction = 1;
|
|
|
+ if (order->Type() == IMTOrder::OP_SELL) direction = -1;
|
|
|
+ context.volume += direction * order->VolumeCurrent();
|
|
|
+ context.position_id = position->Position();
|
|
|
+
|
|
|
+ m_api->LoggerOut(MTLogOK, L"writeback context, key: %s, field: %s", orig_pos_buf, login_buf);
|
|
|
+
|
|
|
+ // 写入
|
|
|
+ m_redis_client->hset(orig_pos_buf, login_buf, std::string((char*)&context, sizeof(position_context)), [this](cpp_redis::reply& r)
|
|
|
+ {
|
|
|
+ if (r.ko())
|
|
|
+ {
|
|
|
+ m_api->LoggerOut(MTLogErr, L"redis: %s", r.error().c_str());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ m_redis_client->commit();
|
|
|
}
|
|
|
|
|
|
MTAPIRES CPluginInstance::LoadParam()
|