GetIndex() public méthode

public GetIndex ( DateTime dateTime, SearchOption option = SearchOption.Prev ) : long
dateTime DateTime
option SearchOption
Résultat long
Exemple #1
0
        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);
        }