private void PopulateOutPositionReview(SqlDataReader reader, OutPosition w) { w.Id = (int)reader["ID"]; w.ShareId = (int)reader["ShareId"]; w.Size = (int)reader["Size"]; if (!reader.IsDBNull(reader.GetOrdinal("EntryPrice"))) { w.EntryPrice = reader.GetDouble(reader.GetOrdinal("EntryPrice")); } if (!reader.IsDBNull(reader.GetOrdinal("EntryFee"))) { w.EntryFee = reader.GetDouble(reader.GetOrdinal("EntryFee")); } if (!reader.IsDBNull(reader.GetOrdinal("EntryDate"))) { w.EntryDate = reader.GetInt32(reader.GetOrdinal("EntryDate")); } if (!reader.IsDBNull(reader.GetOrdinal("EntryTransactionId"))) { w.EntryTransactionId = reader.GetInt32(reader.GetOrdinal("EntryTransactionId")); } if (!reader.IsDBNull(reader.GetOrdinal("ExitPrice"))) { w.ExitPrice = reader.GetDouble(reader.GetOrdinal("ExitPrice")); } if (!reader.IsDBNull(reader.GetOrdinal("ExitFee"))) { w.ExitFee = reader.GetDouble(reader.GetOrdinal("ExitFee")); } if (!reader.IsDBNull(reader.GetOrdinal("ExitDate"))) { w.ExitDate = reader.GetInt32(reader.GetOrdinal("ExitDate")); } if (!reader.IsDBNull(reader.GetOrdinal("ExitTransactionId"))) { w.ExitTransactionId = reader.GetInt32(reader.GetOrdinal("ExitTransactionId")); } if (!reader.IsDBNull(reader.GetOrdinal("DaySpan"))) { w.Days = reader.GetInt32(reader.GetOrdinal("DaySpan")); } }
public void PopulateReview(TradeReview review) { TransactionBLL tBLL = new TransactionBLL(_unit); TradePositionBLL tpBll = new TradePositionBLL(_unit); IndicatorBLL iBll = new IndicatorBLL(_unit); TickerBLL tkBll = new TickerBLL(_unit); OutPosition pos = tpBll.GetOutPositionById(review.TradePositionId); Transaction entryTr = tBLL.GetByID(pos.EntryTransactionId); Entity.Indicator entryInd = iBll.GetIndicatorByShareDate(pos.ShareId, entryTr.TradingDate); Ticker entryT = tkBll.GetTickerByDate(pos.ShareId, entryTr.TradingDate); iBll.PopulateIndicatorWithTicker(entryInd, entryT); review.IsEntryLong = pos.Size > 0 ? true : false; if (entryInd.BB_Low.HasValue && entryInd.BB_High.HasValue) { review.BBEntryPercent = 100 * (entryTr.Price - entryInd.BB_Low.Value) / (entryInd.BB_High.Value - entryInd.BB_Low.Value); } review.EntryPercent = 100 * (entryTr.Price - entryInd.Low.Value) / (entryInd.High.Value - entryInd.Low.Value); if (pos.ExitTransactionId.HasValue) { Transaction exitTr = new TransactionBLL(_unit).GetByID(pos.ExitTransactionId.Value); Entity.Indicator exitInd = new IndicatorBLL(_unit).GetIndicatorByShareDate(pos.ShareId, exitTr.TradingDate); Ticker exitT = tkBll.GetTickerByDate(pos.ShareId, exitTr.TradingDate); iBll.PopulateIndicatorWithTicker(exitInd, exitT); if (exitInd.BB_Low.HasValue && exitInd.BB_High.HasValue) { review.BBExitPercent = 100 * (exitTr.Price - exitInd.BB_Low.Value) / (exitInd.BB_High.Value - exitInd.BB_Low.Value); } review.ExitPercent = 100 * (exitTr.Price - exitInd.Low.Value) / (exitInd.High.Value - exitInd.Low.Value); review.DaysSpan = pos.Days; review.Diff = pos.Diff; review.Diff_Per = pos.Diff_Per; } }
public List <OutPosition> GetPositionSummaryList(int accountId, int?size) { List <OutPosition> opList = new List <OutPosition>(); try { using (SqlConnection conn = new SqlConnection(_connectionString)) { using (SqlCommand cmd = new SqlCommand("USP_GetPositionListByAccount", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("AccountId", SqlDbType.Int).Value = accountId; if (size.HasValue) { cmd.Parameters.Add("Take", SqlDbType.Int).Value = size.Value; } cmd.Connection.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { OutPosition w; while (reader.Read()) { w = new OutPosition(); this.PopulateOutPositionReview(reader, w); opList.Add(w); } } } } } catch (Exception ex) { LogHelper.Error(_log, "Error read latest to DB. ", ex); throw; } return(opList); }
public OutPosition GetOutPositionById(int id) { OutPosition opResult = null; try { using (SqlConnection conn = new SqlConnection(_connectionString)) { using (SqlCommand cmd = new SqlCommand("USP_GetOutPositionById", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("Id", SqlDbType.Int).Value = id; cmd.Connection.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { OutPosition w; while (reader.Read()) { w = new OutPosition(); this.PopulateOutPositionReview(reader, w); opResult = w; } } } } } catch (Exception ex) { LogHelper.Error(_log, "Error read latest to DB. ", ex); throw; } return(opResult); }