예제 #1
0
        public bool Initialize(
            string address,
            short port,
            string protocolVersion,
            short yybId,
            string accountNo,
            short accountType,
            string tradeAccount,
            string tradePassword,
            string communicationPassword,
            out string error)
        {
            if (!_initialized)
            {
                lock (_initializationLockObj)
                {
                    if (!_initialized)
                    {
                        TradingEnvironment.Initialize();

                        _client = new TradingClient();

                        if (!_client.LogOn(address, port, protocolVersion, yybId, accountNo, accountType, tradeAccount, tradePassword, communicationPassword, out error))
                        {
                            _client.Dispose();
                            _client = null;

                            return(false);
                        }

                        _quotePublisher  = new QuotePublisher(_client, QuoteRefreshingInterval);
                        _orderDispatcher = new OrderDispatcher(_client, OrderRefreshingInterval);

                        _initialized = true;

                        return(true);
                    }
                }
            }

            error = "CtpSimulator has been initialized already, can't be reinitialized";
            return(false);
        }
예제 #2
0
        public void UnInitialize()
        {
            if (_initialized)
            {
                lock (_initializationLockObj)
                {
                    if (_initialized)
                    {
                        _quotePublisher.Stop();
                        _quotePublisher = null;

                        _orderDispatcher.Stop();
                        _orderDispatcher = null;

                        _client.LogOff();
                        _client = null;

                        TradingEnvironment.UnInitialize();

                        _initialized = false;
                    }
                }
            }
        }