Example #1
0
        private void UpdateUI(IBMessage message)
        {
            ShowMessageOnPanel("(UpdateUI) Message type: " + message.Type.ToString());

            switch (message.Type)
            {
            case MessageType.ConnectionStatus:
            {
                ConnectionStatusMessage statusMessage = (ConnectionStatusMessage)message;
                if (statusMessage.IsConnected)
                {
                    status_CT.Text     = "Connected! Your client Id: " + ibClient.ClientId;
                    connectButton.Text = "Disconnect";
                }
                else
                {
                    status_CT.Text     = "Disconnected...";
                    connectButton.Text = "Connect";
                }
                break;
            }

            case MessageType.Error:
            {
                ErrorMessage error = (ErrorMessage)message;
                ShowMessageOnPanel("Request " + error.RequestId + ", Code: " + error.ErrorCode + " - " + error.Message);
                HandleErrorMessage(error);
                break;
            }

            case MessageType.TickOptionComputation:
            case MessageType.TickPrice:
            case MessageType.TickSize:
            {
                HandleTickMessage((MarketDataMessage)message);
                break;
            }

            case MessageType.MarketDepth:
            case MessageType.MarketDepthL2:
            {
                deepBookManager.UpdateUI(message);
                break;
            }

            case MessageType.HistoricalData:
            case MessageType.HistoricalDataEnd:
            {
                historicalDataManager.UpdateUI(message);
                break;
            }

            case MessageType.RealTimeBars:
            {
                realTimeBarManager.UpdateUI(message);
                break;
            }

            case MessageType.ScannerData:
            case MessageType.ScannerParameters:
            {
                scannerManager.UpdateUI(message);
                break;
            }

            case MessageType.OpenOrder:
            case MessageType.OpenOrderEnd:
            case MessageType.OrderStatus:
            case MessageType.ExecutionData:
            case MessageType.CommissionsReport:
            {
                orderManager.UpdateUI(message);
                break;
            }

            case MessageType.ManagedAccounts:
            {
                orderManager.ManagedAccounts   = ((ManagedAccountsMessage)message).ManagedAccounts;
                accountManager.ManagedAccounts = ((ManagedAccountsMessage)message).ManagedAccounts;
                exerciseAccount.Items.AddRange(((ManagedAccountsMessage)message).ManagedAccounts.ToArray());
                break;
            }

            case MessageType.AccountSummaryEnd:
            {
                accSummaryRequest.Text = "Request";
                accountManager.UpdateUI(message);
                break;
            }

            case MessageType.AccountDownloadEnd:
            {
                break;
            }

            case MessageType.AccountUpdateTime:
            {
                accUpdatesLastUpdateValue.Text = ((UpdateAccountTimeMessage)message).Timestamp;
                break;
            }

            case MessageType.PortfolioValue:
            {
                accountManager.UpdateUI(message);
                if (exerciseAccount.SelectedItem != null)
                {
                    optionsManager.HandlePosition((UpdatePortfolioMessage)message);
                }
                break;
            }

            case MessageType.AccountSummary:
            case MessageType.AccountValue:
            case MessageType.Position:
            case MessageType.PositionEnd:
            {
                accountManager.UpdateUI(message);
                break;
            }

            case MessageType.ContractDataEnd:
            {
                searchContractDetails.Enabled = true;
                contractManager.UpdateUI(message);

                foreach (var socket in allSockets.ToList())                                 // Loop through all connections/connected clients and send each of them a message
                {
                    socket.Send(searchJsonResponse.Test());
                }

                // Send json object
                // After it is sent .clear it!
                //MessageBox.Show(searchJsonResponse.Test());
                searchJsonResponse.Clear();                                 // Collection empty

                break;
            }

            case MessageType.ContractData:
            {
                HandleContractDataMessage((ContractDetailsMessage)message);
                //MessageBox.Show("contract_start");

                foreach (var socket in allSockets.ToList())                                 // Loop through all connections/connected clients and send each of them a message
                {
                    //var castedMessage = (ContractDetailsMessage)message;
                    //ShowMessageOnPanel("SYMBOL: " + castedMessage.ContractDetails.Summary.Symbol + " successfully found at: " + castedMessage.ContractDetails.Summary.PrimaryExch + " exchange");
                    //socket.Send("SYMBOL: " + castedMessage.ContractDetails.Summary.Symbol + " successfully found at: " + castedMessage.ContractDetails.Summary.Exchange + " exchange");
                }

                // Add new object to json array
                var z = (ContractDetailsMessage)message;                                 // Type cast
                var x = z.ContractDetails.Summary;
                searchJsonResponse.Add(x.Exchange, x.LocalSymbol, x.SecType, x.Currency, x.Exchange, x.PrimaryExch, x.ConId);
                //Log.Insert(DateTime.Now, "Form1.cs", string.Format("ContractData: {0} {1} {2} {3} {4} {5} {6}", x.Exchange, x.LocalSymbol, x.SecType, x.Currency, x.Exchange, x.PrimaryExch, x.ConId), "white");

                break;
            }

            case MessageType.FundamentalData:
            {
                fundamentalsQueryButton.Enabled = true;
                contractManager.UpdateUI(message);
                break;
            }

            case MessageType.ReceiveFA:
            {
                advisorManager.UpdateUI((AdvisorDataMessage)message);
                break;
            }

            case MessageType.PositionMulti:
            case MessageType.AccountUpdateMulti:
            case MessageType.PositionMultiEnd:
            case MessageType.AccountUpdateMultiEnd:
            {
                acctPosMultiManager.UpdateUI(message);
                break;
            }

            case MessageType.SecurityDefinitionOptionParameter:
            case MessageType.SecurityDefinitionOptionParameterEnd:
            {
                optionsManager.UpdateUI(message);
                break;
            }

            case MessageType.SoftDollarTiers:
            {
                orderManager.UpdateUI(message);
                break;
            }

            default:
            {
                HandleMessage(new ErrorMessage(-1, -1, message.ToString()));
                break;
            }
            }
        }         // private void UpdateUI
