Removed Active from StopLimits. The real solution is to have an additional key on the stop limits table in addition to Symbol..like Shares.
This commit is contained in:
@@ -28,7 +28,7 @@ namespace TradeBlotter.ViewModels
|
||||
base.DisplayName="TradeEntry";
|
||||
this.trade=trade;
|
||||
this.tradeRepository=tradeRepository;
|
||||
if(PortfolioDA.HasStopLimit(trade.Symbol)) stopLimit=PortfolioDA.GetStopLimit(trade.Symbol);
|
||||
if(StopLimitDA.HasStopLimit(trade.Symbol)) stopLimit=StopLimitDA.GetStopLimit(trade.Symbol);
|
||||
PropertyChanged+=OnTradeEntryViewModelPropertyChanged;
|
||||
UpdateProperties();
|
||||
}
|
||||
@@ -249,10 +249,10 @@ namespace TradeBlotter.ViewModels
|
||||
{
|
||||
stopLimit=new StopLimit();
|
||||
stopLimit.Symbol=trade.Symbol;
|
||||
stopLimit.Shares=trade.Shares;
|
||||
stopLimit.StopType=StopLimitConstants.STOP_QUOTE;
|
||||
}
|
||||
stopLimit.StopPrice=Utility.ParseCurrency(value);
|
||||
stopLimit.Active=1;
|
||||
}
|
||||
base.OnPropertyChanged("StopLimit");
|
||||
}
|
||||
@@ -347,21 +347,41 @@ namespace TradeBlotter.ViewModels
|
||||
base.OnPropertyChanged("TradeId");
|
||||
base.OnPropertyChanged("DisplayName");
|
||||
statusText = "Save completed.";
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
tradeRepository.UpdateTrade(trade);
|
||||
statusText="Update completed.";
|
||||
statusText = "Update completed.";
|
||||
}
|
||||
UpdateStopLimit();
|
||||
base.OnPropertyChanged("Status");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// There is a general problem with StopLimits at this level because the StopLimits table is keyed on Symbol
|
||||
/// What this means is that we cannot hold two positions for the same security with different stop limits.
|
||||
/// It also means that when we close one of two positions where one or both of those positions has a stop limit
|
||||
/// Then we are not quite sure which stop limit to update.
|
||||
/// The solution would be to key the StopLimit table on the trade.Id as thid would allow us to have a per position stop limit
|
||||
/// In the interim we do our best here to associate the trade with a given stop limit by matching it to the number of shares.
|
||||
/// </summary>
|
||||
private void UpdateStopLimit()
|
||||
{
|
||||
// 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);
|
||||
if(trade.IsClosed)
|
||||
{
|
||||
if(null!=stopLimit && stopLimit.Shares.Equals(trade.Shares))
|
||||
{
|
||||
StopLimitDA.DeleteStopLimit(trade.Symbol);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(null!=stopLimit)
|
||||
{
|
||||
StopLimitDA.InsertUpdateStopLimit(stopLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanSave
|
||||
{
|
||||
get
|
||||
|
||||
Reference in New Issue
Block a user