Beispiel #1
0
		public ChartWindow(CandleSeries candleSeries, DateTime from, DateTime to)
		{
			InitializeComponent();

			if (candleSeries == null)
				throw new ArgumentNullException("candleSeries");

			_candleSeries = candleSeries;
			_trader = MainWindow.Instance.Trader;

			Chart.ChartTheme = "ExpressionDark";

			var area = new ChartArea();
			Chart.Areas.Add(area);

			_candleElem = new ChartCandleElement
			{
				Antialiasing = false, 
				UpFillColor = Colors.White,
				UpBorderColor = Colors.Black,
				DownFillColor = Colors.Black,
				DownBorderColor = Colors.Black,
			};

			area.Elements.Add(_candleElem);

			_trader.NewCandles += ProcessNewCandles;
			_trader.SubscribeCandles(_candleSeries, from, to);
		}
		public ChartWindow(CandleSeries candleSeries)
		{
			InitializeComponent();

			if (candleSeries.IsNull())
				throw new ArgumentNullException("candleSeries");

			_candleSeries = candleSeries;
			_trader = MainWindow.Instance.Trader;

			Chart.ChartTheme = "ExpressionDark";

			var area = new ChartArea();
			Chart.Areas.Add(area);

			_candleElem = new ChartCandleElement
			{
				Antialiasing = false, 
				UpFillColor = Colors.White,
				UpBorderColor = Colors.Black,
				DownFillColor = Colors.Black,
				DownBorderColor = Colors.Black,
			};

			area.Elements.Add(_candleElem);

			_trader.NewCandles += ProcessNewCandles;
			_trader.SubscribeCandles(_candleSeries, DateTime.Today - TimeSpan.FromTicks(((TimeSpan)candleSeries.Arg).Ticks * 100), DateTimeOffset.MaxValue);
		}
Beispiel #3
0
		public SmaStrategy(CandleSeries series, SimpleMovingAverage longSma, SimpleMovingAverage shortSma)
		{
			_series = series;

			LongSma = longSma;
			ShortSma = shortSma;
		}
Beispiel #4
0
		private void OnChartPanelSubscribeCandleElement(ChartCandleElement element, CandleSeries candleSeries)
		{
			_drawTimer.Cancel();

			_elements.Add(new RefPair<IChartElement, int>(element, 0));
			_drawTimer.Activate();
		}
Beispiel #5
0
		/// <summary>
		/// Subscribe to receive new candles.
		/// </summary>
		/// <param name="series">Candles series.</param>
		/// <param name="from">The initial date from which you need to get data.</param>
		/// <param name="to">The final date by which you need to get data.</param>
		public void SubscribeCandles(CandleSeries series, DateTimeOffset from, DateTimeOffset to)
		{
			if (series == null)
				throw new ArgumentNullException("series");

			if (series.CandleType != typeof(TimeFrameCandle))
				throw new ArgumentException(LocalizedStrings.NotSupportCandle.Put("OANDA", series.CandleType), "series");

			if (!(series.Arg is TimeSpan))
				throw new ArgumentException(LocalizedStrings.WrongCandleArg.Put(series.Arg), "series");

			var transactionId = TransactionIdGenerator.GetNextId();

			_series.Add(transactionId, series);

			SendInMessage(new MarketDataMessage
			{
				TransactionId = transactionId,
				DataType = MarketDataTypes.CandleTimeFrame,
				//SecurityId = GetSecurityId(series.Security),
				Arg = series.Arg,
				IsSubscribe = true,
				From = from,
				To = to,
			}.FillSecurityInfo(this, series.Security));
		}
		public void UnsubscribeCandles(CandleSeries series)
		{
			var key = new SubscriptionKey(series.Security.Id, (TimeSpan) series.Arg);
			var subscription = _candleSubscriptions.TryGetValue(key);
			if(subscription == null)
				return;

			subscription.RemoveSubscriber(series);
			if(subscription.NumSubscribers > 0)
				return;

			subscription.CandleBuilder.Candle -= CandleBuilderOnCandle;
			_candleSubscriptions.Remove(key);

			var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
			msg.TransactionId = TransactionIdGenerator.GetNextId();
			msg.OriginalTransactionId = subscription.SubscribeTransactionId;
			msg.SecurityId = GetSecurityId(series.Security);
			msg.DataType = MarketDataTypes.CandleTimeFrame;
			msg.IsSubscribe = false;
			msg.From = subscription.From;
			msg.Arg = subscription.TimeFrame;

			SendInMessage(msg);

			UnSubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
		}
		/// <summary>
		/// Создать <see cref="CandleManagerIndicatorSource"/>.
		/// </summary>
		/// <param name="series">Серия свечек.</param>
		public CandleSeriesIndicatorSource(CandleSeries series)
		{
			if (series == null)
				throw new ArgumentNullException("series");

			_series = series;
			_series.ProcessCandle += OnProcessCandle;
		}
