Exemplo n.º 1
0
        /// <summary>
        /// Process the incoming messages
        /// </summary>
        /// <param name="message">Incoming message</param>
        private void processMessage(string message)
        {
            // Deserialize the incoming command to check wich message has just arrived
            // The action property brings the command name
            switch (Command.Deserialize(message).action)
            {
            case KeepAlive.CLASSNAME:
            {           // If it is a KeepAlive message, just answer Quantsis Conneciton Box another KeepAlive message
                        //CheckAsyncTaskInProgress
                this.send(new KeepAlive().Serialize());
                break;
            }

            case NewOrderResponse.CLASSNAME:
            {           // If it is an NewOrderResponse message and it contains error, show the error message
                var cmd = NewOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case NewStopOrderResponse.CLASSNAME:
            {           // If it is an NewStopOrderResponse message and it contains error, show the error message
                var cmd = NewStopOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case NewStopGainLossOrderResponse.CLASSNAME:
            {           // If it is an NewStopGainLossOrderResponse message and it contains error, show the error message
                var cmd = NewStopGainLossOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case CancelOrderResponse.CLASSNAME:
            {           // If it is an CancelOrderResponse message and it contains error, show the error message
                var cmd = CancelOrderResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case ExecutionReport.CLASSNAME:
            {           // If it is an ExecutionReport message, check if it was successful and updates the order list or show error message
                var cmd = ExecutionReport.Deserialize(message);
                if (cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            case OrderListResponse.CLASSNAME:
            {           // If it is an OrderListResponse, check if it was successful. In negative case show error message.
                var cmd = OrderListResponse.Deserialize(message);
                if (!cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case PositionResponse.CLASSNAME:
            {           // If it is a Position Response, check if it was successful and updates the position list. In case of failure, show error messasge
                var cmd = PositionResponse.Deserialize(message);
                if (cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            case QuoteResponse.CLASSNAME:
            {           // If it is a Quote Response, check if it was successful and logs the message
                var cmd = QuoteResponse.Deserialize(message);
                if (cmd.success)
                {
                    OnQuoteResponse(cmd);
                }
                else
                {
                    NotifyQCB(cmd.ToString());
                }
                break;
            }

            case QuoteUpdate.CLASSNAME:
            {           // If it is a Quote Update, check if it was successful and logs the message
                var cmd = QuoteUpdate.Deserialize(message);
                if (cmd.success)
                {
                    OnQuoteUpdate(cmd);
                }
                else
                {
                    NotifyQCB(cmd.ToString());
                }
                break;
            }

            case QuoteUnsubscribeResponse.CLASSNAME:
            {           // If it is a Quote Unsubscribe Response, check if it was successful
                var cmd = QuoteUnsubscribeResponse.Deserialize(message);
                if (cmd.success)
                {
                    NotifyOMS(cmd.ToString());
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }
                break;
            }

            case CandleResponse.CLASSNAME:
            {           // If it is a Quote Update, check if it was successful and logs the message
                var cmd = CandleResponse.Deserialize(message);
                if (cmd.success)
                {
                    if (cmd.candles != null)
                    {
                        if (cmd.candles.Count <= 0)
                        {
                            NotifyOMS("Nenhum foi possivel retornar nenhum candle para " + cmd.security + " - Timeframe: " + cmd.timeframe);
                        }
                        else
                        {
                            NotifyOMS("Dados Historicos Intraday para: " + cmd.security + " - Qtd de Candles: " + cmd.candles.Count + " - Timeframe: " + cmd.timeframe);
                            //foreach (Candle candle in cmd.candles)
                            //    this.mainForm.log(candle.ToString());
                        }
                    }
                }
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            // Candle Update
            case CandleUpdate.CLASSNAME:
            {           // If it is a Candle Update, check if it was successful and logs the message
                var cmd = CandleUpdate.Deserialize(message);

                if (cmd.success)
                {
                    if (cmd.candle != null)
                    {
                        switch (cmd.timeframe)
                        {
                        case CandleUpdate.TIMEFRAME_INTRADAY_1_MIN:
                            NotifyOMS("Candle Intraday Update: " + cmd.security + " - Last: " + cmd.candle.close + " - Time: " + cmd.candle.date);
                            break;

                        case CandleUpdate.TIMEFRAME_DAILY:
                            NotifyOMS("Candle Daily Update: " + cmd.security + " - Last: " + cmd.candle.close + " - Time: " + cmd.candle.date);
                            break;
                        }
                    }
                }
                //this.mainForm.updatePositions(cmd);
                else
                {
                    NotifyOMS(cmd.ToString());
                }

                break;
            }

            // QCB has disconnected (shut down)
            case Disconnect.CLASSNAME:
                this.disconnect();
                break;
            }
        }