public GetIndex ( DateTime dateTime, SearchOption option = SearchOption.Prev ) : long | ||
dateTime | DateTime | |
option | SearchOption | |
return | long |
public virtual long GetIndex(DateTime dateTime, SearchOption option = SearchOption.Prev)
{
lock (Sync)
{
if (!this.readOpened)
OpenRead();
if (Count == 0)
{
Console.WriteLine($"DataSeries::GetIndex Error, data series has no elements {Name}");
return -1;
}
if (dateTime <= DateTime1)
return 0;
if (dateTime >= DateTime2)
return Count - 1;
var key = GetKey(dateTime, this.readKey, IndexOption.Null);
if (key == null)
return -1;
if (key != this.readKey)
{
if (!CacheObjects && this.readKey != null && this.readKey != this.writeKey &&
this.readKey != this.insertKey && this.readKey != this.deleteKey)
this.readKey.objects = null;
this.readKey = key;
}
return this.readKey.index1 + this.readKey.GetIndex(dateTime, option);
}
}
public TickSeries GetHistoricalTicks(TickType type, Instrument instrument, DateTime dateTime1, DateTime dateTime2) { DataSeries ds = null; switch (type) { case TickType.Bid: ds = GetDataSeries(instrument, DataObjectType.Bid, BarType.Time, 60); break; case TickType.Ask: ds = GetDataSeries(instrument, DataObjectType.Ask, BarType.Time, 60); break; case TickType.Trade: ds = GetDataSeries(instrument, DataObjectType.Trade, BarType.Time, 60); break; } var ts = new TickSeries(); if (ds != null && ds.Count != 0) { var index1 = ds.GetIndex(dateTime1, SearchOption.Next); var index2 = ds.GetIndex(dateTime2, SearchOption.Prev); for (long i = index1; i <= index2; i++) { var obj = ds[i]; switch (type) { case TickType.Bid: if (obj.TypeId == DataObjectType.Bid) { ts.Add((Bid)obj); } else { Console.WriteLine($"DataManager::GetHistoricalTicks Error, object type is not Bid {obj}"); } break; case TickType.Ask: if (obj.TypeId == DataObjectType.Ask) { ts.Add((Ask)obj); } else { Console.WriteLine($"DataManager::GetHistoricalTicks Error, object type is not Ask {obj}"); } break; case TickType.Trade: if (obj.TypeId == DataObjectType.Trade) { ts.Add((Trade)obj); } else { Console.WriteLine($"DataManager::GetHistoricalTicks Error, object type is not Trade {obj}"); } break; } } } return(ts); }