Update the app.config to point to Adrastea. Optimize the TradeBlotter ViewModels/BlotterViewModel, TradeEntryViewModel, TradeViewModel.cs
This commit is contained in:
@@ -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