public void Run() { Spy.Print("Starting thread..."); ctsChartData.DataLoadComplete += chartDataSeries_DataLoadComplete; ctsChartData.DataSeriesUpdated += chartDataSeries_DataSeriesUpdated; if (endDate == DateTime.MaxValue) { // Request the chart data and subscribe for updates. ctsChartData.LoadRealTimeChartData(startDate); } else { // Load only the historical chart data. ctsChartData.LoadHistoricalChartData(startDate, endDate); } Console.WriteLine("load realtime chart data - complete"); }
public void RequestChartData(ChartInterval interval) { this.Text = moMarket.Description; // Set EndDate to the current trading date. DateTime dtEndDate = moSelectedContract.GetTradeDate(DateTime.Now); DateTime dtStartDate; T4.API.ChartData.ChartInterval enBarInterval = ChartInterval.Hour; if (interval == ChartInterval.Day) { enBarInterval = ChartInterval.Day; // User select Day bars, load a month of them. dtStartDate = dtEndDate.AddMonths(-1); } else { //enBarInterval = ChartInterval.Hour; enBarInterval = ChartInterval.Minute; // User selected Hour bars, load a couple of days of them. dtStartDate = dtEndDate; // This little loop here will ensure that we load the previous trade date as well as today and will account for weekends // and holidays. while ((moSelectedContract.GetTradeDate(dtStartDate) == dtEndDate)) { dtStartDate = dtStartDate.AddDays(-1); } } // Create a BarInterval object to tell the API what bar interval we want. // So for example, if we wanted a 15 minute bar, we would do: New T4.API.ChartData.BarInterval(ChartDataType.Minute, 15) //T4.API.ChartData.BarInterval oBarIntvl = new T4.API.ChartData.BarInterval(enBarInterval, 2); T4.API.ChartData.BarInterval oBarIntvl = new T4.API.ChartData.BarInterval(enBarInterval, 5); if (moMarket != null) { // A market was selected. Load the data for the selected market. // First, create a new ChartDataSeries. This object store the chart data from the server as well as keep it updated as live trades // come in. You REALLY should be careful to ensure that you properly Dispose this object when you are no longer using it. moBarData = new T4.API.ChartData.ChartDataSeries(moMarket, oBarIntvl, SessionTimeRange.Empty); moBarData.DataSeriesUpdated += moBarData_DataSeriesUpdated; moBarData.DataLoadComplete += moBarData_DataLoadComplete; // Request the chart data. // LoadRealTimeChartData() takes only a start date. It will load all historical chart data from that date to now and will keep // that data updated as trades get posted to the system. moBarData.LoadRealTimeChartData(dtStartDate); // Alternatively, LoadHistoricalChartData() takes a start and end date and simply only load historical chart data. This method does // NOT keep the data updated as live trades come in. //moBarData.LoadHistoricalChartData(dtStartDate, dtEndDate) } else { // A market was not selected. Load "continuation" data. // The default contructor for ContinuationSettings instructs the API to create a long-term historical series of chart data // for the contract by looking at the total traded volume for each day. The market that has the high trade volume is the // market from which data will be pulled for that trade date. This is called a "volume continuation" and is the most common // method of constructing such chart data sets for a contract. There are other types of continuations that you can create, however // they won't be discussed in this example. T4.API.ChartData.ContinuationSettings oContinuation = new T4.API.ChartData.ContinuationSettings(); // First, create a new ChartDataSeries. This object store the chart data from the server as well as keep it updated as live trades // come in. You REALLY should be careful to ensure that you properly Dispose this object when you are no longer using it. moBarData = new T4.API.ChartData.ChartDataSeries(moSelectedContract, oBarIntvl, SessionTimeRange.Empty, oContinuation); // Request the chart data. // LoadRealTimeChartData() takes only a start date. It will load all historical chart data from that date to now and will keep // that data updated as trades get posted to the system. moBarData.LoadRealTimeChartData(dtStartDate); // Alternatively, LoadHistoricalChartData() takes a start and end date and simply only load historical chart data. This method does // NOT keep the data updated as live trades come in. //moBarData.LoadHistoricalChartData(dtStartDate, dtEndDate) } }