Exemplo n.º 1
0
        private static void SerializeChange(BitArrayWriter writer, RefPair <decimal, decimal> info, decimal price)
        {
            //if (price == 0)
            //	throw new ArgumentOutOfRangeException(nameof(price));

            if (info.First == 0)
            {
                info.First = info.Second = price;
            }

            info.Second = writer.WriteDecimal(price, info.Second);
        }
Exemplo n.º 2
0
        private void DrawTimerOnElapsed(Func <bool> canProcess)
        {
            try
            {
                GuiDispatcher.GlobalDispatcher.AddAction(() => CancelButton.Visibility = Visibility.Visible);

                var index = 0;

                foreach (var batch in _candles.Batch(50))
                {
                    if (!canProcess())
                    {
                        break;
                    }

                    var values = new List <RefPair <DateTimeOffset, IDictionary <IChartElement, object> > >();

                    foreach (var c in batch)
                    {
                        var candle = c;

                        var pair = new RefPair <DateTimeOffset, IDictionary <IChartElement, object> >(candle.OpenTime, new Dictionary <IChartElement, object>());

                        foreach (var elemPair in _elements.Cache)
                        {
                            if (elemPair.Second >= index)
                            {
                                continue;
                            }

                            elemPair.First.DoIf <IChartElement, ChartCandleElement>(e => pair.Second.Add(e, candle));
                            elemPair.First.DoIf <IChartElement, ChartIndicatorElement>(e => pair.Second.Add(e, CreateIndicatorValue(e, candle)));

                            elemPair.Second = index;
                        }

                        values.Add(pair);

                        index++;
                    }

                    ChartPanel.Draw(values);
                }

                GuiDispatcher.GlobalDispatcher.AddAction(() => CancelButton.Visibility = Visibility.Collapsed);
            }
            catch (Exception ex)
            {
                ex.LogError();
            }
        }
Exemplo n.º 3
0
        private static List <Message> GetMessages(RefPair <List <Message>, Dictionary <MessageTypes, Message> > tuple)
        {
            var retVal = tuple.First;

            if (retVal == null)
            {
                retVal = tuple.Second.Values.ToList();
            }
            else if (tuple.Second != null)
            {
                retVal.AddRange(tuple.Second.Values);
            }

            return(retVal);
        }
Exemplo n.º 4
0
        private void ProcessInnerAdapterConnectMessage(IMessageAdapter innerAdapter, ConnectMessage message)
        {
            if (message.Error != null)
            {
                SessionHolder.AddErrorLog(LocalizedStrings.Str625Params, innerAdapter.GetType().Name, message.Error);
            }

            Exception error = null;

            var canProcess = _innerAdapters.SyncGet(c =>
            {
                var connected = message.Error == null;

                _adapterStates[innerAdapter] = new RefPair <bool, Exception>(connected, message.Error);

                if (_canRaiseConnected && connected)
                {
                    _canRaiseConnected    = false;
                    _canRaiseDisconnected = true;

                    ResetConnectionErrors();

                    return(true);
                }

                if (_adapterStates.Count == c.Count)
                {
                    // произошла ошибка и нет ни одного подключенного коннектора
                    if (_adapterStates.Values.All(p => !p.First))
                    {
                        error = new AggregateException(LocalizedStrings.Str626, _adapterStates.Values.Select(p => p.Second));
                        return(true);
                    }

                    ResetConnectionErrors();
                }

                return(false);
            });

            if (canProcess)
            {
                SendOutMessage(new ConnectMessage {
                    Error = error
                });
            }
        }
Exemplo n.º 5
0
        public PositionMetaInfo(DateTime date)
            : base(date)
        {
            BeginValue         = new RefPair <decimal, decimal>();
            CurrentValue       = new RefPair <decimal, decimal>();
            BlockedValue       = new RefPair <decimal, decimal>();
            CurrentPrice       = new RefPair <decimal, decimal>();
            AveragePrice       = new RefPair <decimal, decimal>();
            UnrealizedPnL      = new RefPair <decimal, decimal>();
            RealizedPnL        = new RefPair <decimal, decimal>();
            VariationMargin    = new RefPair <decimal, decimal>();
            Leverage           = new RefPair <decimal, decimal>();
            Commission         = new RefPair <decimal, decimal>();
            CurrentValueInLots = new RefPair <decimal, decimal>();

            Portfolios  = new List <string>();
            ClientCodes = new List <string>();
            DepoNames   = new List <string>();
        }
Exemplo n.º 6
0
        private void ProcessInnerAdapterDisconnectMessage(IMessageAdapter innerAdapter, DisconnectMessage message)
        {
            if (message.Error != null)
            {
                SessionHolder.AddErrorLog(LocalizedStrings.Str627Params, innerAdapter.GetType().Name, message.Error);
            }

            Exception error = null;

            var canProcess = _innerAdapters.SyncGet(c =>
            {
                _adapterStates[innerAdapter] = new RefPair <bool, Exception>(false, message.Error);

                if (_canRaiseDisconnected && _adapterStates.Values.All(p => !p.First))
                {
                    _canRaiseConnected    = true;
                    _canRaiseDisconnected = false;

                    var errors = _adapterStates.Values.Where(p => p.Second != null).Select(p => p.Second).ToArray();

                    if (errors.Length != 0)
                    {
                        error = new AggregateException(LocalizedStrings.Str628, errors);
                        ResetConnectionErrors();
                    }

                    DisposeInnerAdapters();

                    return(true);
                }

                return(false);
            });

            if (canProcess)
            {
                SendOutMessage(new DisconnectMessage {
                    Error = error
                });
            }
        }
