StopLimitDA.cs Removed DeleteStopLimt(String symbol)

Added DeleteStopLimit(String symbol, double shares)
               Added GetStopLimits(String symbol)
               Obsoleted GetStopLimit(String symbol)

StopLimit.cs - Commented out references to EffectiveDate
This commit is contained in:
2026-02-05 13:32:00 -05:00
parent a885dfe42d
commit 523c2dfb21
2 changed files with 86 additions and 34 deletions

View File

@@ -2,6 +2,8 @@ using System.Text;
using MySql.Data.MySqlClient;
using MarketData.MarketDataModel;
using MarketData.Utils;
using System.Net;
using System.Security.Cryptography;
namespace MarketData.DataAccess
{
@@ -11,6 +13,83 @@ namespace MarketData.DataAccess
{
}
public static bool DeleteStopLimit(String symbol,double shares)
{
MySqlConnection sqlConnection = null;
MySqlCommand sqlCommand = null;
String strQuery = null;
try
{
StringBuilder sb = new StringBuilder();
if (null == symbol) return false;
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("portfolio_data"));
sb.Append("delete from stoplimits ");
sb.Append("where symbol='").Append(symbol).Append("'");
sb.Append(" ");
sb.Append("and shares=").Append(Utility.FormatNumber(shares,3));
strQuery = sb.ToString();
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
sqlCommand.ExecuteNonQuery();
return true;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, exception);
return false;
}
finally
{
if (null != sqlCommand) sqlCommand.Dispose();
if (null != sqlConnection) sqlConnection.Close();
}
}
public static StopLimits GetStopLimits(String symbol)
{
MySqlConnection sqlConnection = null;
MySqlDataReader sqlDataReader = null;
MySqlCommand sqlCommand = null;
String strQuery = null;
StopLimits stopLimits = new StopLimits();
try
{
StringBuilder sb = new StringBuilder();
if (null == symbol) return null;
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("portfolio_data"));
sb.Append("select symbol,stop_limit,shares,stop_type from stoplimits ");
sb.Append("where symbol='").Append(symbol).Append("'");
strQuery = sb.ToString();
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
StopLimit stopLimit = new StopLimit();
stopLimit.Symbol = sqlDataReader.GetString(0);
stopLimit.StopPrice = sqlDataReader.GetDouble(1);
stopLimit.Shares = sqlDataReader.GetDouble(2);
stopLimit.StopType = sqlDataReader.GetString(3);
stopLimits.Add(stopLimit);
}
return stopLimits;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, exception);
return stopLimits;
}
finally
{
if (null != sqlCommand) sqlCommand.Dispose();
if (null != sqlDataReader) { sqlDataReader.Close(); sqlDataReader.Dispose(); }
if (null != sqlConnection) sqlConnection.Close();
}
}
[Obsolete("This method is obsolete. Use GetSopLimits(String symbol) instead.", false)]
public static StopLimit GetStopLimit(String symbol)
{
MySqlConnection sqlConnection = null;
@@ -49,12 +128,14 @@ namespace MarketData.DataAccess
if (null != sqlConnection) sqlConnection.Close();
}
}
public static bool InsertUpdateStopLimit(StopLimit stopLimit)
{
if (null == stopLimit || null == stopLimit.Symbol || double.IsNaN(stopLimit.StopPrice)) return false;
if (!HasStopLimit(stopLimit.Symbol)) return InsertStopLimit(stopLimit);
return UpdateStopLimit(stopLimit);
}
private static bool InsertStopLimit(StopLimit stopLimit)
{
MySqlConnection sqlConnection = null;
@@ -93,6 +174,7 @@ namespace MarketData.DataAccess
if (null != sqlConnection) sqlConnection.Close();
}
}
private static bool UpdateStopLimit(StopLimit stopLimit)
{
MySqlConnection sqlConnection = null;
@@ -207,35 +289,5 @@ namespace MarketData.DataAccess
if (null != sqlConnection) sqlConnection.Close();
}
}
public static bool DeleteStopLimit(String symbol)
{
MySqlConnection sqlConnection = null;
MySqlCommand sqlCommand = null;
String strQuery = null;
try
{
StringBuilder sb = new StringBuilder();
if (null == symbol) return false;
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("portfolio_data"));
sb.Append("delete from stoplimits ");
sb.Append("where symbol='").Append(symbol).Append("'");
strQuery = sb.ToString();
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
sqlCommand.ExecuteNonQuery();
return true;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, exception);
return false;
}
finally
{
if (null != sqlCommand) sqlCommand.Dispose();
if (null != sqlConnection) sqlConnection.Close();
}
}
}
}

View File

@@ -57,7 +57,7 @@ namespace MarketData.MarketDataModel
public double StopPrice{get;set;}
public double Shares{get;set;}
public String StopType{get;set;}
public DateTime EffectiveDate{get;set;} // if the EffectiveDate is Epoch then the StopLimit is taken to be in effect and is the most recent. Otherwise it is considered an historical stop limit
// public DateTime EffectiveDate{get;set;} // if the EffectiveDate is Epoch then the StopLimit is taken to be in effect and is the most recent. Otherwise it is considered an historical stop limit
public StopLimit()
{
@@ -70,7 +70,7 @@ namespace MarketData.MarketDataModel
sb.Append(Utility.FormatCurrency(StopPrice)).Append(",");
sb.Append(Utility.FormatNumber(Shares, 3)).Append(",");
sb.Append(StopType).Append(",");
sb.Append(EffectiveDate.ToShortDateString());
// sb.Append(EffectiveDate.ToShortDateString());
return sb.ToString();
}
@@ -81,7 +81,7 @@ namespace MarketData.MarketDataModel
nvpCollection.Add(new NVP("StopPrice", StopPrice.ToString()));
nvpCollection.Add(new NVP("Shares", Shares.ToString()));
nvpCollection.Add(new NVP("StopType", StopType.ToString()));
nvpCollection.Add(new NVP("EffectiveDate", EffectiveDate.ToShortDateString()));
// nvpCollection.Add(new NVP("EffectiveDate", EffectiveDate.ToShortDateString()));
return nvpCollection;
}
@@ -94,7 +94,7 @@ namespace MarketData.MarketDataModel
stopLimit.StopPrice=nvpDictionary["StopPrice"].Get<double>();
stopLimit.Shares=nvpDictionary["Shares"].Get<double>();
stopLimit.StopType=nvpDictionary["StopType"].Get<String>();
stopLimit.EffectiveDate=nvpDictionary["EffectiveDate"].Get<DateTime>();
// stopLimit.EffectiveDate=nvpDictionary["EffectiveDate"].Get<DateTime>();
return stopLimit;
}
}