Exemple #1
0
        public void UpdateStats(Trade trade, bool skipCollectionLoad = false)
        {
            var tradeEntry = Context.Entry(trade);

            if (!skipCollectionLoad &&                    //used to bypass annoyances w/ automated testing
                tradeEntry.State != EntityState.Added &&
                tradeEntry.State != EntityState.Detached) //trade entry state check, otherwise the load is meaningless and will cause a crash
            {
                tradeEntry.Collection(x => x.Orders).Load();
                tradeEntry.Collection(x => x.CashTransactions).Load();
                tradeEntry.Collection(x => x.FXTransactions).Load();
            }

            DateTime openDate = DetermineStartingDate(trade, Context);

            //Dates
            trade.DateOpened = openDate;
            if (trade.Open)
            {
                trade.DateClosed = null;
            }
            else
            {
                SetClosingDate(trade);
            }

            TradeTracker tracker = TradeSim.SimulateTrade(trade, Context, Datasourcer, _optionsCapitalUsageMultiplier);

            tracker.SetTradeStats(trade);
        }
Exemple #2
0
        public TradeViewModel(Trade trade, IDataSourcer dataSourcer, IDBContext context) : base(null)
        {
            context.Trades
            .Where(x => x.ID == trade.ID)
            .Include(x => x.Strategy)
            .Include(x => x.Orders)
            .Include("Orders.Instrument")
            .Include("Orders.Currency")
            .Include(x => x.CashTransactions)
            .Include("CashTransactions.Instrument")
            .Include("CashTransactions.Currency")
            .Include(x => x.FXTransactions)
            .Include("FXTransactions.FunctionalCurrency")
            .Include("FXTransactions.FXCurrency")
            .Load();

            Trade   = trade;
            Tracker = TradeSim.SimulateTrade(trade, context, dataSourcer, Properties.Settings.Default.optionsCapitalUsageMultiplier);
        }
Exemple #3
0
        /// <summary>
        /// Simulate the trade and update its stats. Does not save to db.
        /// </summary>
        /// <param name="trade"></param>
        /// <returns></returns>
        public async Task UpdateStats(Trade trade)
        {
            DateTime openDate = DetermineStartingDate(trade);

            //Dates
            trade.DateOpened = openDate;
            if (trade.Open)
            {
                trade.DateClosed = null;
            }
            else
            {
                SetClosingDate(trade);
            }

            TradeTracker tracker = await TradeSim.SimulateTrade(trade, _contextFactory, _dataSourcer, _settings.OptionsCapitalUsageMultiplier);

            tracker.SetTradeStats(trade);
        }