Exemplo n.º 7
0
        private void ProcessCandleElement(IEnumerable <Candle> candles)
        {
            foreach (var batch in candles.Batch(50))
            {
                if (_isStopped || _isDisposed)
                {
                    break;
                }

                var values = new List <RefPair <DateTimeOffset, IDictionary <IChartElement, object> > >();

                foreach (var c in batch)
                {
                    var candle = c;

                    var pair = new RefPair <DateTimeOffset, IDictionary <IChartElement, object> >(candle.OpenTime, new Dictionary <IChartElement, object>());

                    _candlesCount++;

                    // ограничиваем кол-во передаваемых свечек, чтобы не фризился интерфейс
                    if (_candlesCount % 100 == 0)
                    {
                        System.Threading.Thread.Sleep(200);
                    }

                    foreach (var el in ChartPanel.Elements)
                    {
                        el.DoIf <IChartElement, ChartCandleElement>(e => pair.Second.Add(e, candle));
                        el.DoIf <IChartElement, ChartIndicatorElement>(e => pair.Second.Add(e, CreateIndicatorValue(e, candle)));
                    }

                    values.Add(pair);
                }

                ChartPanel.Draw(values);
            }
        }
Exemplo n.º 8
0
        private void DrawTimerOnElapsed()
        {
            try
            {
                if (_isDisposed)
                {
                    return;
                }

                _isStopped = false;

                var elements = _elements.SyncGet(c => c.CopyAndClear());

                var candleElement = elements.OfType <ChartCandleElement>().FirstOrDefault();

                if (candleElement == null)
                {
                    foreach (var e in elements.OfType <ChartIndicatorElement>())
                    {
                        var element = e;

                        var allValues = _candles
                                        .Take(_candlesCount)
                                        .Select(candle => new RefPair <DateTimeOffset, IDictionary <IChartElement, object> >(candle.OpenTime, new Dictionary <IChartElement, object>
                        {
                            { element, CreateIndicatorValue(element, candle) }
                        }))
                                        .ToList();

                        GuiDispatcher.GlobalDispatcher.AddAction(() =>
                        {
                            ChartPanel.Reset(new[] { element });
                            ChartPanel.Draw(allValues);
                        });
                    }
                }
                else
                {
                    foreach (var batch in _candles.Batch(50))
                    {
                        if (_isStopped || _isDisposed)
                        {
                            break;
                        }

                        var values = new List <RefPair <DateTimeOffset, IDictionary <IChartElement, object> > >();

                        foreach (var c in batch)
                        {
                            var candle = c;

                            var pair = new RefPair <DateTimeOffset, IDictionary <IChartElement, object> >(candle.OpenTime, new Dictionary <IChartElement, object>());

                            _candlesCount++;

                            //// ограничиваем кол-во передаваемых свечек, чтобы не фризился интерфейс
                            //if (_candlesCount % 100 == 0)
                            //	System.Threading.Thread.Sleep(200);

                            foreach (var el in ChartPanel.Elements)
                            {
                                el.DoIf <IChartElement, ChartCandleElement>(e => pair.Second.Add(e, candle));
                                el.DoIf <IChartElement, ChartIndicatorElement>(e => pair.Second.Add(e, CreateIndicatorValue(e, candle)));
                            }

                            values.Add(pair);
                        }

                        ChartPanel.Draw(values);
                    }
                }

                GuiDispatcher.GlobalDispatcher.AddAction(() => CancelButton.Visibility = Visibility.Collapsed);
            }
            catch (Exception ex)
            {
                ex.LogError();
            }
        }
Exemplo n.º 9
0
 private static decimal DeserializeChange(BitArrayReader reader, RefPair <decimal, decimal> info)
 {
     info.First = reader.ReadDecimal(info.First);
     return(info.First);
 }
Exemplo n.º 10
0
 private static RefPair <decimal, decimal> Clone(RefPair <decimal, decimal> info)
 {
     return(RefTuple.Create(info.First, info.Second));
 }
Exemplo n.º 11
0
 private static void Write(Stream stream, RefPair <decimal, decimal> info)
 {
     stream.WriteEx(info.First);
     stream.WriteEx(info.Second);
 }
Exemplo n.º 12
0
		private void DrawTimerOnElapsed(Func<bool> canProcess)
		{
			try
			{
				GuiDispatcher.GlobalDispatcher.AddAction(() => CancelButton.Visibility = Visibility.Visible);

				var index = 0;

				foreach (var batch in _candles.Batch(50))
				{
					if (!canProcess())
						break;

					var values = new List<RefPair<DateTimeOffset, IDictionary<IChartElement, object>>>();

					foreach (var c in batch)
					{
						var candle = c;

						var pair = new RefPair<DateTimeOffset, IDictionary<IChartElement, object>>(candle.OpenTime, new Dictionary<IChartElement, object>());

						foreach (var elemPair in _elements.Cache)
						{
							if (elemPair.Second >= index)
								continue;

							elemPair.First.DoIf<IChartElement, ChartCandleElement>(e => pair.Second.Add(e, candle));
							elemPair.First.DoIf<IChartElement, ChartIndicatorElement>(e => pair.Second.Add(e, CreateIndicatorValue(e, candle)));

							elemPair.Second = index;
						}

						values.Add(pair);

						index++;
					}

					ChartPanel.Draw(values);
				}

				GuiDispatcher.GlobalDispatcher.AddAction(() => CancelButton.Visibility = Visibility.Collapsed);
			}
			catch (Exception ex)
			{
				ex.LogError();
			}
		}