Beispiel #8
0
		private void OnChartPanelSubscribeIndicatorElement(ChartIndicatorElement element, CandleSeries candleSeries, IIndicator indicator)
		{
			_drawTimer.Cancel();

			_elements.Add(new RefPair<IChartElement, int>(element, 0));
			_indicators.Add(element, indicator);
			_drawTimer.Activate();
		}
Beispiel #9
0
		public SmaStrategy(ICandleManager candleManager, CandleSeries series, SimpleMovingAverage longSma, SimpleMovingAverage shortSma)
		{
			_candleManager = candleManager;
			_series = series;

			LongSma = longSma;
			ShortSma = shortSma;
		}
		private void CandleSettingsEditorOnClosed(object sender, RoutedEventArgs routedEventArgs)
		{
			if (_tempCandleSeries == CandleSettingsEditor.Settings || _candleSeries == null)
				return;

			_tempCandleSeries = CandleSettingsEditor.Settings.Clone();
			SecurityPicker_OnSecuritySelected(SecurityPicker.SelectedSecurity);
		}
		/// <summary>
		/// Создать <see cref="CandleManagerIndicatorSource"/>.
		/// </summary>
		/// <param name="series">Серия свечек.</param>
		/// <param name="getPart">Конвертер свечки, через которую можно получить ее параметр (цену закрытия <see cref="Candle.ClosePrice"/>, цену открытия <see cref="Candle.OpenPrice"/> и т.д.).</param>
		public CandleSeriesIndicatorSource(CandleSeries series, Func<Candle, decimal> getPart)
			: base(getPart)
		{
			if (series == null)
				throw new ArgumentNullException("series");

			_series = series;
			_series.ProcessCandle += OnProcessCandle;
		}
Beispiel #12
0
		private void ProcessNewCandles(CandleSeries series, IEnumerable<Candle> candles)
		{
			if (series != _candleSeries)
				return;

			foreach (var timeFrameCandle in candles)
			{
				Chart.Draw(_candleElem, timeFrameCandle);
			}
		}
Beispiel #13
0
		public SmaStrategy(CandleSeries series, SimpleMovingAverage longSma, SimpleMovingAverage shortSma)
		{
			_series = series;

			LongSma = longSma;
			ShortSma = shortSma;

			_longSmaPeriod = this.Param("LongSmaPeriod", longSma.Length);
			_shortSmaPeriod = this.Param("ShortSmaPeriod", shortSma.Length);
		}
Beispiel #14
0
		IEnumerable<Range<DateTimeOffset>> IExternalCandleSource.GetSupportedRanges(CandleSeries series)
		{
			if (series.CandleType != typeof(TimeFrameCandle) || !(series.Arg is TimeSpan))
				yield break;

			var tf = (TimeSpan)series.Arg;

			if (OandaMessageAdapter.TimeFrames.Contains(tf))
				yield return new Range<DateTimeOffset>(DateTimeOffset.MinValue, CurrentTime);
		}
Beispiel #15
0
        static void Main(string[] args)
        {
            _candleManager = new CandleManager();

            if (!GetSetings())
                return;

            var storageRegistry = new StorageRegistry();
            ((LocalMarketDataDrive)storageRegistry.DefaultDrive).Path = _historyPath;

            var cbs = new TradeStorageCandleBuilderSource { StorageRegistry = storageRegistry };
            _candleManager.Sources.OfType<TimeFrameCandleBuilder>().Single().Sources.Add(cbs);


            

            _candleManager.Processing += GetCandles;


            foreach (var Sec in listOfName)
            {
                foreach (var timeFrame in listOfTimeFrame)
                {
                  
                   

                _series = new CandleSeries(typeof(TimeFrameCandle), Sec, timeFrame);

                LisfStreamWriters.Add(_series.ToString(), new StreamWriter(GetFileName(_series), false));


                _candleManager.Start(_series, _startTime, _endTime);

                


 
    }

            }

     

            Console.ReadKey();

            // Закроем все потоки которые мы записывали

            foreach (var strim in LisfStreamWriters)
            {
                strim.Value.Close();   
            }

        

        }
		public SubscribeCandleElementCommand(ChartCandleElement element, CandleSeries candleSeries)
		{
			if (element == null)
				throw new ArgumentNullException(nameof(element));

			if (candleSeries == null)
				throw new ArgumentNullException(nameof(candleSeries));

			Element = element;
			CandleSeries = candleSeries;
		}
		public ChartAddElementCommand(ChartArea area, IChartElement element, CandleSeries series = null)
		{
			if (area == null)
				throw new ArgumentNullException(nameof(area));

			if (element == null)
				throw new ArgumentNullException(nameof(element));

			Area = area;
			Element = element;
			Series = series;
		}
