예제 #1
0
        public void Basics()
        {
            // reset count
            newtxt = 0;
            // track something
            GenericTracker <object> gt = new GenericTracker <object>();

            // count new items
            gt.NewTxt += new TextIdxDelegate(gt_NewTxt);
            // get some symbols
            string[] syms = new string[] { "IBM", "LVS", "IBM", "WAG", "GOOG" };
            // add them
            foreach (string sym in syms)
            {
                gt.addindex(sym, sym == "IBM" ? null : new object());
            }
            // ensure we have them
            Assert.AreEqual(4, newtxt);
            Assert.AreNotEqual(gt.Count, syms.Length);
            // test fetching by label
            Assert.IsNull(gt["IBM"]);
            Assert.IsNotNull(gt["GOOG"]);
            Assert.AreEqual(0, gt.getindex("IBM"));
            // get label from index
            Assert.AreEqual("GOOG", gt.getlabel(3));
        }
예제 #2
0
        static List <Token> getstublessfunction(int fidx, GenericTracker <List <Token> > stubs)
        {
            // get copy of the current stub
            var ftoks = new List <Token>(stubs[fidx]);
            // get this function's symbol
            var fsym = new string[] { stubs.getlabel(fidx) };
            // prepare a list of all symbols slurped into ftoken table
            var  syms = new List <string>(fsym);
            bool allsymbolsslurped = false;

            do
            {
                var lastsymcount = syms.Count;
                // look for all new symbols
                syms = getallsymbolspresent(ftoks.ToArray(), syms, stubs);
                // if found, slurp tokens and rerun until no new symbols' tokens are slurped
                for (int i = lastsymcount; i < syms.Count; i++)
                {
                    // get new symbol to slurp
                    var newfuncsym = syms[i];
                    // grab the tokens for this symbol
                    var newtoks = stubs[newfuncsym];
                    // slurp it into this function's implementation
                    ftoks.AddRange(newtoks);
                }
                // update continue state
                allsymbolsslurped = lastsymcount == syms.Count;
                // continue until all needed symbols are available in this substream
            } while (!allsymbolsslurped);
            return(ftoks);
        }
예제 #3
0
        static GenericTracker <List <Token> > getstublessftable(GenericTracker <List <Token> > function2functoks)
        {
            var tmp        = function2functoks.ToArray();
            var stubtokens = new GenericTracker <List <Token> >(tmp.Length);

            for (int i = 0; i < tmp.Length; i++)
            {
                stubtokens.addindex(function2functoks.getlabel(i), function2functoks[i]);
            }
            // now process every function stub
            for (int i = 0; i < function2functoks.Count; i++)
            {
                // always pass in the stubs
                var stubless = getstublessfunction(i, stubtokens);
                // update the primary list with the stubless result
                function2functoks[i] = stubless;
            }
            return(function2functoks);
        }
예제 #4
0
 public void Basics()
 {
     // reset count
     newtxt = 0;
     // track something
     GenericTracker<object> gt = new GenericTracker<object>();
     // count new items
     gt.NewTxt += new TextIdxDelegate(gt_NewTxt);
     // get some symbols
     string[] syms = new string[] { "IBM", "LVS", "IBM", "WAG", "GOOG" };
     // add them
     foreach (string sym in syms)
         gt.addindex(sym, sym == "IBM" ? null : new object());
     // ensure we have them
     Assert.AreEqual(4, newtxt);
     Assert.AreNotEqual(gt.Count, syms.Length);
     // test fetching by label
     Assert.IsNull(gt["IBM"]);
     Assert.IsNotNull(gt["GOOG"]);
     Assert.AreEqual(0, gt.getindex("IBM"));
     // get label from index
     Assert.AreEqual("GOOG", gt.getlabel(3));
 }
