| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include "pch.h"
- #include "PluginInstance.h"
- CPluginInstance::CPluginInstance()
- {
- }
- CPluginInstance::~CPluginInstance()
- {
- }
- void CPluginInstance::Release()
- {
- delete this;
- }
- MTAPIRES CPluginInstance::Start(IMTServerAPI * server)
- {
- MTAPIRES ret = MT_RET_OK;
- if (!server) return MT_RET_ERR_PARAMS;
- m_api = server;
- if ((m_config = m_api->PluginCreate()) == nullptr)
- return MT_RET_ERR_MEM;
- ret = m_api->About(m_info);
- if (ret != MT_RET_OK)
- m_api->LoggerOut(MTLogOK, L"Server info failed [%d]", ret);
- if ((ret = m_api->PluginSubscribe(this)) != MT_RET_OK)
- {
- m_api->LoggerOut(MTLogAtt, L"Plugin subscribe failed [%d]", ret);
- return ret;
- }
- if (ret = m_api->OrderSubscribe(this) != MT_RET_OK)
- {
- m_api->LoggerOut(MTLogAtt, L"Order subscribe failed [%d]", ret);
- return ret;
- }
- if (ret = m_api->DealSubscribe(this) != MT_RET_OK)
- {
- m_api->LoggerOut(MTLogAtt, L"Deal subscribe failed [%d]", ret);
- return ret;
- }
- if ((ret = LoadParam()) != MT_RET_OK)
- {
- m_api->LoggerOut(MTLogAtt, L"Load param failed [%d]", ret);
- return ret;
- }
- return MT_RET_OK;
- }
- MTAPIRES CPluginInstance::Stop()
- {
- MTAPIRES ret = MT_RET_OK;
- if (m_api == nullptr)
- return MT_RET_OK;
- if (m_config != nullptr)
- {
- m_config->Release();
- m_config = nullptr;
- }
- if ((ret = m_api->PluginUnsubscribe(this)) != MT_RET_OK && ret != MT_RET_ERR_NOTFOUND)
- m_api->LoggerOut(MTLogErr, L"failed to unsubscribe from plugin config updates [%s (%u)]",
- SMTFormat::FormatError(ret), ret);
- if ((ret = m_api->OrderUnsubscribe(this)) != MT_RET_OK && ret != MT_RET_ERR_NOTFOUND)
- m_api->LoggerOut(MTLogErr, L"failed to unsubscribe order [%s (%u)]",
- SMTFormat::FormatError(ret), ret);
- if ((ret = m_api->DealUnsubscribe(this)) != MT_RET_OK && ret != MT_RET_ERR_NOTFOUND)
- m_api->LoggerOut(MTLogErr, L"failed to unsubscribe deal [%s (%u)]",
- SMTFormat::FormatError(ret), ret);
- m_api = nullptr;
- return MT_RET_OK;
- }
- MTAPIRES CPluginInstance::LoadParam()
- {
- MTAPIRES res = MT_RET_OK;
- IMTConParam* param = NULL;
- CMTStr128 tmp;
- if (!m_api || !m_config) return MT_RET_ERR_PARAMS;
- if ((res = m_api->PluginCurrent(m_config)) != MT_RET_OK)
- {
- m_api->LoggerOut(MTLogErr, L"failed to get current plugin configuration [%s (%u)]",
- SMTFormat::FormatError(res), res);
- return res;
- }
- if ((param = m_api->PluginParamCreate()) == NULL)
- {
- m_api->LoggerOut(MTLogErr, L"failed to create plugin parameter object");
- return MT_RET_ERR_MEM;
- }
- if ((res = m_config->ParameterGet(L"Trader", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_INT)
- {
- return(MT_RET_ERR_PARAMS);
- }
- m_trader = param->ValueInt();
- if ((res = m_config->ParameterGet(L"Step", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_INT)
- {
- return(MT_RET_ERR_PARAMS);
- }
- m_step = param->ValueInt();
- if ((res = m_config->ParameterGet(L"Tolerance", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_INT)
- {
- return(MT_RET_ERR_PARAMS);
- }
- m_tolerance = param->ValueInt();
- if ((res = m_config->ParameterGet(L"Groups", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_STRING)
- {
- return(MT_RET_ERR_PARAMS);
- }
- m_groups = param->ValueString();
- if ((res = m_config->ParameterGet(L"Logins", param)) != MT_RET_OK || param->Type() != IMTConParam::TYPE_STRING)
- {
- return(MT_RET_ERR_PARAMS);
- }
- m_logins = param->ValueString();
- }
|