Beispiel #18
0
		private void ProcessNewCandles(CandleSeries series, IEnumerable<Candle> candles)
		{
			if (series != _candleSeries)
				return;

			this.GuiAsync(() =>
			{
				foreach (var timeFrameCandle in candles)
				{
					Chart.ProcessCandle(_candleElem, timeFrameCandle);
				}
			});
		}
Beispiel #19
0
		protected override void OnStarted()
		{
			_series = new CandleSeries(typeof(TimeFrameCandle), Security, TimeFrame);

			_shortSma.Length = ShortSmaPeriod;
			_longSma.Length = LongSmaPeriod;

			if (_area == null)
			{
				_area = new ChartArea();

				_area.Elements.Add(new ChartCandleElement());
				_area.Elements.Add(new ChartIndicatorElement { Color = Colors.Green, StrokeThickness = 1 });
				_area.Elements.Add(new ChartIndicatorElement { Color = Colors.Red, StrokeThickness = 1 });
				_area.Elements.Add(new ChartTradeElement());

				new ChartAddAreaCommand(_area).Process(this);
			}

			this
				.WhenNewMyTrades()
				.Do(trades =>
				{
					foreach (var myTrade in trades)
					{
						new ChartDrawCommand(myTrade.Trade.Time, new Dictionary<IChartElement, object>
						{
							{ _area.Elements[3], myTrade }
						}).Process(this);
					}
				})
				.Apply(this);

			_series
				.WhenCandles()
				.Do(Process)
				.Apply(this);

			this.GetCandleManager().Start(_series);

			Security
				.WhenMarketDepthChanged(SafeGetConnector())
				.Do(md => new UpdateMarketDepthCommand(md).Process(this))
				.Apply(this);

			SafeGetConnector().RegisterMarketDepth(Security);

			base.OnStarted();
		}
		public SubscribeIndicatorElementCommand(ChartIndicatorElement element, CandleSeries candleSeries, IIndicator indicator)
		{
			if (element == null)
				throw new ArgumentNullException(nameof(element));

			if (candleSeries == null)
				throw new ArgumentNullException(nameof(candleSeries));

			if (indicator == null)
				throw new ArgumentNullException(nameof(indicator));

			Element = element;
			CandleSeries = candleSeries;
			Indicator = indicator;
		}
Beispiel #21
0
		public SmaStrategy(IChart chart, ChartCandleElement candlesElem, ChartTradeElement tradesElem, 
			SimpleMovingAverage shortMa, ChartIndicatorElement shortElem,
			SimpleMovingAverage longMa, ChartIndicatorElement longElem,
			CandleSeries series)
		{
			_chart = chart;
			_candlesElem = candlesElem;
			_tradesElem = tradesElem;
			_shortElem = shortElem;
			_longElem = longElem;
			
			_series = series;

			ShortSma = shortMa;
			LongSma = longMa;
		}
