Update the app.config to point to Adrastea. Optimize the TradeBlotter ViewModels/BlotterViewModel, TradeEntryViewModel, TradeViewModel.cs
This commit is contained in:
@@ -19,6 +19,7 @@ using TradeBlotter.Cache;
|
||||
using System.Windows.Forms;
|
||||
using MarketData.MarketDataModel;
|
||||
using TradeBlotter.Model;
|
||||
using MarketData.Cache;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
@@ -113,6 +114,7 @@ namespace TradeBlotter.ViewModels
|
||||
List<BlotterTradeModel> repositoryTrades=tradeRepository.GetTrades();
|
||||
repositoryTrades=repositoryTrades.OrderByDescending(x=>x.TradeDate).ThenBy(x=>x.TradeId).ToList();
|
||||
List<TradeViewModel> all = (from trade in repositoryTrades select new TradeViewModel(trade, tradeRepository)).ToList();
|
||||
|
||||
double totalMarketValue = 0;
|
||||
foreach (TradeViewModel tradeViewModel in all)
|
||||
{
|
||||
@@ -266,9 +268,9 @@ namespace TradeBlotter.ViewModels
|
||||
Dispatcher uiDispatcher = Dispatcher.CurrentDispatcher; // get the UI dispatcher
|
||||
Task workerTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
GBPriceCache.GetInstance().Clear();
|
||||
foreach (TradeViewModel tvm in this.AllTrades)
|
||||
{
|
||||
tvm.UseCache=true; // switch to cache when refreshing
|
||||
tvm.Invalidate();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -249,10 +249,10 @@ namespace TradeBlotter.ViewModels
|
||||
{
|
||||
stopLimit=new StopLimit();
|
||||
stopLimit.Symbol=trade.Symbol;
|
||||
stopLimit.Active=1;
|
||||
stopLimit.StopType=StopLimitConstants.STOP_QUOTE;
|
||||
}
|
||||
stopLimit.StopPrice=Utility.ParseCurrency(value);
|
||||
stopLimit.Active=1;
|
||||
}
|
||||
base.OnPropertyChanged("StopLimit");
|
||||
}
|
||||
@@ -358,7 +358,8 @@ namespace TradeBlotter.ViewModels
|
||||
}
|
||||
private void UpdateStopLimit()
|
||||
{
|
||||
if(null==stopLimit&&PortfolioDA.HasStopLimit(trade.Symbol))PortfolioDA.DeleteStopLimit(trade.Symbol);
|
||||
// if(null==stopLimit && PortfolioDA.HasStopLimit(trade.Symbol))PortfolioDA.DeleteStopLimit(trade.Symbol);
|
||||
if(null==stopLimit)PortfolioDA.DeleteStopLimit(trade.Symbol);
|
||||
else if(null!=stopLimit)PortfolioDA.InsertUpdateStopLimit(stopLimit);
|
||||
}
|
||||
public bool CanSave
|
||||
|
||||
@@ -17,6 +17,7 @@ using TradeBlotter.DataAccess;
|
||||
using TradeBlotter.Command;
|
||||
using TradeBlotter.UIUtils;
|
||||
using TradeBlotter.Cache;
|
||||
using MarketData.Cache;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
@@ -32,14 +33,13 @@ namespace TradeBlotter.ViewModels
|
||||
|
||||
public TradeViewModel(BlotterTradeModel trade, TradeRepository tradeRepository)
|
||||
{
|
||||
UseCache=false;
|
||||
if (null == trade) throw new ArgumentNullException("trade");
|
||||
if (null == tradeRepository) throw new ArgumentNullException("tradeRepository");
|
||||
this.trade = trade;
|
||||
this.tradeRepository = tradeRepository;
|
||||
PropertyChanged += OnTradeViewModelPropertyChanged;
|
||||
}
|
||||
public bool UseCache{get;set;}
|
||||
|
||||
public override SaveParameters GetSaveParameters()
|
||||
{
|
||||
return null;
|
||||
@@ -98,7 +98,6 @@ namespace TradeBlotter.ViewModels
|
||||
}
|
||||
public String SellPrice
|
||||
{
|
||||
// get { return trade.IsClosed?Utility.FormatCurrency(trade.SellPrice):Constants.CONST_DASHES; }
|
||||
get { return trade.IsClosed?Utility.FormatPrice(trade.SellPrice):Constants.CONST_DASHES; }
|
||||
set { trade.SellPrice = double.Parse(value); base.OnPropertyChanged("SellPrice"); }
|
||||
}
|
||||
@@ -125,16 +124,17 @@ namespace TradeBlotter.ViewModels
|
||||
{
|
||||
get { return trade.IsOpen; }
|
||||
}
|
||||
|
||||
public void Invalidate()
|
||||
{
|
||||
Price price = null;
|
||||
if(UseCache)price=PriceCache.GetInstance().GetLatestPrice(trade.Symbol);
|
||||
if (null == price) price = PricingDA.GetPrice(trade.Symbol);
|
||||
price = GBPriceCache.GetInstance().GetPriceOrLatestAvailable(trade.Symbol,DateTime.Now);
|
||||
if (null == price) return;
|
||||
trade.LatestPrice = price.Close;
|
||||
trade.PriceDate = price.Date;
|
||||
trade.HasLatestPrice = true;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
base.OnPropertyChanged("GainLoss");
|
||||
@@ -148,7 +148,6 @@ namespace TradeBlotter.ViewModels
|
||||
get
|
||||
{
|
||||
return Utility.FormatPrice(trade.LatestPrice);
|
||||
// return Utility.FormatCurrency(trade.LatestPrice);
|
||||
}
|
||||
set { trade.LatestPrice = double.Parse(value); base.OnPropertyChanged("CurrentPrice"); }
|
||||
}
|
||||
@@ -248,14 +247,16 @@ namespace TradeBlotter.ViewModels
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!trade.HasLatestPrice)
|
||||
if (trade.IsClosed) return Constants.CONST_DASHES;
|
||||
if (!trade.HasLatestPrice)
|
||||
{
|
||||
Invalidate();
|
||||
base.OnPropertyChanged("PriceDate");
|
||||
base.OnPropertyChanged("CurrentPrice");
|
||||
}
|
||||
if (trade.IsClosed) return Constants.CONST_DASHES;
|
||||
return trade.HasLatestPrice?Utility.FormatCurrency(trade.Shares*trade.LatestPrice):"0.00";
|
||||
// if (trade.IsClosed) return Constants.CONST_DASHES;
|
||||
return trade.HasLatestPrice ? Utility.FormatCurrency(trade.Shares * trade.LatestPrice) : "0.00";
|
||||
// return Utility.FormatCurrency(trade.Shares*trade.LatestPrice);
|
||||
}
|
||||
}
|
||||
public String Weight
|
||||
@@ -266,7 +267,11 @@ namespace TradeBlotter.ViewModels
|
||||
}
|
||||
set
|
||||
{
|
||||
weight = Utility.ParsePercent(value);
|
||||
if(value.Equals("N/A") || value.Equals(Constants.CONST_DASHES))
|
||||
{
|
||||
weight = 0.00;
|
||||
}
|
||||
else weight = Utility.ParsePercent(value);
|
||||
}
|
||||
}
|
||||
public override string DisplayName
|
||||
|
||||
Reference in New Issue
Block a user