Ejemplo n.º 1
0
        //TODO: handleSSPAccountRequest
        public async Task <SSPSignalCreateResult> CreateSSPAccount(
            SSPSignalCreateRequest ptr, CancellationToken cancellationToken)
        {
            m_ptrLogger.LogOk("START");
            var m_masterUserSetting = await _masterSettingsService.GetMasterSetting(cancellationToken);

            if (await _signalService.GetSSPSignalCount(ptr._masterLogin, cancellationToken) >=
                m_masterUserSetting._maxSSPAccount)
            {
                m_ptrLogger.LogWarning("Max SSP Signal reached. Ignoring SSP request");
                return(null);
            }
            if (await _signalService.IsSignalNameExist(ptr._signalName, cancellationToken))
            {
                m_ptrLogger.LogWarning("Signal name already exist.... %s", ptr._signalName);
                return(null);
            }

            MasterUser ptrUser = await _masterUserService.GetMasterAccount(ptr._masterLogin,
                                                                           cancellationToken);

            var result = new SSPSignalCreateResult();

            if (ptrUser != null)
            {
                Signal sig = new Signal();
                sig._isSSP       = true;
                sig._masterLogin = ptr._masterLogin;
                COPY_STR_S(out sig._signalName, ptr._signalName);
                sig._signalIndex    = -1;
                sig._mt4ServerIndex = SRV_TYPE_DEMO;
                sig._mt4Login       = -1;

                var ptrMT4Req2 = (MT4Request) new MT4Request();
                //memset(ptrMT4Req2, 0, sizeof(MT4Request));
                ptrMT4Req2.accType     = ACC_TYPE_SSP;
                ptrMT4Req2.masterLogin = ptrUser._login;
                ptrMT4Req2.reqType     = MT4REQ.MT4REQ_NEW_ACCOUNT;
                //ptrMT4Req2.socketID = ptr._header._socketID;
                ptrMT4Req2.status        = ORD_STAT_RECVD;
                ptrMT4Req2.serverTransID = TransactionService.NewTransactionId();
                ptrMT4Req2.ptrData       = (MasterUser) new MasterUser();
                memcpy(ref ptrMT4Req2.ptrData, ptrUser);

                sig.AccountTransId = ptrMT4Req2.serverTransID;
                sig._rebateAmount  = m_masterUserSetting._rebate_SSP;
                sig._sspPercentage = 100.0F;
                m_ptrLogger.LogInfo("Inserting SSP signal in DB Signal: %s MasterLogin: %d Dummy MT4 Login: %d", ptr._signalName, ptr._masterLogin, sig._mt4Login);
                await _signalService.InsertSignal(sig, cancellationToken);

                bool res = true;
                if (res)
                {
                    SSPSignal ssp = new SSPSignal();
                    ssp._signalIndex    = sig._signalIndex;
                    ssp._sspMasterLogin = sig._masterLogin;
                    ssp._sspMT4Login    = sig._mt4Login;
                    Debug.Assert(sig.AccountTransId != Guid.Empty);
                    ssp.SspAccountTransId  = sig.AccountTransId;
                    ssp._sspMT4ServerIndex = SRV_TYPE_DEMO;
                    ssp._strategyType      = ptr._strategyType;
                    ssp._symbolIndex       = ptr._symbolIndex;

                    /*if (m_ptrMySqlWrapper.insertSSPSignal(&ssp))
                     * {
                     *  SSPSignalCreateResponse ptrResp = GetMessageObject<SSPSignalCreateResponse>(MT_SSPSignalCreateResponse_ID);
                     *  ptrResp._header._loginID = ptr._header._loginID;
                     *  ptrResp._header._socketID = ptr._header._socketID;
                     *  ptrResp._retCode = eReturnCode.RC_OK;
                     *  memcpy(out ptrResp._sspSignal, &ssp, sizeof(SSPSignal));
                     *  SentDataUsingSocketID(ptrResp, MT_SSPSignalCreateResponse_ID, ptrResp._header._socketID);
                     *
                     *  m_ptrLogger.LogOk("Sending request to connector for opening SSP MT4 account");
                     *  m_ptrDemoMT4Manager.insertMT4Request(ptrMT4Req2);
                     * }
                     * else
                     * {
                     *  m_ptrLogger.LogError("Unable to insert SSPSignal for signal Index: %d master login: %d Dummy MT4 Login: %d", ssp._signalIndex, ptr._masterLogin, sig._mt4Login);
                     * } */

                    //When SSP MT4 account created then we will send response to client side
                    await _signalService.InsertSSPSignal(ssp, cancellationToken);

                    result.SSPSignal = ssp;
                    bool res2 = true;
                    if (!res2)
                    {
                        m_ptrLogger.LogError("Unable to insert SSPSignal for signal Index: %d master login: %d Dummy MT4 Login: %d", ssp._signalIndex, ptr._masterLogin, sig._mt4Login);
                    }
                    else
                    {
                        m_ptrLogger.LogOk("Sending request to connector for opening SSP MT4 account");
                        m_ptrDemoMT4Manager.insertMT4Request(ptrMT4Req2);
                        result.MT4Request = ptrMT4Req2;
                    }
                }
                else
                {
                    m_ptrLogger.LogError("Unable to insert SSP signal in DB Signal: %s MasterLogin: %d Dummy MT4 Login: %d", ptr._signalName, ptr._masterLogin, sig._mt4Login);
                }

                CppHelper.free(ptrUser);
                ptrUser = null;
            }
            m_ptrLogger.LogOk("END");
            return(result);
        }