Beispiel #22
0
		private void Chart_OnSubscribeIndicatorElement(ChartIndicatorElement element, CandleSeries series, IIndicator indicator, ChartPanel chart)
		{
			var values = _allCandles
				.Select(candle =>
				{
					if (candle.State != CandleStates.Finished)
						candle.State = CandleStates.Finished;

					return new RefPair<DateTimeOffset, IDictionary<IChartElement, object>>(candle.OpenTime, new Dictionary<IChartElement, object>
					{
						{ element, indicator.Process(candle) }
					});
				})
				.ToArray();

			chart.Draw(values);
		}
        public EMAEventModelStrategy(CandleSeries series, 
            ExponentialMovingAverage filterMA, ExponentialMovingAverage longMA, ExponentialMovingAverage shortMA,
            Unit takeProfitUnit, Unit stopLossUnit)
        {
            this.FilterMA = filterMA;
            this.LongMA = longMA;
            this.ShortMA = shortMA;

            this.CandleSeries = series;

            this.TakeProfitUnit = takeProfitUnit;
            this.StopLossUnit = stopLossUnit;

            this.StopTradingUnit = this.StopLossUnit * 3;

            this.UseQuoting = true;
            this.BestPriceOffset = 5;
        }
		public void UnsubscribeCandles(CandleSeries series)
		{
			var tuple = _subscriptionDates.TryGetValue(series.Security.Id);
			if(tuple == null)
				return;

			var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
			msg.TransactionId = TransactionIdGenerator.GetNextId();
			msg.OriginalTransactionId = tuple.Item2;
			msg.SecurityId = GetSecurityId(series.Security);
			msg.DataType = MarketDataTypes.CandleTimeFrame;
			msg.IsSubscribe = false;
			msg.From = tuple.Item1;
			msg.Arg = series.Arg;

			SendInMessage(msg);

			UnSubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
		}
		public void SubscribeCandles(CandleSeries series)
		{
			var transId = TransactionIdGenerator.GetNextId();
			
			_subscriptionDates[series.Security.Id] = Tuple.Create(series.From, transId);

			var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
			msg.TransactionId = transId;
			msg.SecurityId = GetSecurityId(series.Security);
			msg.DataType = MarketDataTypes.CandleTimeFrame;
			msg.IsSubscribe = true;
			msg.From = series.From;
			msg.Arg = (TimeSpan)series.Arg;

			_lastCandles.Remove(Tuple.Create(msg.SecurityId, msg.Arg));

			SendInMessage(msg);

			SubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
		}
		/// <summary>
		/// Создать <see cref="CandleSettingsEditor"/>.
		/// </summary>
		public CandleSettingsEditor()
		{
			InitializeComponent();
			CandleType.ItemsSource = _candleTypes;

			_visibility.Add(typeof(TimeFrameCandle), TimeFramePanel);
			_visibility.Add(typeof(TickCandle), IntValuePanel);
			_visibility.Add(typeof(VolumeCandle), DecimalValuePanel);
			_visibility.Add(typeof(RangeCandle), UnitValuePanel);
			_visibility.Add(typeof(RenkoCandle), UnitValuePanel);
			_visibility.Add(typeof(PnFCandle), PnfValuePanel);

			Settings = new CandleSeries
			{
				CandleType = typeof(TimeFrameCandle),
				Arg = TimeSpan.FromMinutes(1),
			};

			UnitValue.Value = new Unit(1);
			PnfBoxSize.Value = new Unit(1);
		}
Beispiel #27
0
		public void SubscribeCandles(CandleSeries series)
		{
			if (!IsConnected)
			{
				_subscribersBuffer.Add(series);
				return;
			}

			var key = new SubscriptionKey(series.Security.Id, (TimeSpan) series.Arg);
			var transId = TransactionIdGenerator.GetNextId();
			
			var subscription = _candleSubscriptions.TryGetValue(key);

			if (subscription != null)
			{
				Candles?.Invoke(series, subscription.CandleBuilder.AllCandles);
				subscription.AddSubscriber(series);

				return;
			}

			subscription = new CandleSubscription(series.Security, series.From, (TimeSpan) series.Arg, transId);
			subscription.AddSubscriber(series);
			_candleSubscriptions.Add(key, subscription);

			subscription.CandleBuilder.Candle += CandleBuilderOnCandle;

			var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
			msg.TransactionId = transId;
			msg.SecurityId = GetSecurityId(series.Security);
			msg.DataType = MarketDataTypes.CandleTimeFrame;
			msg.IsSubscribe = true;
			msg.From = series.From;
			msg.Arg = series.Arg;

			SendInMessage(msg);

			SubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
		}
		/// <summary>
		/// To get the number of candles.
		/// </summary>
		/// <param name="series">Candles series.</param>
		/// <returns>Number of candles.</returns>
		public int GetCandleCount(CandleSeries series)
		{
			var info = GetInfo(series);
			return info == null ? 0 : info.CandleCount;
		}
