Exemplo n.º 1
0
 //This is the "UI entry point" and as such will handle the UI update by another thread
 public void HandleMessage(IBMessage message)
 {
     if (this.InvokeRequired)
     {
         MessageHandlerDelegate callback = new MessageHandlerDelegate(HandleMessage);
         this.Invoke(callback, new object[] { message });
     }
     else
     {
         UpdateUI(message);
     }
 }
Exemplo n.º 2
0
        private void ProcessMessage(IBMessage message)
        {
            switch (message.Type)
            {
            case MessageType.OpenOrder:
                HandleOpenOrder((OpenOrderMessage)message);
                break;

            case MessageType.SoftDollarTiers:
                HandleSoftDollarTiers((SoftDollarTiersMessage)message);
                break;
            }
        }
Exemplo n.º 3
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);
                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);
                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;
            }

            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;
            }
            }
        }
Exemplo n.º 4
0
        private void UpdateUI(IBMessage message)
        {
            switch (message.Type)
            {
            case MessageType.ConnectionStatus:
            {
                ConnectionStatusMessage status = (ConnectionStatusMessage)message;
                if (status.Connected)
                {
                    tssLabel.Text   = "Status: Connected - Client ID = " + Client.ClientId;
                    btnConnect.Text = "Disconnect";

                    //OneDayWPRTimer = new Timer(new TimerCallback(CalculateWPR), WPRType.OneDay, 0, 60 * 1000);
                    //FiveDayWPRTimer = new Timer(new TimerCallback(CalculateWPR), WPRType.FiveDay, 0, 60 * 1000);
                    //WPRTimer = new Timer(new TimerCallback(CalculateWPR), WPRType.Both, 0, 60 * 1000);
                }
                else
                {
                    tssLabel.Text   = "Status: Disconnected";
                    btnConnect.Text = "Connect";
                }
                break;
            }

            case MessageType.Error:
            {
                ErrorMessage error     = (ErrorMessage)message;
                string       requestId = GetString(error.RequestId, "RequestId");
                string       code      = GetString(error.Code, "Code");
                Log($"{(string.IsNullOrEmpty(requestId) ? string.Empty : requestId + ", ")}" +
                    $"{(string.IsNullOrEmpty(code) ? string.Empty : code + " - ")}" +
                    $"{error.Message}");
                break;
            }

            case MessageType.Log:
            {
                LogMessage log = (LogMessage)message;
                Log(log.Message);
                break;
            }

            case MessageType.CalculateWPR:
            {
                //Log(string.Format("{0:MM/dd/yyyy HH:mm:ss} - Calculate WPR", DateTime.Now));
                MDManager.UpdateUI(message);
                break;
            }

            case MessageType.TickPrice:
            {
                MDManager.UpdateUI(message);
                break;
            }

            case MessageType.HistoricalDataEnd:
            {
                HistoricalDataEndMessage historicalDataEndMessage = (HistoricalDataEndMessage)message;
                HandleMessage(new LogMessage(historicalDataEndMessage.ToString()));
                MDManager.UpdateHistoricalData(message);
                break;
            }

            case MessageType.HistoricalData:
            {
                HistoricalDataMessage historicalDataMessage = (HistoricalDataMessage)message;
                HandleMessage(new LogMessage(historicalDataMessage.ToString()));
                MDManager.UpdateHistoricalData(message);
                break;
            }

            case MessageType.RealTimeBars:
            {
                RealTimeBarMessage rtbMessage = (RealTimeBarMessage)message;
                HandleMessage(new LogMessage(rtbMessage.ToString()));
                MDManager.UpdateRealTimeData(rtbMessage);
                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);
            //		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;
            //	}
            //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(message.ToString()));
                break;
            }
            }
        }
Exemplo n.º 5
0
 public void HandleIncomingMessage(IBMessage message)
 {
     ProcessMessage(message);
 }