Example #1
0
        /// <summary>
        /// The update trade filled trading histories.
        /// </summary>
        /// <param name="order">
        /// The order.
        /// </param>
        /// <param name="tradingFillsHistory">
        /// The trading fills history.
        /// </param>
        /// <param name="backwardWindow">
        /// The backward window.
        /// </param>
        /// <param name="forwardWindow">
        /// The forward window.
        /// </param>
        /// <returns>
        /// The <see cref="ITradingHistoryStack"/>.
        /// </returns>
        private ITradingHistoryStack UpdateTradeFilledTradingHistories(
            Order order,
            ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack> tradingFillsHistory,
            TimeSpan backwardWindow,
            TimeSpan?forwardWindow)
        {
            if (!tradingFillsHistory.ContainsKey(order.Instrument.Identifiers))
            {
                // ReSharper disable once PossibleInvalidOperationException
                ITradingHistoryStack history          = new TradingHistoryStack(backwardWindow, i => i.FilledDate.Value, this.tradingStackLogger);
                ITradingHistoryStack historyDecorator = new TradingHistoryDelayedDecorator(history, forwardWindow.GetValueOrDefault());
                var stack =
                    forwardWindow != null
                        ? historyDecorator
                        : history;

                // ReSharper disable once PossibleInvalidOperationException
                stack.Add(order, order.FilledDate.Value);
                tradingFillsHistory.TryAdd(order.Instrument.Identifiers, stack);
            }
            else
            {
                tradingFillsHistory.TryGetValue(order.Instrument.Identifiers, out var history);
                // ReSharper disable once PossibleInvalidOperationException
                history?.Add(order, order.FilledDate.Value);
                history?.ArchiveExpiredActiveItems(order.FilledDate.Value);
            }

            tradingFillsHistory.TryGetValue(order.Instrument.Identifiers, out var updatedHistory);

            return(updatedHistory);
        }
Example #2
0
        /// <summary>
        /// The update trade latest trading histories.
        /// </summary>
        /// <param name="order">
        /// The order.
        /// </param>
        /// <param name="tradingHistory">
        /// The trading history.
        /// </param>
        /// <param name="backwardWindowSize">
        /// The backward window size.
        /// </param>
        /// <param name="forwardWindowSize">
        /// The forward window size.
        /// </param>
        /// <returns>
        /// The <see cref="ITradingHistoryStack"/>.
        /// </returns>
        private ITradingHistoryStack UpdateTradeLatestTradingHistories(
            Order order,
            ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack> tradingHistory,
            TimeSpan backwardWindowSize,
            TimeSpan?forwardWindowSize)
        {
            if (!tradingHistory.ContainsKey(order.Instrument.Identifiers))
            {
                ITradingHistoryStack history          = new TradingHistoryStack(backwardWindowSize, i => i.MostRecentDateEvent(), this.tradingStackLogger);
                ITradingHistoryStack historyDecorator = new TradingHistoryDelayedDecorator(history, forwardWindowSize.GetValueOrDefault());
                var stack =
                    forwardWindowSize != null
                    ? historyDecorator
                    : history;

                stack.Add(order, order.MostRecentDateEvent());
                tradingHistory.TryAdd(order.Instrument.Identifiers, stack);
            }
            else
            {
                tradingHistory.TryGetValue(order.Instrument.Identifiers, out var history);
                history?.Add(order, order.MostRecentDateEvent());
                history?.ArchiveExpiredActiveItems(order.MostRecentDateEvent());
            }

            tradingHistory.TryGetValue(order.Instrument.Identifiers, out var updatedHistory);

            return(updatedHistory);
        }