/// <summary> /// Example: to get 15 minute bars, /// interval = ChartInterval.Minute /// period = 15 /// </summary> /// <param name="market"></param> /// <param name="interval"></param> /// <param name="period"></param> /// <param name="startDate"></param> /// <param name="endDate">Leave endDate = null for realtime (endDate = current date)</param> static public EZChartDataSeries MakeChartData(EZInstrument instrument, ezBarInterval barInterval, DateTime startDate, DateTime?endDate = null) { Market market = APIMain.MarketFromInstrument(instrument); // Load the data for the selected market. BarInterval interval = new BarInterval(APIConvert.ToChartInterval(barInterval.Interval), barInterval.Period); ChartDataSeries ctsChartData = new ChartDataSeries(market, interval, SessionTimeRange.Empty); var session = new ezSessionTimeRange(); EZChartDataSeries chartData = new EZChartDataSeries(market.Description, barInterval, session); var chartThread = new ChartDataThread(ctsChartData, chartData, startDate, endDate); var thread = new Thread(new ThreadStart(chartThread.Run)); thread.Name = market.Description + ":" + barInterval; thread.Start(); return(chartData); //dataPoints = new List<ezBarDataPoint>(); /*foreach (HistoricalQuote hq in historical) * { * ezBarDataPoint dp = new ezBarDataPoint(hq.Open, hq.High, hq.Low, hq.Close, 0, hq.Volume); * dataPoints.Add(dp); * }*/ }
public DataProviderMarketData() : base() { uiControl = null; uiModifyControl = null; DataUpdate += DataProviderMarketData_DataUpdate; api = APIMain.Instance; }
public TestSpreadsForm() { InitializeComponent(); api = APIMain.Instance; api.OnInsideMarketUpdate += api_OnInsideMarketUpdate; }
private void RequestChartData(EZInstrument instrument, zChartInterval interval, int period) { ChartDataForm chartForm; // Set EndDate to the current trading date. //DateTime dtEndDate = selectedContract.GetTradeDate(DateTime.Now); DateTime dtEndDate = DateTime.Now; DateTime dtStartDate; // Pick a different start date depending on if we are viewing DAYS, HOURS, MINUTES, etc... if (interval == zChartInterval.Week) { dtStartDate = dtEndDate.AddMonths(-16); } else if (interval == zChartInterval.Day) { dtStartDate = dtEndDate.AddMonths(-5); } else if (interval == zChartInterval.Minute) { dtStartDate = dtEndDate; if (period <= 15) // 15 minute (or less) bars { dtStartDate = dtStartDate.AddTradeHours(-4); } else // more than 15 minute bars { dtStartDate = dtStartDate.AddTradeDays(-2); } } else { // Anything we haven't covered, we'll load a couple days (not ideal - needs to be improved). dtStartDate = dtEndDate; dtStartDate = dtStartDate.AddTradeDays(-3); /*// 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 ((selectedContract.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 ezBarInterval(zChartDataType.Minute, 15) ezBarInterval ezbi = new ezBarInterval(interval, period); IChartDataProvider provider = new ChartDataProviderCTS(instrument.Name + " : " + ezbi, ezbi, ezSessionTimeRange.Empty); chartForm = new ChartDataForm(provider); WinForms.SetWaitCursor(true); //provider.LoadHistoricalChartData(APIMain.MarketFromInstrument(instrument), dtStartDate, dtEndDate); provider.LoadRealTimeChartData(APIMain.MarketFromInstrument(instrument), dtStartDate); chartForm.Show(); }
public DataProviderExcel() : base() { uiControl = null; uiModifyControl = null; DataUpdate += DataProviderTradeDetail_DataUpdate; api = APIMain.Instance; }
public override void UpdateProviderFromPropertyValues() { selectedMarketQuoteItem = prop["QuoteItem"]; ezInstrumentKey instrumentKey = APIFactory.InstrumentKeyFromString(prop["InstrumentKey"]); currentInstrument = APIMain.InstrumentFromKey(instrumentKey); //api.SubscribeToInstrument(instrument.Key); api.OnInsideMarketUpdate += api_OnInsideMarketUpdate; api_OnInsideMarketUpdate(currentInstrument); }
public SimpleExecutionEngine() { api = APIMain.Instance; api.OnFill += api_OnFill; executionStatus = new Dictionary <string, ExecutionStatus>(); orders = new Dictionary <string, List <EZOrder> >(); fills = new Dictionary <string, List <EZFill> >(); }
public ChartSelectorDialog() { InitializeComponent(); api = APIMain.Instance; foreach (string intervalName in Enum.GetNames(typeof(zChartInterval))) { comboChartInterval.Items.Add(intervalName); } comboChartInterval.SelectedIndex = 0; }
public DataProviderTradeDetail() : base() { uiControl = null; uiModifyControl = null; DataUpdate += DataProviderTradeDetail_DataUpdate; // Create the ItemGroup that will represent the choices of // Trade Detail available to the user. itemGroup = new SelectedItemGroup("TradeDetail"); InitializeItemGroup(); api = APIMain.Instance; }
public APITestForm() { InitializeComponent(); api = APIMain.Instance; bool autoSubscribeInstruments = false; bool subscribeMarketDepth = true; bool subscribeTimeAndSales = false; // Change the following line to use LoginType.Universal // for Universal Login to API: UserInteractionAPIStart(autoSubscribeInstruments, subscribeMarketDepth, subscribeTimeAndSales); }
private void SendOrder(zBuySell buySell, zOrderType orderType, int qty, double price) { //OrderRoute.GetOrderRoute(this, this.Market.Name); /*ezOrderProfile prof = new ezOrderProfile(OrderRoute.OrderFeed, TTAPI_Instrument); * prof.BuySell = buySell; * prof.OrderType = orderType; * prof.OrderQuantity = ezQuantity.FromInt(this, qty); * prof.LimitPrice = ezPrice.FromDouble(this, price); * prof.AccountType = OrderRoute.AccountType; * prof.AccountName = OrderRoute.AccountName; * TTAPI_Instrument.Session.SendOrder(prof); */ APIMain.SendOrder(); }
private void RequestChartData(EZInstrument instrument, zChartInterval interval, int period) { // Set EndDate to the current trading date. //DateTime dtEndDate = selectedContract.GetTradeDate(DateTime.Now); DateTime dtEndDate = DateTime.Now; DateTime dtStartDate; zChartInterval enBarInterval = zChartInterval.Hour; if (interval == zChartInterval.Day) { enBarInterval = zChartInterval.Day; // User select Day bars, load a few months of them. dtStartDate = dtEndDate.AddMonths(-3); } else { enBarInterval = interval; // User selected non-Day bars (Hour, Minute, etc.), load a couple of days of them. dtStartDate = dtEndDate; dtStartDate = dtStartDate.AddDays(-3); /*// 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 ((selectedContract.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 ezBarInterval(zChartDataType.Minute, 15) ezBarInterval oBarIntvl = new ezBarInterval(enBarInterval, period); string chartName = instrument.Name + " : " + oBarIntvl; IChartDataProvider provider = new ChartDataProviderCTS(chartName, oBarIntvl, ezSessionTimeRange.Empty); if (LoadingNewChart != null) { LoadingNewChart(provider); } this.SetChartDataProvider(provider); WinForms.SetWaitCursor(true); provider.LoadHistoricalChartData(APIMain.MarketFromInstrument(instrument), dtStartDate, dtEndDate); }
private void itemAddToFavorites_Click(object sender, EventArgs e) { //ListViewItem selectedItem = marketListView.SelectedItems[0]; Market rightClickMarket = markets[marketListView.FocusedItem.Name]; // Add to favorites. var item = new ListViewItem(rightClickMarket.Description); item.Name = rightClickMarket.Description; item.ImageKey = "market"; favoritesListView.Items.Add(item); // Add to the Favorites List we maintain behind the scenes. favoritesList.Add(rightClickMarket); //api.SaveXmlMarketList(MarketListFromListView(favoritesListView), APIMain.GetAPIDirectory("XML") + "MarketListFavorites.xml"); api.SaveXmlMarketList(favoritesList, APIMain.GetAPIDirectory("XML") + "MarketListFavorites.xml"); }
// Initialise the api when the application starts. private void frmMain_Load(object sender, System.EventArgs e) { string loginUsername = txtUsername.Text; string loginPassword = txtPassword.Text; api = APIMain.Instance; /*api.OnInitialize += new InitializeHandler(api_OnInitialize); * api.OnInstrumentFound += new InstrumentFoundHandler(api_OnInstrumentFound); * api.OnInsideMarketUpdate += new InsideMarketHandler(api_OnInsideMarketUpdate); * api.OnFill += api_OnFill; * api.OnOrder += api_OnOrder;*/ btnConnect.Enabled = false; splashForm.Status = "attempting to login..."; api.LoginFailure += api_LoginFailure; api.LoginSuccess += api_LoginSuccess; //api.StartUserInteraction(); api.StartAPIUnattended(txtUsername.Text.Trim(), txtPassword.Text.Trim(), "CTS"); }
public APIMarketSelectForm() { try { InitializeComponent(); api = APIMain.Instance; exchanges = api.GetExchangeDictionary(); selectedExchange = null; selectedContract = null; selectedMarket = null; DialogResult = DialogResult.Abort; // Start off in List view. toolStripMenuItem4.Checked = true; previouslySelectedMenuItem = toolStripMenuItem4; marketListView.View = View.List; // Load Favorites from Xml file. favoritesList = api.LoadXmlMarketList(APIMain.GetAPIDirectory("XML") + "MarketListFavorites.xml"); // Store these Favorites for easy use and access. favoritesMarkets = new Dictionary <string, Market>(); foreach (Market market in favoritesList) { favoritesMarkets[market.Description] = market; } // And display the favorites on the FavoritesListView. PopulateListView(favoritesListView, favoritesList); currentlyViewing = MarketSelectViewType.EXCHANGES; UpdateDisplay(); } catch (Exception ex) { ExceptionHandler.TraceException(ex); } }
public override void UpdateProviderFromPropertyValues() { //selectedMarketData = prop["QuoteItem"]; ezInstrumentKey instrumentKey = APIFactory.InstrumentKeyFromString(prop["InstrumentKey"]); // Get historical data for 1-hour "bars". EZInstrument instrument = APIMain.InstrumentFromKey(instrumentKey); zChartInterval interval = zChartInterval.Hour; int period = 1; // TODO analyze different time periods (ex: different hours of the trading session) to // get a better "AverageVolumePerTimePeriod" calculation. EZChartDataSeries historicalData = api.RequestHistoricalData(instrument, interval, period); if (historicalData == null) { averageVolumePerTimePeriod = prop["AverageVolumePerTimePeriod"] ?? 0; timePeriodLength = prop["TimePeriodLengthMinutes"] ?? 0.0; } else { int totalVolume = 0; int volumeCount = 0; foreach (ezBarDataPoint dp in historicalData.TradeBars) { totalVolume += dp.Volume; ++volumeCount; } double averageVolumePerHour = (double)totalVolume / (double)volumeCount; timePeriodLength = 5.0; // five minutes averageVolumePerTimePeriod = (int)Math.Round(averageVolumePerHour / 20.0); } currentInstrument = APIMain.InstrumentFromKey(instrumentKey); //api.SubscribeToInstrument(instrument.Key); api.OnInsideMarketUpdate += api_OnInsideMarketUpdate; api_OnInsideMarketUpdate(currentInstrument); }
public TradeBuilderForm() { InitializeComponent(); api = APIMain.Instance; this.DialogResult = DialogResult.Abort; initialTradeNameText = txtTradeName.Text; // Default to a buy-side entry. entrySide = zBuySell.Buy; tradeStepPanels = new CircularLinkedList <TradeRulePanelControl>(); tradeStepPanels.AddFirst(panelPreconditions); tradeStepPanels.AddLast(panelStop); tradeStepPanels.AddLast(panelExit); tradeStepPanels.AddLast(panelEntry); ChangeActivePanel(tradeStepPanels.Head); ruleChooserForm = new RuleChooserForm(this); ruleChooserForm.RuleSelect += ruleChooserForm_RuleSelect; }
public UIControlChart() { InitializeComponent(); activeIndicators = new IndicatorMap(); InitializeChart(); this.MouseWheel += ChartDataForm_MouseWheel; foreach (string intervalName in Enum.GetNames(typeof(zChartInterval))) { comboChartInterval.Items.Add(intervalName); } comboChartInterval.SelectedIndex = 0; // Trigger the ActiveChartChanged method to populate the initial indicator list. ActiveChartChanged(); status.Text = "Select a time period and interval, and use the [Select market...] button to display a chart."; api = APIMain.Instance; }
public DataProviderMomentum() : base() { // For the momentum indicator, we will start off assuming we are in the // "collecting data" state (which will change to "READY" when the DataProvider // has enough data that it can begin returning calculations. //dataProviderState = DataProviderState.COLLECTING_DATA; // Start off with ZERO momentum. As the indicator changes, POSITIVE values means market moving UP with // momentum. NEGATIVE values means market moving DOWN with momentum. momentum = 0.0; uiControl = null; uiModifyControl = null; DataUpdate += DataProviderMarketData_DataUpdate; lastPrint = null; lastPrintQty = null; lastPrintTotalVolume = 0; timeFrames = new VolumeTimeFrames(); api = APIMain.Instance; }
public static ezPrice operator --(ezPrice price) { ezPrice ezp = APIMain.DecrementTick(price.instrument, price); return(ezp); }