Example #1
0
        /// <inheritdoc />
        protected override HeikinAshiCandleMessage CreateCandle(ICandleBuilderSubscription subscription, ICandleBuilderValueTransform transform)
        {
            var timeFrame = subscription.Message.GetTimeFrame();

            var board  = subscription.Message.IsRegularTradingHours ? ExchangeInfoProvider.GetOrCreateBoard(subscription.Message.SecurityId.BoardCode) : ExchangeBoard.Associated;
            var bounds = timeFrame.GetCandleBounds(transform.Time, board, board.WorkingTime);

            if (transform.Time < bounds.Min)
            {
                return(null);
            }

            var openTime = bounds.Min;

            var candle = FirstInitCandle(subscription, new HeikinAshiCandleMessage
            {
                TimeFrame = timeFrame,
                OpenTime  = openTime,
                HighTime  = openTime,
                LowTime   = openTime,
                CloseTime = openTime,
            }, transform);

            var currentCandle = subscription.CurrentCandle;

            if (currentCandle != null)
            {
                candle.OpenPrice = (currentCandle.OpenPrice + currentCandle.ClosePrice) / 2M;
            }

            return(candle);
        }
Example #2
0
        /// <inheritdoc />
        protected override HeikinAshiCandleMessage CreateCandle(MarketDataMessage message, HeikinAshiCandleMessage currentCandle, ICandleBuilderValueTransform transform)
        {
            var timeFrame = message.GetTimeFrame();

            var board  = ExchangeInfoProvider.GetOrCreateBoard(message.SecurityId.BoardCode);
            var bounds = timeFrame.GetCandleBounds(transform.Time, board, board.WorkingTime);

            if (transform.Time < bounds.Min)
            {
                return(null);
            }

            var openTime = bounds.Min;

            var candle = FirstInitCandle(message, new HeikinAshiCandleMessage
            {
                TimeFrame = timeFrame,
                OpenTime  = openTime,
                HighTime  = openTime,
                LowTime   = openTime,
                CloseTime = openTime,
            }, transform);

            if (currentCandle != null)
            {
                candle.OpenPrice = (currentCandle.OpenPrice + currentCandle.ClosePrice) / 2M;
            }

            return(candle);
        }
Example #3
0
        /// <summary>
        /// To save the board.
        /// </summary>
        /// <param name="board">Board.</param>
        public static void SaveBoard(ExchangeBoard board)
        {
            if (board == null)
            {
                throw new ArgumentNullException(nameof(board));
            }

            ExchangeInfoProvider.Save(board);
        }
Example #4
0
        /// <summary>
        /// To get a board by its code. If board with the passed name does not exist, then it will be created.
        /// </summary>
        /// <param name="code">Board code.</param>
        /// <param name="createBoard">The handler creating a board, if it is not found. If the value is <see langword="null" />, then the board is created by default initialization.</param>
        /// <returns>Exchange board.</returns>
        public static ExchangeBoard GetOrCreateBoard(string code, Func <string, ExchangeBoard> createBoard = null)
        {
            if (code.IsEmpty())
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (code.CompareIgnoreCase("RTS"))
            {
                return(Forts);
            }

            var board = ExchangeInfoProvider.GetExchangeBoard(code);

            if (board != null)
            {
                return(board);
            }

            if (createBoard == null)
            {
                var exchange = ExchangeInfoProvider.GetExchange(code);

                if (exchange == null)
                {
                    exchange = new Exchange {
                        Name = code
                    };
                    ExchangeInfoProvider.Save(exchange);
                }

                board = new ExchangeBoard
                {
                    Code     = code,
                    Exchange = exchange
                };
            }
            else
            {
                board = createBoard(code);

                if (ExchangeInfoProvider.GetExchange(board.Exchange.Name) == null)
                {
                    ExchangeInfoProvider.Save(board.Exchange);
                }
            }

            SaveBoard(board);

            return(board);
        }
Example #5
0
        ///// <summary>
        ///// Все площадки.
        ///// </summary>
        //public static ExchangeBoard[] AllBoards
        //{
        //	get { return ExchangeInfoProvider.Boards; }
        //}

        /// <summary>
        /// To get a board by its code.
        /// </summary>
        /// <param name="code">Board code.</param>
        /// <returns>Found board. If board with the passed name does not exist, then <see langword="null" /> will be returned.</returns>
        public static ExchangeBoard GetBoard(string code)
        {
            return(code.CompareIgnoreCase("RTS") ? Forts : ExchangeInfoProvider.GetExchangeBoard(code));
        }
Example #6
0
        public Tuple <News, bool> ProcessNewsMessage(Security security, NewsMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var isNew = false;

            News news;

            if (!message.Id.IsEmpty())
            {
                news = _newsById.SafeAdd(message.Id, key =>
                {
                    isNew = true;
                    var n = EntityFactory.CreateNews();
                    n.Id  = key;
                    return(n);
                });
            }
            else
            {
                isNew = true;

                news = EntityFactory.CreateNews();
                _newsWithoutId.Add(news);
            }

            if (isNew)
            {
                news.ServerTime = message.ServerTime;
                news.LocalTime  = message.LocalTime;
            }

            if (!message.Source.IsEmpty())
            {
                news.Source = message.Source;
            }

            if (!message.Headline.IsEmpty())
            {
                news.Headline = message.Headline;
            }

            if (security != null)
            {
                news.Security = security;
            }

            if (!message.Story.IsEmpty())
            {
                news.Story = message.Story;
            }

            if (!message.BoardCode.IsEmpty())
            {
                news.Board = ExchangeInfoProvider.GetOrCreateBoard(message.BoardCode);
            }

            if (message.Url != null)
            {
                news.Url = message.Url;
            }

            message.CopyExtensionInfo(news);

            return(Tuple.Create(news, isNew));
        }
Example #7
0
        public static bool Update(ExchangeInfoEntity exchangeInfoEntity, DbTransaction trans = null)
        {
            var provider = new ExchangeInfoProvider();

            return(provider.Update(exchangeInfoEntity, trans));
        }
Example #8
0
        public static bool Save(System.String idx, System.String platformCode, System.String account, System.Guid managerId, System.Int32 zoneName, System.Int32 packId, System.Byte[] rowVersion, System.Int32 exchangeBatchLimitCode, ref System.Int32 returnCode, DbTransaction trans = null)
        {
            ExchangeInfoProvider provider = new ExchangeInfoProvider();

            return(provider.Save(idx, platformCode, account, managerId, zoneName, packId, rowVersion, exchangeBatchLimitCode, ref returnCode, trans));
        }
Example #9
0
        public static bool Delete(System.String idx, System.Byte[] rowVersion, DbTransaction trans = null)
        {
            ExchangeInfoProvider provider = new ExchangeInfoProvider();

            return(provider.Delete(idx, rowVersion, trans));
        }
Example #10
0
        public static List <ExchangeInfoEntity> GetAll()
        {
            var provider = new ExchangeInfoProvider();

            return(provider.GetAll());
        }
Example #11
0
        public static ExchangeInfoEntity GetById(System.String idx)
        {
            var provider = new ExchangeInfoProvider();

            return(provider.GetById(idx));
        }