コード例 #1
0
        /// <summary>
        /// Gets the level1 quote from the current input lines.
        /// </summary>
        /// <param name="ticker">The ticker.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        private DataPoint GetLevel1Quote(string ticker, List <InputLine> data, DateTime date)
        {
            //Creaate new orderbook
            OrderBook orderbook = new OrderBook(ticker);

            //Get lines
            foreach (var line in data)
            {
                //Get data
                var    input = line.Line.Split(',');
                bool   isBid = input[1] == "b";
                double price = double.Parse(input[2], NumberStyles.Any, new CultureInfo("en-US"));
                double size  = double.Parse(input[3], NumberStyles.Any, new CultureInfo("en-US"));

                //Add to book
                orderbook.AddQuote(isBid, price, size);
            }

            //Return current quote
            return(new Tick(DataFeed.GetQuantlerTicker(ticker), DataFeed.DataSource)
            {
                AskSize = Convert.ToDecimal(orderbook.AskSize),
                AskPrice = Convert.ToDecimal(orderbook.BestAsk),
                BidPrice = Convert.ToDecimal(orderbook.BestBid),
                BidSize = Convert.ToDecimal(orderbook.BidSize),
                Depth = 0,
                Occured = date,
                TimeZone = TimeZone.Utc
            });
        }
コード例 #2
0
        /// <summary>
        /// Gets the data points.
        /// </summary>
        /// <param name="inputLine">The line.</param>
        /// <returns></returns>
        public override IEnumerable <DataPoint> GetDataPoints(InputLine inputLine)
        {
            //Get data in json format
            RootObject data = JSON.Deserialize <RootObject>(inputLine.Line, Jil.Options.ISO8601);

            //Go trough messages
            foreach (var message in data.Messages)
            {
                //Get current time
                if (!DateTime.TryParseExact(message.Timestamp[0], "yyyy-MM-dd HH:mm:ss.ffffff", null, DateTimeStyles.None,
                                            out DateTime utc))
                {
                    if (!DateTime.TryParse(message.Timestamp[0], out utc))
                    {
                        continue;
                    }
                }

                //Get bidprice and askprice
                decimal bidprice = message.BidPrice / 10000m;
                decimal askprice = message.AskPrice / 10000m;

                //Create tick
                DateTime nytime = utc.ConvertTo(TimeZone.Utc, TimeZone.NewYork);
                yield return(new Tick(DataFeed.GetQuantlerTicker(message.Symbol), DataSource.IEX)
                {
                    AskSize = message.AskSize,
                    AskPrice = askprice,
                    BidSize = message.BidSize,
                    BidPrice = bidprice,
                    Depth = 0,
                    Occured = nytime,
                    TimeZone = TimeZone.NewYork
                });
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the data points.
        /// </summary>
        /// <param name="inputLine">The line.</param>
        /// <returns></returns>
        public override IEnumerable <DataPoint> GetDataPoints(InputLine inputLine)
        {
            //Get input
            var data     = inputLine.Line.Split(',');
            var toreturn = new List <DataPoint>();

            try
            {
                //Check input
                if (data.Length < 4)
                {
                    throw new Exception("Missing data");
                }
                else if (Regex.Matches(data[0], @"[a-zA-Z]").Count > 0) //Header
                {
                    return(toreturn);
                }
                else if (data.Length > 4) //Trade data
                {
                    //Prob. trade data
                    DateTime occured = Time.FromUnixTime(long.Parse(data[3]), true);
                    toreturn.Add(new Tick(DataFeed.GetQuantlerTicker(data[2]), DataFeed.DataSource)
                    {
                        TradePrice = decimal.Parse(data[4], NumberStyles.Any, new CultureInfo("en-US")),
                        Size       = decimal.Parse(data[5], NumberStyles.Any, new CultureInfo("en-US")),
                        Occured    = occured,
                        TimeZone   = TimeZone.Utc
                    });
                    return(toreturn);
                }

                //Get data
                DateTime date   = Time.FromUnixTime(long.Parse(data[0]), true);
                string   ticker = inputLine.Filename.Split('_')[1];

                //Get Current Snapshot
                if (!_aggregatedLines.TryGetValue(ticker, out Snapshot snapshot))
                {
                    snapshot = new Snapshot(date);
                    _aggregatedLines.Add(ticker, snapshot);
                }

                //Check if this snapshot has ended
                if (snapshot.Date < date)
                {
                    //Return the level 1 quote
                    toreturn.Add(GetLevel1Quote(ticker, snapshot.InputLines, snapshot.Date));

                    //Remove the old lines from this snapshot and add the current new one
                    snapshot.Reset(date, inputLine);
                }
                else //Add to known lines
                {
                    snapshot.InputLines.Add(inputLine);
                }
            }
            catch
            {
                _log.Warn($"Cannot parse data from line as it is incorrect");
            }

            //Return what we have
            return(toreturn);
        }
コード例 #4
0
ファイル: HistoricalLocalFeed.cs プロジェクト: w1r2p1/Core-2
 /// <summary>
 /// Gets the name of the ticker at quantler.
 /// </summary>
 /// <param name="ticker">The ticker.</param>
 /// <returns></returns>
 public override TickerSymbol GetQuantlerTicker(string ticker) =>
 _baseDataFeed.GetQuantlerTicker(ticker);