Example #1
0
        public static unsafe int GetQuotesEx(string ticker, Periodicity periodicity, int lastValid, int size, Quotation* quotes, GQEContext* context)
        {
            // TODO: Add logic here. Take a look at the demo below:

            Debug.WriteLine("GetQuotesEx(ticker: " + ticker + ", periodicity: " + periodicity + ", lastValid: " + lastValid + ", size: " + size + ", ...)");

            /*for (var i = 0; i < 5; i++)
            {
                quotes[i].DateTime = new AmiDate(DateTime.Now.AddDays(i - 5));
                quotes[i].Price = 10;
                quotes[i].Open = 15;
                quotes[i].High = 16;
                quotes[i].Low = 9;
                quotes[i].Volume = 1000;
                quotes[i].OpenInterest = 0;
                quotes[i].AuxData1 = 0;
                quotes[i].AuxData2 = 0;
            }

            return 5;*/

            // return 'lastValid + 1' if no updates are found and you want to keep all existing records
            return lastValid + 1;
        }
Example #2
0
        public static unsafe int GetQuotesEx(string ticker, Periodicity periodicity, int lastValid, int size, Quotation* quotes, GQEContext* context)
        {
            Debug.WriteLine("GetQuotesEx(ticker: " + ticker + ", periodicity: " + periodicity + ", lastValid: " + lastValid + ", size: " + size + ", ...)");

            var existingQuotes = new Quotation[0];

            if (lastValid > 2)
            {
                Array.Resize<Quotation>(ref existingQuotes, lastValid + 1);

                for (var i = 0; i <= lastValid; i++)
                {
                    existingQuotes[i] = new Quotation
                    {
                        DateTime = quotes[i].DateTime,
                        Open = quotes[i].Open,
                        High = quotes[i].High,
                        Low = quotes[i].Low,
                        Price = quotes[i].Price,
                        Volume = quotes[i].Volume,
                        OpenInterest = quotes[i].OpenInterest,
                        AuxData1 = quotes[i].AuxData1,
                        AuxData2 = quotes[i].AuxData2
                    };
                }

                Array.Sort<Quotation>(existingQuotes, new Comparison<Quotation>((q1, q2) => q1.DateTime.CompareTo(q2.DateTime)));
            }

            var newQuotes = DataSource.GetQuotes(ticker, periodicity, size, existingQuotes);

            if (newQuotes.Any())
            {
                lastValid = 0;
                for (var i = 0; i < newQuotes.Length; i++)
                {
                    quotes[i].DateTime = newQuotes[i].DateTime;
                    quotes[i].Price = newQuotes[i].Price;
                    quotes[i].Open = newQuotes[i].Open;
                    quotes[i].High = newQuotes[i].High;
                    quotes[i].Low = newQuotes[i].Low;
                    quotes[i].Volume = newQuotes[i].Volume;
                    quotes[i].OpenInterest = newQuotes[i].OpenInterest;
                    quotes[i].AuxData1 = newQuotes[i].AuxData1;
                    quotes[i].AuxData2 = newQuotes[i].AuxData2;
                    lastValid++;
                }

                return lastValid;
            }

            // return 'lastValid + 1' if no updates are found and you want to keep all existing records
            return lastValid + 1;
        }