Beispiel #29
0
 /// <summary>
 /// To create candles from the tick trades collection.
 /// </summary>
 /// <param name="trades">Tick trades.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="onlyFormed">Process only formed candles.</param>
 /// <returns>Candles.</returns>
 public static IEnumerable <Candle> ToCandles(this IEnumerable <Trade> trades, CandleSeries series, bool onlyFormed = true)
 {
     return(trades
            .ToMessages <Trade, ExecutionMessage>()
            .ToCandles(series, onlyFormed)
            .ToCandles <Candle>(series.Security, series.CandleType));
 }
Beispiel #30
0
 /// <summary>
 /// To create candles from the order books collection.
 /// </summary>
 /// <param name="depths">Market depths.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="type">Type of candle depth based data.</param>
 /// <param name="onlyFormed">Process only formed candles.</param>
 /// <returns>Candles.</returns>
 public static IEnumerable <Candle> ToCandles(this IEnumerable <MarketDepth> depths, CandleSeries series, DepthCandleSourceTypes type = DepthCandleSourceTypes.Middle, bool onlyFormed = true)
 {
     return(depths
            .ToMessages <MarketDepth, QuoteChangeMessage>()
            .ToCandles(series, type, onlyFormed)
            .ToCandles <Candle>(series.Security, series.CandleType));
 }
Beispiel #31
0
 /// <summary>
 /// To start candles getting.
 /// </summary>
 /// <param name="manager">The candles manager.</param>
 /// <param name="series">Candles series.</param>
 public static void Start(this ICandleManager manager, CandleSeries series)
 {
     manager.ThrowIfNull().Start(series, series.From, series.To);
 }
Beispiel #32
0
 /// <summary>
 /// To get all candles.
 /// </summary>
 /// <typeparam name="TCandle">The candles type.</typeparam>
 /// <param name="candleManager">The candles manager.</param>
 /// <param name="series">Candles series.</param>
 /// <returns>Candles.</returns>
 public static IEnumerable <TCandle> GetCandles <TCandle>(this ICandleManager candleManager, CandleSeries series)
     where TCandle : Candle
 {
     return(candleManager.ThrowIfNull().Container.GetCandles(series).OfType <TCandle>());
 }
Beispiel #33
0
 /// <summary>
 /// To get candles by the total number.
 /// </summary>
 /// <typeparam name="TCandle">The candles type.</typeparam>
 /// <param name="candleManager">The candles manager.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="candleCount">The number of candles that should be returned.</param>
 /// <returns>Found candles.</returns>
 public static IEnumerable <TCandle> GetCandles <TCandle>(this ICandleManager candleManager, CandleSeries series, int candleCount)
 {
     return(candleManager.ThrowIfNull().Container.GetCandles(series, candleCount).OfType <TCandle>());
 }
Beispiel #34
0
 /// <summary>
 /// To get a temporary candle on the specific date.
 /// </summary>
 /// <param name="candleManager">The candles manager.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="time">The candle date.</param>
 /// <returns>The found candle (<see langword="null" />, if the candle by the specified criteria does not exist).</returns>
 public static TimeFrameCandle GetTimeFrameCandle(this ICandleManager candleManager, CandleSeries series, DateTimeOffset time)
 {
     return(candleManager.GetCandles <TimeFrameCandle>(series).FirstOrDefault(c => c.OpenTime == time));
 }
Beispiel #35
0
        IEnumerable <Range <DateTimeOffset> > ICandleSource <Candle> .GetSupportedRanges(CandleSeries series)
        {
            if (series == null)
            {
                throw new ArgumentNullException(nameof(series));
            }

            if (series.Security is IndexSecurity)
            {
                yield return(new Range <DateTimeOffset>(_from, _to));
            }
        }
Beispiel #36
0
 void ICandleSource <Candle> .Stop(CandleSeries series)
 {
     _connector.UnSubscribeCandles(series);
     _candleSeries.Remove(series);
 }
Beispiel #37
0
 void ICandleSource <Candle> .Start(CandleSeries series, DateTimeOffset?from, DateTimeOffset?to)
 {
     _candleSeries.Add(series);
     _connector.SubscribeCandles(series, from, to);
 }
Beispiel #38
0
 IEnumerable <Range <DateTimeOffset> > ICandleSource <Candle> .GetSupportedRanges(CandleSeries series)
 {
     yield return(new Range <DateTimeOffset>(DateTimeOffset.MinValue, DateTimeOffset.MaxValue));
 }