Example #2
0
        private void UpdateUI(IBMessage message)
        {
            switch (message.Type)
            {
            case MessageType.ConnectionStatus:
            {
                ConnectionStatusMessage statusMessage = (ConnectionStatusMessage)message;
                if (statusMessage.IsConnected)
                {
                    status_CT.Text     = "Connected! Your client Id: " + ibClient.ClientId;
                    connectButton.Text = "Disconnect";
                }
                else
                {
                    status_CT.Text     = "Disconnected...";
                    connectButton.Text = "Connect";
                }
                break;
            }

            case MessageType.Error:
            {
                ErrorMessage error = (ErrorMessage)message;
                ShowMessageOnPanel("Request " + error.RequestId + ", Code: " + error.ErrorCode + " - " + error.Message + "\r\n");
                break;
            }

            case MessageType.TickOptionComputation:
            case MessageType.TickPrice:
            case MessageType.TickSize:
            {
                HandleTickMessage((MarketDataMessage)message);
                break;
            }

            case MessageType.MarketDepth:
            case MessageType.MarketDepthL2:
            {
                deepBookManager.UpdateUI(message);
                break;
            }

            case MessageType.HistoricalData:
            case MessageType.HistoricalDataEnd:
            {
                historicalDataManager.UpdateUI(message);
                break;
            }

            case MessageType.RealTimeBars:
            {
                realTimeBarManager.UpdateUI(message);
                break;
            }

            case MessageType.ScannerData:
            {
                scannerManager.UpdateUI(message);
                break;
            }

            case MessageType.OpenOrder:
            case MessageType.OpenOrderEnd:
            case MessageType.OrderStatus:
            case MessageType.ExecutionData:
            case MessageType.CommissionsReport:
            {
                orderManager.UpdateUI(message);
                break;
            }

            case MessageType.ManagedAccounts:
            {
                orderManager.ManagedAccounts   = ((ManagedAccountsMessage)message).ManagedAccounts;
                accountManager.ManagedAccounts = ((ManagedAccountsMessage)message).ManagedAccounts;
                exerciseAccount.Items.AddRange(((ManagedAccountsMessage)message).ManagedAccounts.ToArray());
                break;
            }

            case MessageType.AccountSummaryEnd:
            {
                accSummaryRequest.Text = "Request";
                accountManager.UpdateUI(message);
                break;
            }

            case MessageType.AccountDownloadEnd:
            {
                break;
            }

            case MessageType.AccountUpdateTime:
            {
                accUpdatesLastUpdateValue.Text = ((UpdateAccountTimeMessage)message).Timestamp;
                break;
            }

            case MessageType.PortfolioValue:
            {
                accountManager.UpdateUI(message);
                if (exerciseAccount.SelectedItem != null)
                {
                    optionsManager.HandlePosition((UpdatePortfolioMessage)message);
                }
                break;
            }

            case MessageType.AccountSummary:
            case MessageType.AccountValue:
            case MessageType.Position:
            case MessageType.PositionEnd:
            {
                accountManager.UpdateUI(message);
                break;
            }

            case MessageType.ContractDataEnd:
            {
                searchContractDetails.Enabled = true;
                contractManager.UpdateUI(message);
                break;
            }

            case MessageType.ContractData:
            {
                HandleContractDataMessage((ContractDetailsMessage)message);
                break;
            }

            case MessageType.FundamentalData:
            {
                fundamentalsQueryButton.Enabled = true;
                contractManager.UpdateUI(message);
                break;
            }

            case MessageType.ReceiveFA:
            {
                advisorManager.UpdateUI((AdvisorDataMessage)message);
                break;
            }

            default:
            {
                HandleMessage(new ErrorMessage(-1, -1, message.ToString()));
                break;
            }
            }
        }