protected void PopulateGrid(IBMessage message) { HistoricalDataMessage bar = (HistoricalDataMessage)message; RealTimeBarMessage rtBar = (RealTimeBarMessage)message; DateTime start = new DateTime(1970, 1, 1, 0, 0, 0); DateTime dt = start.AddMilliseconds(rtBar.Timestamp * 1000).ToLocalTime(); String strDT = String.Format("{0:yyyyMMdd HH:mm:ss}", dt); gridView.Rows.Add(1); //gridView[0, gridView.Rows.Count - 1].Value = bar.Date; gridView[0, gridView.Rows.Count - 1].Value = strDT; gridView[1, gridView.Rows.Count - 1].Value = bar.Close; gridView[2, gridView.Rows.Count - 1].Value = bar.Open; gridView[3, gridView.Rows.Count - 1].Value = bar.High; gridView[4, gridView.Rows.Count - 1].Value = bar.Low; gridView[5, gridView.Rows.Count - 1].Value = rtBar.LongVolume; /* * gridView[0, gridView.Rows.Count - 1].Value = bar.Date; * gridView[1, gridView.Rows.Count - 1].Value = bar.Open; * gridView[2, gridView.Rows.Count - 1].Value = bar.High; * gridView[3, gridView.Rows.Count - 1].Value = bar.Low; * gridView[4, gridView.Rows.Count - 1].Value = bar.Close; * gridView[5, gridView.Rows.Count - 1].Value = bar.Volume; * gridView[6, gridView.Rows.Count - 1].Value = bar.Wap; * */ }
private IBMessage createStartOfMinuteMessage() { DateTime dt = new DateTime(2015, 11, 21, 9, 16, 0, DateTimeKind.Local).ToUniversalTime(); DateTime dt0 = new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime(); TimeSpan span = dt.Subtract(dt0); IBMessage RTBMessage = new RealTimeBarMessage(1000, Convert.ToInt64(span.TotalSeconds), 20100, 20200, 20000, 20100, 500, 20100, 0); return(RTBMessage); }
private IBMessage createTimeMessage(DateTime dt) { //DateTime dt = new DateTime(2015, 11, 21, 9, 10, 55); DateTime dt0 = new DateTime(1970, 1, 1, 0, 0, 0); TimeSpan span = dt.Subtract(dt0); IBMessage RTBMessage = new RealTimeBarMessage(1000, Convert.ToInt64(span.TotalSeconds), 20100, 20200, 20000, 20100, 500, 20100, 0); return(RTBMessage); }
private IBMessage createMessage_General(DateTime datetime) { DateTime dt = datetime.ToUniversalTime(); DateTime dt0 = new DateTime(1970, 1, 1, 0, 0, 0); TimeSpan span = dt.Subtract(dt0); IBMessage RTBMessage = new RealTimeBarMessage(1000, Convert.ToInt64(span.TotalSeconds), 20100, 20200, 20000, 20100, 500, 20100, 0); return(RTBMessage); }
private IBMessage createMessage_for_isRTBarProcessStart_Close(DateTime datetime) { DateTime dt = datetime.ToUniversalTime(); DateTime dt0 = new DateTime(1970, 1, 1, 0, 0, 0); TimeSpan span = dt.Subtract(dt0); IBMessage RTBMessage = new RealTimeBarMessage(1000, Convert.ToInt64(span.TotalSeconds), 20110, 20200, 20000, 20155, 500, 20100, 0); // public RealTimeBarMessage(int reqId, long date, double open, double high, double low, double close, long volume, double WAP, int count) return(RTBMessage); }
public static Boolean isThisMessageStartOfMinute(IBMessage message) { RealTimeBarMessage rtBar = (RealTimeBarMessage)message; DateTime start = new DateTime(1970, 1, 1, 0, 0, 0); DateTime current = start.AddMilliseconds(rtBar.Timestamp * 1000).ToLocalTime(); if (current.Second == 0) { return(true); } return(false); }
public void UpdateRealTimeData(RealTimeBarMessage message) { if (RealTimeReqIdToContractDesc.ContainsKey(message.RequestId)) { string contractDesc = RealTimeReqIdToContractDesc[message.RequestId]; if (ContractDescToWPR.ContainsKey(contractDesc)) { WPRCalculator calc = ContractDescToWPR[contractDesc]; calc.Close = message.Close; calc.LatestHigh = message.High; calc.LatestLow = message.Low; DataGridView grid = (DataGridView)DataGrid; CalculateBothWPRs(contractDesc, calc, grid); } } }
public void UpdateUI(RealTimeBarMessage rtBar) { barCounter++; Chart rtBarsChart = (Chart)uiControl; DateTime start = new DateTime(1970, 1, 1, 0, 0, 0); DateTime dt = start.AddMilliseconds(rtBar.Timestamp * 1000).ToLocalTime(); // adding date and high rtBarsChart.Series[0].Points.AddXY(dt, rtBar.High); // adding low rtBarsChart.Series[0].Points[barCounter].YValues[1] = rtBar.Low; //adding open rtBarsChart.Series[0].Points[barCounter].YValues[2] = rtBar.Open; // adding close rtBarsChart.Series[0].Points[barCounter].YValues[3] = rtBar.Close; PopulateGrid(rtBar); }
public override void UpdateUI(IBMessage message) { barCounter++; RealTimeBarMessage rtBar = (RealTimeBarMessage)message; /* * DateTime start = new DateTime(1970, 1, 1, 0, 0, 0); * * DateTime dt = start.AddMilliseconds(rtBar.Timestamp * 1000).ToLocalTime(); * * //***for new MD logiic*** * DateTime searchEndToMin = marketDataHelper.getTimeToMin(dt); * //DateTime searchEndToMin = marketDataHelper.getTimeToMin(dt.AddSeconds(5)); * DateTime searchStart = marketDataHelper.getGapStartTime(searchEndToMin); * Boolean fullMinute = false; * double second = dt.Second; * if (dt.Second == 0) * fullMinute=true; */ //appForm.strategyManager.handleRealTimeBarMessage(message); MDManager.handleRealTimeBarMessage(message); PopulateGrid(message); }
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; } } }
static void client_RealTimeBar(RealTimeBarMessage e) { Console.WriteLine("Received Real Time Bar: " + e.Close); }