示例#1
0
 public void Dispose()
 {
     _demo?.Dispose();
     _demo = null;
     _live?.Dispose();
     _live = null;
     _factory?.Dispose();
     _factory = null;
 }
示例#2
0
        public async Task StartAsync(CancellationToken cancellationToken, bool startThreads = true)
        {
            Debug.Assert(!_isStarting);

            if (_isStarting)
            {
                throw new InvalidOperationException();
            }

            _isStarting = true;
            _factory    = ManagerHost.CreateFactory(HandleException);
            CheckFactory();
            _factory.WinsockStartup();
            var m_masterUserSetting = await _masterSettingsService.GetCachedMasterSettingsAsync(cancellationToken);

            var mt4Accounts = await _mt4AccountService.GetAllMT4Accounts(cancellationToken);

            lock (_mt4LoginsByServerIndex)
                foreach (var mt4Account in mt4Accounts)
                {
                    AddMt4LoginNoLock(mt4Account._mt4ServerIndex, mt4Account._mt4Login);
                }

            m_ptrLogger.LogInfo("Initializng DEMO MT4 Manager");
            Debug.Assert(_demo == null);
            _demo = new WitFXServerConnector(
                eMT4ServerType.SRV_TYPE_DEMO, this, _factory,
                m_masterUserSetting._demoServer, m_masterUserSetting._demoManagerLogin,
                m_masterUserSetting._demoManagerPassword, _baseLogger, true, true,
                startThreads: startThreads);

            CppHelper.memcpy(ref _demo.m_masterUserSetting, m_masterUserSetting);

            //_demo.setMT4SocialUsers(m_mapMT4MasterLogin);
            //_demo.setMT4ResponseFunPtr(onMT4Response);
            //_demo.setMarketDataFunPtr(onMarketData);
            //_demo.setSymbolInfoFunPtr(onSymbolInfo);
            //_demo.setOnTradeFunPtr(onTradeResponse);
            //_demo.setOnMarginFunPtr(onMarginLevelResponse);

            m_ptrLogger.LogInfo("Initializng LIVE MT4 Manager");
            Debug.Assert(_live == null);
            _live = new WitFXServerConnector(
                eMT4ServerType.SRV_TYPE_LIVE, this, _factory,
                m_masterUserSetting._liveServer, m_masterUserSetting._liveManagerLogin,
                m_masterUserSetting._liveManagerPassword, _baseLogger, true, true,
                startThreads: startThreads);

            CppHelper.memcpy(ref _live.m_masterUserSetting, m_masterUserSetting);

            //_live.setMT4SocialUsers(m_mapMT4MasterLogin);
            //_live.setMT4ResponseFunPtr(onMT4Response);
            //_live.setOnTradeFunPtr(onTradeResponse);
            //_live.setOnMarginFunPtr(onMarginLevelResponse);

            if (startThreads)
            {
                if (_demo.IsAPIValid())
                {
                    m_ptrLogger.LogInfo("Starting DEMO MT4 Manager connection...");
                    _demo.startNormalManager();
                }
                else
                {
                    m_ptrLogger.LogError("MT4 MANAGER API IS NOT VALID");
                }
                if (_live.IsAPIValid())
                {
                    m_ptrLogger.LogInfo("Starting LIVE MT4 Manager connection...");
                    _live.startNormalManager();
                }
                else
                {
                    m_ptrLogger.LogError("MT4 MANAGER API IS NOT VALID");
                }

                var demoUpdateWorker = _updateWorkerFactory(eMT4ServerType.SRV_TYPE_DEMO);
                await demoUpdateWorker.ConfigureAsync(cancellationToken);

                _workerManager.StartWorker(demoUpdateWorker);

                var liveUpdateWorker = _updateWorkerFactory(eMT4ServerType.SRV_TYPE_LIVE);
                await liveUpdateWorker.ConfigureAsync(cancellationToken);

                _workerManager.StartWorker(liveUpdateWorker);
            }
        }