Ejemplo n.º 2
0
        //TODO: handleSMAccountRequest
        public async Task <SMSignalCreateResponse> CreateSMAccount(
            SMSignalCreateRequest ptr, CancellationToken cancellationToken)
        {
            var ptrResp = new SMSignalCreateResponse();

            m_ptrLogger.LogOk("START");

            var m_masterUserSetting = await _masterSettingsService.GetMasterSetting(cancellationToken);

            if (ptr._isSignalCreated)
            {
                if (await _signalService.GetSSPCountForSMSignal(ptr._smSignal._smMasterLogin,
                                                                ptr._smSignal._signalIndex, cancellationToken) >=
                    m_masterUserSetting._maxSSPInSM)
                {
                    m_ptrLogger.LogInfo("Max SSP Signal reached for SM signal index %d. Ignoring SM request", ptr._smSignal._signalIndex);
                    return(null);
                }

                //Alexey: additional code
                var signalOfSM = await _signalService.GetSignal(ptr._smSignal._signalIndex, cancellationToken);

                Debug.Assert(signalOfSM != null);

                SMSignal smSig = new SMSignal();
                //memset(&smSig, 0, sizeof(SMSignal));

                smSig._signalIndex   = ptr._smSignal._signalIndex;
                smSig._smMasterLogin = ptr._smSignal._smMasterLogin;
                smSig._smMT4Login    = ptr._smSignal._smMT4Login;
                Debug.Assert(signalOfSM.AccountTransId != Guid.Empty);
                smSig.SmAccountTransId   = signalOfSM.AccountTransId;
                smSig._smMT4ServerIndex  = SRV_TYPE_DEMO;
                smSig._sspMasterLogin    = ptr._smSignal._sspMasterLogin;
                smSig._sspMT4Login       = ptr._smSignal._sspMT4Login;
                smSig._sspMT4ServerIndex = ptr._smSignal._sspMT4ServerIndex;
                smSig._sspSignalIndex    = ptr._smSignal._sspSignalIndex;

                await _signalService.InsertSMSignal(smSig, cancellationToken);

                bool res = true;

                if (res)
                {
                    //ptrResp = new SMSignalCreateResponse(); //MT_SMSignalCreateResponse_ID
                    //ptrResp._header._loginID = ptr._header._loginID;
                    //ptrResp._header._socketID = ptr._header._socketID;
                    ptrResp._retCode = RC_OK;
                    //memcpy(ref ptrResp._smSignal, smSig);
                    ptrResp._smSignal = smSig;
                    //SentDataUsingSocketID(ptrResp, MT_SSPSignalCreateResponse_ID, ptrResp._header._socketID);

                    //addFollower(smSig._sspMT4Login, smSig._smMT4Login, smSig._smMT4ServerIndex);
                    //addFollowerVolume(smSig._sspSignalIndex, smSig._smMT4ServerIndex, smSig._smMT4Login, m_masterUserSetting._signalTradeVolume);
                }
                else
                {
                    m_ptrLogger.LogError("Unable to insert SMSignal for signal Index: %d master login: %d MT4 Login: %d", smSig._signalIndex, ptr._smSignal._smMasterLogin, smSig._smMT4Login);
                }
            }
            else
            {
                if (await _signalService.GetSMSignalCount(ptr._smSignal._smMasterLogin, cancellationToken) >=
                    m_masterUserSetting._maxSMAccount)
                {
                    m_ptrLogger.LogWarning("Max SM Signal reached. Ignoring SM request");
                    return(null);
                }

                if (await _signalService.IsSignalNameExist(ptr._signalName, cancellationToken))
                {
                    m_ptrLogger.LogWarning("Signal name already exist.... %s", ptr._signalName);
                    return(null);
                }


                MasterUser ptrUser = await _masterUserService.GetMasterAccount(ptr._smSignal._smMasterLogin,
                                                                               cancellationToken);

                if (ptrUser != null)
                {
                    Signal sig = new Signal();
                    sig._isSSP       = false;
                    sig._masterLogin = ptr._smSignal._smMasterLogin;
                    COPY_STR_S(out sig._signalName, ptr._signalName);
                    sig._signalIndex    = -1;
                    sig._mt4ServerIndex = SRV_TYPE_DEMO;
                    sig._mt4Login       = -1;


                    MT4Request ptrMT4Req2 = (MT4Request) new MT4Request();
                    //memset(ptrMT4Req2, 0, sizeof(MT4Request));
                    ptrMT4Req2.accType     = ACC_TYPE_SM;
                    ptrMT4Req2.masterLogin = ptr._smSignal._smMasterLogin;
                    ptrMT4Req2.reqType     = MT4REQ.MT4REQ_NEW_ACCOUNT;
                    //ptrMT4Req2.socketID = ptr._header._socketID;
                    ptrMT4Req2.status        = ORD_STAT_RECVD;
                    ptrMT4Req2.serverTransID = TransactionService.NewTransactionId();
                    ptrMT4Req2.ptrData       = (MasterUser) new MasterUser();
                    memcpy(ref ptrMT4Req2.ptrData, ptrUser);

                    sig.AccountTransId = ptrMT4Req2.serverTransID;
                    sig._rebateAmount  = m_masterUserSetting._rebate_SM;
                    sig._sspPercentage = m_masterUserSetting._ssp_per;
                    m_ptrLogger.LogInfo("Inserting SM signal in DB Signal: %s MasterLogin: %d Dummy MT4 Login: %d", ptr._signalName, ptr._smSignal._smMasterLogin, sig._mt4Login);

                    await _signalService.InsertSignal(sig, cancellationToken);

                    ptrResp.Signal = sig;
                    bool res2 = true;

                    if (res2)
                    {
                        if (ptr._smSignal._sspMT4Login != 0)
                        {
                            SMSignal smSig = new SMSignal();
                            //memset(&smSig, 0, sizeof(SMSignal));
                            smSig._signalIndex   = sig._signalIndex;
                            smSig._smMasterLogin = sig._masterLogin;
                            Debug.Assert(sig.AccountTransId != Guid.Empty);
                            smSig.SmAccountTransId   = sig.AccountTransId;
                            smSig._smMT4Login        = sig._mt4Login;
                            smSig._smMT4ServerIndex  = SRV_TYPE_DEMO;
                            smSig._sspMasterLogin    = ptr._smSignal._sspMasterLogin;
                            smSig._sspMT4Login       = ptr._smSignal._sspMT4Login;
                            smSig._sspMT4ServerIndex = ptr._smSignal._sspMT4ServerIndex;
                            smSig._sspSignalIndex    = ptr._smSignal._sspSignalIndex;

                            await _signalService.InsertSMSignal(smSig, cancellationToken);

                            bool res3 = true;

                            if (res3)
                            {
                                //ptrResp = new SMSignalCreateResponse(); //MT_SMSignalCreateResponse_ID
                                //ptrResp._header._loginID = ptr._header._loginID;
                                //ptrResp._header._socketID = ptr._header._socketID;
                                ptrResp._retCode = RC_OK;
                                //memcpy(ref ptrResp._smSignal, smSig);
                                ptrResp._smSignal = smSig;
                                ptrResp.Signal    = sig;
                                //SentDataUsingSocketID(ptrResp, MT_SSPSignalCreateResponse_ID, ptrResp._header._socketID);

                                //addFollower(smSig._sspMT4Login, smSig._smMasterLogin, smSig._smMT4ServerIndex);
                                //addFollowerVolume(smSig._sspSignalIndex, smSig._smMT4ServerIndex, smSig._smMasterLogin, m_masterUserSetting._signalTradeVolume);
                            }
                            else
                            {
                                m_ptrLogger.LogError("Unable to insert SMSignal for signal Index: %d master login: %d MT4 Login: %d", smSig._signalIndex, ptr._smSignal._smMasterLogin, sig._mt4Login);
                            }
                        }
                    }
                    else
                    {
                        m_ptrLogger.LogError("Unable to insert SM signal in DB Signal: %s MasterLogin: %d Dummy MT4 Login: %d", ptr._signalName, ptr._smSignal._smMasterLogin, sig._mt4Login);
                    }
                    m_ptrLogger.LogOk("Sending request to connector for opening SM MT4 account");
                    m_ptrDemoMT4Manager.insertMT4Request(ptrMT4Req2);

                    //if (ptrResp == null)
                    //{
                    //    ptrResp = new SMSignalCreateResponse(); // { _header = new MessageHeader { _loginID = ptr._header._loginID } };
                    //}

                    ptrResp.MT4Request = ptrMT4Req2;
                    CppHelper.free(ptrUser);
                    ptrUser = null;
                }
            }
            m_ptrLogger.LogOk("END");
            return(ptrResp);
        }