예제 #5
0
        public static bool PlayHistoricalTicks(Response r, GenericTracker<string> symbols, DateTime start, DateTime endexclusive, int expecteddays, DebugDelegate deb)
        {
            bool skipexpected = expecteddays == 0;
            // prepare to track actual days for each symbol
            GenericTracker<int> actualdays = new GenericTracker<int>();
            foreach (string sym in symbols)
                actualdays.addindex(sym, 0);
            // prepare to track all tickfiles
            Dictionary<string, List<string>> files = new Dictionary<string, List<string>>();
            // get all required tickfiles for each symbol on each date
            DateTime now = new DateTime(start.Ticks);
            int tfc = 0;
            while (now < endexclusive)
            {
                // get the tick files
                List<string> allfiles = TikUtil.GetFilesFromDate(Util.TLTickDir, Util.ToTLDate(now));
                // go through them all and see if we find expected number
                foreach (string fn in allfiles)
                {
                    // get security
                    SecurityImpl sec = SecurityImpl.FromTIK(fn);
                    // see if we want this symbol
                    int idx = symbols.getindex(sec.HistSource.RealSymbol);
                    if (idx < 0)
                        idx = symbols.getindex(sec.Symbol);
                    sec.HistSource.Close();
                    // skip if we don't
                    if (idx < 0)
                        continue;
                    string sym = symbols.getlabel(idx);
                    // if we have it, count actual day
                    actualdays[idx]++;
                    // save file and symbol
                    if (!files.ContainsKey(sym))
                        files.Add(sym, new List<string>());
                    files[sym].Add(fn);
                    // count files
                    tfc++;
                }
                // add one day
                now = now.AddDays(1);
            }
            // notify
            if (deb != null)
            {
                deb("found " + tfc + " tick files matching dates: " + Util.ToTLDate(start) + "->" + Util.ToTLDate(endexclusive) + " for: " + string.Join(",", symbols.ToArray()));
            }
            // playback when actual meets expected
            bool allok = true;
            foreach (string sym in symbols)
            {
                if (skipexpected || (actualdays[sym] >= expecteddays))
                {
                    // get tick files
                    string[] tf = files[sym].ToArray();
                    // notify
                    if (deb != null)
                    {
                        deb(sym + " playing back " + tf.Length + " tick files.");
                    }
                    // playback
                    HistSim h = new SingleSimImpl(tf);
                    h.GotTick += new TickDelegate(r.GotTick);
                    h.PlayTo(MultiSimImpl.ENDSIM);
                    h.Stop();
                    // notify
                    if (deb != null)
                    {
                        deb(sym + " completed playback. ");
                    }
                }
                else
                    allok = false;
            }


            return allok;

        }
예제 #6
0
        static unsafe void OnNxCoreTrade(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg)
        {
            if (keepcurrent && (STATUS < 4))
            {
                return;
            }
            if (DOLIVESKIPTEST)
            {
                if (pNxCoreSys->nxTime.MsOfDay < (DateTime.UtcNow.TimeOfDay.TotalMilliseconds - (DateTime.Now.IsDaylightSavingTime() ? (1000 * 60 * 60 * 4) : (1000 * 60 * 60 * 5))))
                {
                    return;
                }
                DOLIVESKIPTEST = false;
                D("NxCore starting realtime data");
            }
            // Get the symbol for category message

            int idx = _nxsyms.getindex(new string(&pNxCoreMsg->coreHeader.pnxStringSymbol->String));

            if (idx < 0)
            {
                return;
            }
            if (!_nxsyms[idx])
            {
                return;
            }
            // Assign a pointer to the Trade data
            NxCoreTrade *Trade = &pNxCoreMsg->coreData.Trade;
            // Get the price and net change
            double Price = NxCore.PriceToDouble(Trade->Price, Trade->PriceType);
            //double NetChange = NxCore.PriceToDouble(Trade->NetChange, Trade->PriceType);
            NxTime time   = pNxCoreMsg->coreHeader.nxExgTimestamp;
            int    tltime = time.Hour * 10000 + time.Minute * 100 + time.Second;
            NxDate date   = pNxCoreMsg->coreHeader.nxSessionDate;
            int    tldate = (int)date.Year * 10000 + (int)date.Month * 100 + (int)date.Day;
            string ex     = excode2name(pNxCoreMsg->coreHeader.ReportingExg);
            int    size   = (int)Trade->Size;

            // check for index
            if (size <= 0)
            {
                return;
            }
            Tick k = new TickImpl();

            k.symbol = _realsym2nxidx.getlabel(idx);
            k.date   = tldate;
            k.time   = tltime;
            k.trade  = (decimal)Price;
            k.ex     = ex;
            k.size   = size;
            try
            {
                tl.newTick(k);
            }
            catch (Exception e)
            {
                D("bad tick: " + k.symbol + " " + Price + " " + size + " " + ex + " " + e.Message + e.StackTrace);
            }
        }