function QueryFunctions()

global m_CEL;

global m_CurFunc;

global m_Symbol1;
global m_Symbol2;

global m_OptionSymbol;

global m_Status;
global m_OrderID;
global m_UpdatesCount;
global m_LatencyTime;
global m_PlacedOrdersCount;

try
    
    if ~m_CEL.IsStarted
        disp 'You can send request only when CEL is started.';
    elseif ~strcmp(m_CEL.Environment.DataConnectionStatus , 'csConnectionUp')
        disp 'Currently Data Connection is not UP. Please send request when connection status changed to UP.';
    else
        
        m_UpdatesCount = 0;
        m_LatencyTime = 0;
        disp ' ';
        
        switch m_CurFunc
           
            case 'none'
                m_CurFunc = 'expression';
                
            case 'expression'
                disp '_____________________________________________________';
                disp 'Expression';
                disp '-----------------------------------------------------';
                disp ' ';
                
                % Informing about requesting last 300 daily closes for given symbols.
                disp(['Requesting daily closes for "' m_Symbol1 '" and "' m_Symbol2 '" ...']);

                expressionRequest = m_CEL.CreateExpressionRequest;

                expressionRequest.AddSubExpression(['Close(' m_Symbol1 ')'], 'ts1');
                expressionRequest.AddSubExpression(['Close(' m_Symbol2 ')'], 'ts2');
                expressionRequest.set('RangeStart', int32(0));
                expressionRequest.set('RangeEnd', int32(-300));
                expressionRequest.set('HistoricalPeriod', 'hpDaily');
                expressionRequest.set('UpdatesEnabled', true);

                m_CEL.RequestExpression(expressionRequest);
                pause(2);

                m_OrderID = '';
                m_CurFunc = 'orders';
                
            case 'orders'
                m_CEL.RemoveAllExpressions;
                pause(2);
                
                if ContinueSample
                    % Unregistering callback listeners for Expression.
                    m_CEL.unregisterevent({'ExpressionResolved' 'CEL_ExpressionResolved'; ...
                                           'ExpressionAdded' 'CEL_ExpressionAdded'; ...
                                           'ExpressionUpdated' 'CEL_ExpressionUpdated'; ...
                                           'ExpressionInserted' 'CEL_ExpressionInserted'; ...
                                           'ExpressionRemoved' 'CEL_ExpressionRemoved'});
                    pause(2);
                
                    disp '_____________________________________________________';
                    disp 'OrderPlacing';
                    disp '-----------------------------------------------------';
                    disp ' ';

                    GWConnectionStatus = m_CEL.Environment.get('GWConnectionStatus');
                    if strcmp(GWConnectionStatus, 'csConnectionUp')
                        disp(['Trying to place a market order for "' m_Symbol1 '" ...']);

                        m_PlacedOrdersCount = 0;

                        % Informing about subscribing to given symbol.
                        disp(['Subscribing to "', m_Symbol1, '" ...']);

                        m_CEL.NewInstrument(m_Symbol1);
                    else
                        disp(['The order has not been placed, because GW connection status is ', GWConnectionStatus]);
                    end

                    m_Status = 0;
                    m_CurFunc = 'realtimedata';
                else
                    pause(2);
                end
                                   
            case 'realtimedata'
                m_CEL.RemoveAllInstruments;
                pause(2);
                
                if ContinueSample
                    % Unegistering callback listeners for Orders.
                    m_CEL.unregisterevent({'GWConnectionStatusChanged' 'CEL_OnGWConnectionStatusChanged'; ...
                                           'AccountChanged' 'CEL_OnAccountChanged'; ...
                                           'OrderChanged' 'CEL_OrderChanged'});
                    pause(2);
                
                    disp '_____________________________________________________';
                    disp 'RealTimeData';
                    disp '-----------------------------------------------------';
                    disp ' ';

                    % Informing about requesting realtime data for given symbol.
                    disp(['Requesting real time data for "' m_OptionSymbol '" ...']);

                    m_CEL.NewInstrument(m_OptionSymbol);

                    m_CurFunc = 'timedbars';
                else
                    pause(2);
                end
                
            case 'timedbars'
                m_CEL.RemoveAllInstruments;
                pause(2);
                
                if ContinueSample
                    % Unegistering callback listeners for RealTimeData & Orders.
                    m_CEL.unregisterevent({'InstrumentSubscribed' 'CEL_OnInstrumentSubscribed'; ...
                                           'InstrumentChanged' 'CEL_OnInstrumentChanged'; ...
                                           'IncorrectSymbol' 'CEL_OnIncorrectSymbol'});
                    pause(2);
                
                    disp '_____________________________________________________';
                    disp 'TimedBars';
                    disp '-----------------------------------------------------';
                    disp ' ';

                    % Informing about requesting timed bars for given symbol.
                    disp(['Requesting daily timed bars for "' m_Symbol1 '" ...']);

                    % Create and configure the timed bars request.
                    timedBarsRequest = m_CEL.CreateTimedBarsRequest;

                    timedBarsRequest.set('Intraday', int32(1));
                    timedBarsRequest.set('IncludeEnd', true);
                    timedBarsRequest.set('RangeStart', int32(0));
                    timedBarsRequest.set('RangeEnd', int32(-10));
                    timedBarsRequest.set('Symbol', m_Symbol1);
                    timedBarsRequest.set('DaysBeforeExpiration', int32(1));
                    timedBarsRequest.set('SessionsFilter', int32(31));
                    timedBarsRequest.set('UpdatesEnabled', true);
                    timedBarsRequest.set('EqualizeCloses', true);
                    timedBarsRequest.set('Continuation', 'tsctNoContinuation');
                    timedBarsRequest.set('HistoricalPeriod', 'hpDaily');

                    % Request the timed bars.
                    m_CEL.RequestTimedBars(timedBarsRequest);
                    pause(2);

                    m_CurFunc = '';
                else
                    pause(2);
                end
                
            otherwise
                m_CEL.RemoveAllTimedBars;
                
                disp 'Finishing sample...';
                disp ' ';
                
                % Unegistering callback listeners for TimedBars.
                m_CEL.unregisterevent({'TimedBarsResolved' 'CEL_OnTimedBarsResolved'; ...
                                       'TimedBarsAdded' 'CEL_OnTimedBarsAdded'; ...
                                       'TimedBarsUpdated' 'CEL_OnTimedBarsUpdated'; ...
                                       'TimedBarsInserted' 'CEL_OnTimedBarsInserted'; ...
                                       'TimedBarsRemoved' 'CEL_OnTimedBarsRemoved'});

                % Unegistering common callback listeners.
                m_CEL.unregisterevent({'DataConnectionStatusChanged' 'CEL_OnDataConnectionStatusChanged'; ...
                                       'CELStarted' 'CEL_OnCELStarted'; ...
                                       'LineTimeChanged' 'CEL_OnLineTimeChanged'; ...
                                       'DataError' 'CEL_OnDataError'});
                                   
                CEL_ShutDown;
                                   
                m_CurFunc = '';
        end
        
    end
catch
    CEL_ShutDown;
    disp('An error occurred in QueryFunctions.m file.');
end