Beispiel #39
0
 /// <summary>
 /// To create candles from the tick trades collection.
 /// </summary>
 /// <param name="trades">Tick trades.</param>
 /// <param name="series">Candles series.</param>
 /// <returns>Candles.</returns>
 public static IEnumerableEx <CandleMessage> ToCandles(this IEnumerableEx <ExecutionMessage> trades, CandleSeries series)
 {
     return(trades
            .ToEntities <ExecutionMessage, Trade>(series.Security)
            .ToCandles(series)
            .ToMessages <Candle, CandleMessage>());
 }
Beispiel #40
0
 private void OnStopped(CandleSeries series)
 {
     Stopped?.Invoke(series);
 }
Beispiel #41
0
 void ICandleSource <Candle> .Stop(CandleSeries series)
 {
     _series.Remove(series);
     _source.UnSubscribeCandles(series);
 }
		private SeriesInfo GetInfo(CandleSeries series)
		{
			if (series == null)
				throw new ArgumentNullException(nameof(series));

			return _info.TryGetValue(series);
		}
Beispiel #43
0
 /// <summary>
 /// To create candles from the order books collection.
 /// </summary>
 /// <param name="depths">Market depths.</param>
 /// <param name="series">Candles series.</param>
 /// <returns>Candles.</returns>
 public static IEnumerableEx <CandleMessage> ToCandles(this IEnumerableEx <QuoteChangeMessage> depths, CandleSeries series)
 {
     return(depths
            .ToEntities <QuoteChangeMessage, MarketDepth>(series.Security)
            .ToCandles(series)
            .ToMessages <Candle, CandleMessage>());
 }
Beispiel #44
0
 IEnumerable <Range <DateTimeOffset> > ICandleSource <Candle> .GetSupportedRanges(CandleSeries series)
 {
     return(_source.GetSupportedRanges(series));
 }
Beispiel #45
0
 /// <summary>
 /// To get a candle by the index.
 /// </summary>
 /// <typeparam name="TCandle">The candles type.</typeparam>
 /// <param name="candleManager">The candles manager.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="candleIndex">The candle's position number from the end.</param>
 /// <returns>The found candle. If the candle does not exist, then <see langword="null" /> will be returned.</returns>
 public static TCandle GetCandle <TCandle>(this ICandleManager candleManager, CandleSeries series, int candleIndex)
     where TCandle : Candle
 {
     return((TCandle)candleManager.ThrowIfNull().Container.GetCandle(series, candleIndex));
 }
Beispiel #46
0
 /// <summary>
 /// To create candles from the tick trades collection.
 /// </summary>
 /// <param name="trades">Tick trades.</param>
 /// <param name="series">Candles series.</param>
 /// <returns>Candles.</returns>
 public static IEnumerableEx <Candle> ToCandles(this IEnumerableEx <Trade> trades, CandleSeries series)
 {
     return(new CandleEnumerable <Trade>(series, trades));
 }
Beispiel #47
0
 /// <summary>
 /// To get candles by date range.
 /// </summary>
 /// <typeparam name="TCandle">The candles type.</typeparam>
 /// <param name="candleManager">The candles manager.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="timeRange">The date range which should include candles. The <see cref="Candle.OpenTime"/> value is taken into consideration.</param>
 /// <returns>Found candles.</returns>
 public static IEnumerable <TCandle> GetCandles <TCandle>(this ICandleManager candleManager, CandleSeries series, Range <DateTimeOffset> timeRange)
     where TCandle : Candle
 {
     return(candleManager.ThrowIfNull().Container.GetCandles(series, timeRange).OfType <TCandle>());
 }
Beispiel #48
0
 public CandleEnumerable(CandleSeries series, IEnumerableEx <TValue> values)
     : base(() => new CandleEnumerator(series, values))
 {
     _values = values;
 }
Beispiel #49
0
        ///// <summary>
        ///// To stop candles getting.
        ///// </summary>
        ///// <param name="series">Candles series.</param>
        //public static void Stop(this CandleSeries series)
        //{
        //	var manager = series.ThrowIfNull().CandleManager;

        //	// серию ранее не запускали, значит и останавливать не нужно
        //	if (manager == null)
        //		return;

        //	manager.Stop(series);
        //}

        //private static ICandleManagerContainer GetContainer(this CandleSeries series)
        //{
        //	return series.ThrowIfNull().CandleManager.Container;
        //}

        /// <summary>
        /// To get the number of candles.
        /// </summary>
        /// <param name="candleManager">The candles manager.</param>
        /// <param name="series">Candles series.</param>
        /// <returns>Number of candles.</returns>
        public static int GetCandleCount(this ICandleManager candleManager, CandleSeries series)
        {
            return(candleManager.ThrowIfNull().Container.GetCandleCount(series));
        }
