public static List<OrderQueryEntity> GetOrderByInstrument(string exchangeCode,Guid userId, Guid instrumentId, Guid accountGroupId, OrderType orderType, bool isExecute, DateTime fromDate, DateTime toDate) { List<OrderQueryEntity> queryOrders = new List<OrderQueryEntity>(); string sql = string.Empty; using (SqlConnection sqlConnection = DataAccess.GetInstance(exchangeCode).GetSqlConnection()) { SqlCommand command = sqlConnection.CreateCommand(); command.CommandText = isExecute ? "dbo.P_GetExecutedOrderByInstrument" : "dbo.P_GetCancelledOrderByInstrument"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@UserID", userId)); command.Parameters.Add(new SqlParameter("@InstrumentID", instrumentId)); command.Parameters.Add(new SqlParameter("@OrderType", (byte)orderType)); command.Parameters.Add(new SqlParameter("@FromDate", fromDate)); command.Parameters.Add(new SqlParameter("@ToDate", toDate)); command.Parameters.Add(new SqlParameter("@AccountGroupId", accountGroupId)); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { OrderQueryEntity order = new OrderQueryEntity(); order.InstrumentCode = (string)reader["InstrumentCode"]; order.BuySell = (bool)reader["IsBuy"]; order.OpenClose = (string)reader["OpenClose"]; order.Lot = (decimal)reader["Lot"]; order.OrderCode = (string)reader["OrderCode"]; order.AccountCode = (string)reader["AccountCode"]; order.SetPrice = (string)reader["ExecutePrice"]; order.OrderType = reader["OrderType"].ConvertToEnumValue<OrderType>(); order.ExecuteTime = (DateTime)reader["ExecuteTime"]; order.Relation = (string)reader["Relation"]; order.Dealer = (Guid)reader["approverID"]; queryOrders.Add(order); } } } return queryOrders; }
public static List<OrderQueryEntity> GetOrderByInstrument(string exchangeCode, HashSet<Guid> accounts, HashSet<Guid> instruments, Guid instrumentId, Guid accountGroupId, OrderType orderType, bool isExecute, DateTime fromDate, DateTime toDate) { List<OrderQueryEntity> queryOrders = new List<OrderQueryEntity>(); string sql = string.Empty; try { string instrumentXmlString = GetInstrumentPermisstionString(instruments); string accountXmlString = GetAccountPermisstionString(accounts); using (SqlConnection sqlConnection = DataAccess.GetInstance(exchangeCode).GetSqlConnection()) { SqlCommand command = sqlConnection.CreateCommand(); command.CommandText = isExecute ? "dbo.P_GetExecutedOrder" : "dbo.P_GetCancelledOrder"; command.CommandType = CommandType.StoredProcedure; SqlParameter parameter = new SqlParameter("@accountsXml", SqlDbType.NText); parameter.Value = accountXmlString; command.Parameters.Add(parameter); parameter = new SqlParameter("@instrumentsXml", SqlDbType.NText); parameter.Value = instrumentXmlString; command.Parameters.Add(parameter); parameter = new SqlParameter("@InstrumentID", SqlDbType.UniqueIdentifier); parameter.Value = instrumentId; command.Parameters.Add(parameter); parameter = new SqlParameter("@OrderType", SqlDbType.Int); parameter.Value = (byte)orderType; command.Parameters.Add(parameter); parameter = new SqlParameter("@FromDate", SqlDbType.DateTime); parameter.Value = fromDate; command.Parameters.Add(parameter); parameter = new SqlParameter("@ToDate", SqlDbType.DateTime); parameter.Value = toDate; command.Parameters.Add(parameter); parameter = new SqlParameter("@AccountGroupId", SqlDbType.UniqueIdentifier); parameter.Value = accountGroupId; command.Parameters.Add(parameter); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { OrderQueryEntity order = new OrderQueryEntity(); order.InstrumentCode = (string)reader["InstrumentCode"]; order.BuySell = (bool)reader["IsBuy"]; order.OpenClose = (string)reader["OpenClose"]; order.Lot = (decimal)reader["Lot"]; order.OrderCode = (string)reader["OrderCode"]; order.AccountCode = (string)reader["AccountCode"]; order.SetPrice = (string)reader["ExecutePrice"]; order.OrderType = reader["OrderType"].ConvertToEnumValue<OrderType>(); if (isExecute) { order.ExecuteTime = (DateTime)reader["ExecuteTime"]; } order.Relation = (string)reader["Relation"]; //order.Dealer = (Guid)reader["approverID"] ==; order.ExchangeCode = exchangeCode; queryOrders.Add(order); } } } } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "ExchangeData.GetOrderByInstrument Error\r\n{0}", ex.ToString()); } return queryOrders; }