Пример #1
0
        /// <summary>
        /// To create candles from the tick trades collection.
        /// </summary>
        /// <typeparam name="TCandle">The candles type.</typeparam>
        /// <param name="trades">Tick trades.</param>
        /// <param name="arg">Candle arg.</param>
        /// <returns>Candles.</returns>
        public static IEnumerable <TCandle> ToCandles <TCandle>(this IEnumerableEx <Trade> trades, object arg)
            where TCandle : Candle
        {
            var firstTrade = trades.FirstOrDefault();

            if (firstTrade == null)
            {
                return(Enumerable.Empty <TCandle>());
            }

            return(trades.ToCandles(new CandleSeries(typeof(TCandle), firstTrade.Security, arg)).Cast <TCandle>());
        }
Пример #2
0
        /// <summary>
        /// Build market depths from order log.
        /// </summary>
        /// <param name="items">Orders log lines.</param>
        /// <param name="builder">Order log to market depth builder.</param>
        /// <param name="interval">The interval of the order book generation. The default is <see cref="TimeSpan.Zero"/>, which means order books generation at each new string of orders log.</param>
        /// <param name="maxDepth">The maximal depth of order book. The default is <see cref="Int32.MaxValue"/>, which means endless depth.</param>
        /// <returns>Market depths.</returns>
        public static IEnumerableEx <MarketDepth> ToMarketDepths(this IEnumerableEx <OrderLogItem> items, IOrderLogMarketDepthBuilder builder, TimeSpan interval = default(TimeSpan), int maxDepth = int.MaxValue)
        {
            var first = items.FirstOrDefault();

            if (first == null)
            {
                return(Enumerable.Empty <MarketDepth>().ToEx());
            }

            return(items.ToMessages <OrderLogItem, ExecutionMessage>()
                   .ToMarketDepths(builder, interval)
                   .ToEntities <QuoteChangeMessage, MarketDepth>(first.Order.Security));
        }
Пример #3
0
        /// <summary>
        /// To create ticks from candles.
        /// </summary>
        /// <param name="candles">Candles.</param>
        /// <returns>Trades.</returns>
        public static IEnumerableEx <Trade> ToTrades(this IEnumerableEx <Candle> candles)
        {
            var candle = candles.FirstOrDefault();

            if (candle == null)
            {
                return(Enumerable.Empty <Trade>().ToEx());
            }

            return(candles
                   .ToMessages <Candle, CandleMessage>()
                   .ToTrades(candle.Security.VolumeStep ?? 1m)
                   .ToEntities <ExecutionMessage, Trade>(candle.Security));
        }
Пример #4
0
        /// <summary>
        /// Построить тиковые сделки из лога заявок.
        /// </summary>
        /// <param name="items">Строчки лога заявок.</param>
        /// <returns>Тиковые сделки.</returns>
        public static IEnumerableEx <Trade> ToTrades(this IEnumerableEx <OrderLogItem> items)
        {
            var first = items.FirstOrDefault();

            if (first == null)
            {
                return(Enumerable.Empty <Trade>().ToEx(0));
            }

            var ticks = items
                        .Select(i => i.ToMessage())
                        .ToEx(items.Count)
                        .ToTicks();

            return(ticks.Select(m => m.ToTrade(first.Order.Security)).ToEx(ticks.Count));
        }