Ejemplo n.º 1
0
        /// <summary>
        /// get the value of a single position
        /// </summary>
        /// <param name="position">position</param>
        /// <param name="quoteFeed">quote feed</param>
        /// <returns>value</returns>
        public static decimal PositionValue(Position position, IQuoteFeed quoteFeed)
        {
            Contract.Requires(position != null);
            Contract.Requires(quoteFeed != null);

            Quote lastQuote = quoteFeed.GetQuote(position.Symbol);

            return(lastQuote.Price * position.Quantity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// update the prices in the database
        /// </summary>
        /// <param name="database">database</param>
        /// <param name="quoteFeed">quote feed</param>
        private static void UpdatePrices(IDatabase database, IQuoteFeed quoteFeed)
        {
            List <string> symbols = database.GetSymbols();

            foreach (string symbol in symbols)
            {
                Quote quote = quoteFeed.GetQuote(symbol);
                database.SaveQuote(quote);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// get the value of an account
        /// </summary>
        /// <param name="account">account</param>
        /// <param name="quoteFeed">quote feed</param>
        /// <returns>value</returns>
        public static decimal AccountValue(Account account, IQuoteFeed quoteFeed)
        {
            Contract.Requires(account?.Positions != null);

            return(account.Positions.Values.Aggregate(0m, (total, position) => total + PositionValue(position, quoteFeed)));
        }