ssgonell wrote:
First, this returned null for series.
var series = DataManager.AddDataSeries(instrument, 0, BarType.Time, BarSize.Day);
0 is wrong value, it should be
DataObjectType.Bar for bars.
DataManager.AddDataSeries method is currently bugged and will be fixed in the next release.
You can work without handling DataSeries:
Code:
Instrument instrument = InstrumentManager["SPX"];
if (instrument == null)
{
instrument = new Instrument(InstrumentType.Index, "SPX", "Custom Daily", CurrencyId.USD);
InstrumentManager.Add(instrument);
}
var bar = new Bar(DateTime.Now, DateTime.Now.AddDays(1), instrument.Id, BarType.Time, BarSize.Day,
100, 102, 100, 101, 100500);
// add custom fields here
bar[101] = "some value";
bar[102] = 123;
Console.WriteLine($"Adding bar: {bar}");
DataManager.Save(instrument, bar, SaveMode.Add);
Additionally, do not use
Code:
DataManager.Save(instrument, series, SaveMode.Add);
in the current context(series), because it makes duplicates of the object in the series.