Beispiel #50
0
 public void PushNewValue(CandleSeries series, TValue value)
 {
     NewSourceValues(series, new[] { value });
 }
Beispiel #51
0
 /// <summary>
 /// To create candles from the order books collection.
 /// </summary>
 /// <param name="depths">Market depths.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="type">Type of candle depth based data.</param>
 /// <param name="onlyFormed">Process only formed candles.</param>
 /// <returns>Candles.</returns>
 public static IEnumerable <CandleMessage> ToCandles(this IEnumerable <QuoteChangeMessage> depths, CandleSeries series, DepthCandleSourceTypes type = DepthCandleSourceTypes.Middle, bool onlyFormed = true)
 {
     return(new CandleMessageEnumerable(series.ToMarketDataMessage(true), onlyFormed, depths, type));
 }
Beispiel #52
0
 public override void Stop(CandleSeries series)
 {
     RaiseStopped(series);
 }
Beispiel #53
0
 /// <summary>
 /// To create candles from the tick trades collection.
 /// </summary>
 /// <param name="trades">Tick trades.</param>
 /// <param name="series">Candles series.</param>
 /// <param name="onlyFormed">Process only formed candles.</param>
 /// <returns>Candles.</returns>
 public static IEnumerable <CandleMessage> ToCandles(this IEnumerable <ExecutionMessage> trades, CandleSeries series, bool onlyFormed = true)
 {
     return(new CandleMessageEnumerable(series.ToMarketDataMessage(true), onlyFormed, trades));
 }
Beispiel #54
0
 public override void Start(CandleSeries series, DateTimeOffset from, DateTimeOffset to)
 {
 }
Beispiel #55
0
 void ICandleSource <Candle> .Start(CandleSeries series, DateTimeOffset from, DateTimeOffset to)
 {
     _source.SubscribeCandles(series, from, to);
 }
Beispiel #56
0
                    public override IEnumerable <Range <DateTimeOffset> > GetSupportedRanges(CandleSeries series)
                    {
                        if (series == null)
                        {
                            throw new ArgumentNullException(nameof(series));
                        }

                        if (series.Security != _security)
                        {
                            yield break;
                        }

                        yield return(new Range <DateTimeOffset>(DateTimeOffset.MinValue, DateTimeOffset.MaxValue));
                    }
		/// <summary>
		/// To notify the container about the start of the candles getting for the series.
		/// </summary>
		/// <param name="series">Candles series.</param>
		/// <param name="from">The initial date from which the candles will be get.</param>
		/// <param name="to">The final date by which the candles will be get.</param>
		public void Start(CandleSeries series, DateTimeOffset from, DateTimeOffset to)
		{
			if (series == null)
				throw new ArgumentNullException(nameof(series));

			var info = _info.SafeAdd(series, key => new SeriesInfo(this));
			info.Reset(from);
		}
Beispiel #58
0
 /// <summary>
 /// To get the current candle.
 /// </summary>
 /// <typeparam name="TCandle">The candles type.</typeparam>
 /// <param name="candleManager">The candles manager.</param>
 /// <param name="series">Candles series.</param>
 /// <returns>The found candle. If the candle does not exist, the <see langword="null" /> will be returned.</returns>
 public static TCandle GetCurrentCandle <TCandle>(this ICandleManager candleManager, CandleSeries series)
     where TCandle : Candle
 {
     return(candleManager.GetCandle <TCandle>(series, 0));
 }
Beispiel #59
0
 private void OnConnectorCandleSeriesStopped(CandleSeries series)
 {
     _candleSeries.Remove(series);
     Stopped?.Invoke(series);
 }
Beispiel #60
0
 /// <summary>
 /// To create candles from the order books collection.
 /// </summary>
 /// <param name="depths">Market depths.</param>
 /// <param name="series">Candles series.</param>
 /// <returns>Candles.</returns>
 public static IEnumerableEx <Candle> ToCandles(this IEnumerableEx <MarketDepth> depths, CandleSeries series)
 {
     return(new CandleEnumerable <MarketDepth>(series, depths));
 }