-
Hi everyone,
CSV file is quoted below: Brokerage Run Date,Action,Symbol,Security Description,Security Type,Quantity,Price ( "The data and information in this spreadsheet is provided to you solely for your use and is not for distribution. The spreadsheet is provided for" Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If all the files you receive are standard like this, meaning it starts with a header row first column of void Main()
{
var s = @"
Brokerage
Run Date,Action,Symbol,Security Description,Security Type,Quantity,Price ($),Commission ($),Fees ($),Accrued Interest ($),Amount ($),Settlement Date
03/31/2020, REINVESTMENT FIDELITY GOVERNMENT MONEY MARKET (SPAXX) (Cash), SPAXX, FIDELITY GOVERNMENT MONEY MARKET,Cash,6.05,1,,,,-6.05,
03/31/2020, DIVIDEND RECEIVED FIDELITY GOVERNMENT MONEY MARKET (SPAXX) (Cash), SPAXX, FIDELITY GOVERNMENT MONEY MARKET,Cash,,,,,,6.05,
03/25/2020, DIVIDEND RECEIVED FIDELITY MSCI FINLS INDEX ETF (FNCL) (Margin), FNCL, FIDELITY MSCI FINLS INDEX ETF,Margin,,,,,,20.3,
03/25/2020, DIVIDEND RECEIVED FIDELITY MSCI CONSUMER STAPLES INDEX ET (FSTA) (Margin), FSTA, FIDELITY MSCI CONSUMER STAPLES INDEX ETF,Margin,,,,,,19.1,
03/06/2020, REINVESTMENT FIDELITY REAL ESTATE INCOME (FRIFX) (Margin), FRIFX, FIDELITY REAL ESTATE INCOME,Margin,0.171,12.46,,,,-2.13,
03/06/2020, DIVIDEND RECEIVED FIDELITY REAL ESTATE INCOME (FRIFX) (Margin), FRIFX, FIDELITY REAL ESTATE INCOME,Margin,,,,,,2.13,
02/28/2020, REINVESTMENT FIDELITY GOVERNMENT MONEY MARKET (SPAXX) (Cash), SPAXX, FIDELITY GOVERNMENT MONEY MARKET,Cash,11.84,1,,,,-11.84,
""The data and information in this spreadsheet is provided to you solely for your use and is not for distribution.The spreadsheet is provided for""
""informational purposes only, and is not intended to provide advice, nor should it be construed as an offer to sell, a solicitation of an offer to buy or a""
Thank you!
";
var records = new List<FidelityRecord>();
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
IgnoreBlankLines = false,
};
using (var reader = new StringReader(s.ToString()))
using (var csv = new CsvReader(reader, config))
{
csv.Context.RegisterClassMap<FidelityCSVMap>();
while (csv.Read())
{
if (csv[0] == "Run Date")
{
break;
}
}
csv.ReadHeader();
while (csv.Read())
{
if (string.IsNullOrEmpty(csv[0]))
{
break;
}
records.Add(csv.GetRecord<FidelityRecord>());
}
}
records.Dump();
}
class FidelityRecord
{
public DateTime RunDate { get; set; }
public string Action { get; set; }
public string Symbol { get; set; }
public Single? Quantity { get; set; }
public Single? Price { get; set; }
public Single? Amount { get; set; }
}
sealed class FidelityCSVMap : ClassMap<FidelityRecord>
{
FidelityCSVMap()
{
Map(m => m.RunDate).Name("Run Date", "RunDate");
Map(m => m.Action).Name("Action", "Action");
Map(m => m.Symbol).Name("Symbol", "Symbol");
Map(m => m.Quantity).Name("Quantity", "Quantity");
Map(m => m.Price).Name("Price ($)", "Price");
Map(m => m.Amount).Name("Amount ($)", "Amount");
}
} I'm using LINQPad which is where the |
Beta Was this translation helpful? Give feedback.
If all the files you receive are standard like this, meaning it starts with a header row first column of
Run Date
and is done when a blank row is found, you can do this.