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);
        }
Exemplo n.º 2
0
        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);
        }