private static DataTable addDataTableColumns(DataTable result) { Records.Datum.CE1 ce = new Records.Datum.CE1(); result.Columns.Add("CE" + "expiryDate"); result.Columns.Add("CE" + "underlying"); result.Columns.Add("CE" + "identifier"); result.Columns.Add("CE" + "pchangeinOpenInterest"); result.Columns.Add("CE" + "impliedVolatility"); result.Columns.Add("CE" + "totalBuyQuantity"); result.Columns.Add("CE" + "totalSellQuantity"); result.Columns.Add("CE" + "underlyingValue"); result.Columns.Add("CE" + "pChange"); result.Columns.Add("Contract"); result.Columns.Add("CE" + "openInterest"); result.Columns.Add("CE" + "changeinOpenInterest"); result.Columns.Add("CE" + "totalTradedVolume"); result.Columns.Add("CE" + "lastPrice"); result.Columns.Add("CE" + "change"); result.Columns.Add("CE" + "bidQty"); result.Columns.Add("CE" + "bidprice"); result.Columns.Add("CE" + "askPrice"); result.Columns.Add("CE" + "askQty"); result.Columns.Add("StrikePrice"); Records.Datum.PE1 pe = new Records.Datum.PE1(); //result.Columns.Add("strikePrice"); result.Columns.Add("PE" + "bidQty"); result.Columns.Add("PE" + "bidprice"); result.Columns.Add("PE" + "askPrice"); result.Columns.Add("PE" + "askQty"); result.Columns.Add("PE" + "change"); result.Columns.Add("PE" + "lastPrice"); result.Columns.Add("PE" + "totalTradedVolume"); result.Columns.Add("PE" + "changeinOpenInterest"); result.Columns.Add("PE" + "pchangeinOpenInterest"); result.Columns.Add("PE" + "pChange"); result.Columns.Add("ExpiryDate"); result.Columns.Add("PE" + "underlying"); result.Columns.Add("PE" + "identifier"); result.Columns.Add("PE" + "openInterest"); result.Columns.Add("PE" + "impliedVolatility"); result.Columns.Add("PE" + "totalBuyQuantity"); result.Columns.Add("PE" + "totalSellQuantity"); result.Columns.Add("PE" + "underlyingValue"); return(result); }
public static Records.Datum.PE1 GetPE(string ocType, string expiryDate, int strikePrice) { Records.Datum.PE1 result = null; Records recordsObject = GetOC(ocType); foreach (Records.Datum datum in recordsObject.data) { if (datum.expiryDate.Equals(expiryDate) && datum.strikePrice.Equals(strikePrice)) { if (datum.PE != null) { result = datum.PE; } } } return(result); }
private void GridviewDataBind(DataTable dataTable) { int avgOfSP = 0; foreach (DataRow row in dataTable.Rows) { if (row["Strike Price"] != null && row["Strike Price"].ToString().Trim().Length > 0) { avgOfSP += Convert.ToInt32(row["Strike Price"]); } } if (dataTable.Rows.Count > 0) { avgOfSP = avgOfSP / dataTable.Rows.Count; } int columnDiff = 0; if (rblOCType.SelectedValue.Equals(NIFTY)) { columnDiff = NIFTY_COL_DIFF; } if (rblOCType.SelectedValue.Equals(BANKNIFTY)) { columnDiff = BANKNIFTY_COL_DIFF; } //Assign header value to the center column dataTable.Columns[SELECTED_SP_COL_INDEX].ColumnName = avgOfSP.ToString(); for (int icount = SELECTED_SP_COL_INDEX - 1; icount >= LOWER_SP_COL_START_INDEX; icount--) { dataTable.Columns[icount].ColumnName = Math.Round(Convert.ToDouble(avgOfSP - (SELECTED_SP_COL_INDEX - icount) * columnDiff), 0).ToString(); } //Assign value to the right columns from the center for (int icount = SELECTED_SP_COL_INDEX + 1; icount <= HIGHER_SP_COL_END_INDEX; icount++) { dataTable.Columns[icount].ColumnName = Math.Round(Convert.ToDouble(avgOfSP + (icount - SELECTED_SP_COL_INDEX) * columnDiff), 0).ToString(); } int lotsSize = 0; if (rblOCType.SelectedValue.Equals(NIFTY)) { lotsSize = NIFTY_LOT_SIZE; } if (rblOCType.SelectedValue.Equals(BANKNIFTY)) { lotsSize = BANKNIFTY_LOT_SIZE; } foreach (DataRow row in dataTable.Rows) { //Get latest premium value from the OC if (row[CONTRACT_TYP_COL_INDEX].ToString().Equals(enumContractType.CE.ToString())) { Records.Datum.CE1 cE1 = OCHelper.GetCE(rblOCType.SelectedValue, row[EXP_DATE_COL_INDEX].ToString(), Convert.ToInt32(row[SP_COL_INDEX])); if (cE1 != null) { row[CMP_COL_INDEX] = cE1.lastPrice.ToString(); } else { row[CMP_COL_INDEX] = "0"; } } if (row[CONTRACT_TYP_COL_INDEX].ToString().Equals(enumContractType.PE.ToString())) { Records.Datum.PE1 pE1 = OCHelper.GetPE(rblOCType.SelectedValue, row[EXP_DATE_COL_INDEX].ToString(), Convert.ToInt32(row[SP_COL_INDEX])); if (pE1 != null) { row[CMP_COL_INDEX] = pE1.lastPrice.ToString(); } else { row[CMP_COL_INDEX] = "0"; } } for (int icount = LOWER_SP_COL_START_INDEX; icount <= HIGHER_SP_COL_END_INDEX; icount++) { row[icount] = Convert.ToString(Convert.ToInt32(row[LOTS_COL_INDEX]) * lotsSize * CalculateExpiryValue(row[CONTRACT_TYP_COL_INDEX].ToString(), row[TRANSTYP_COL_INDEX].ToString(), Convert.ToDouble(row[SP_COL_INDEX]), Convert.ToDouble(row[CMP_COL_INDEX]), Convert.ToDouble(dataTable.Columns[icount].ColumnName))); } } MySession.Current.StrategyBuilderDt = dataTable; gvStrategy.DataSource = dataTable; gvStrategy.DataBind(); }