Пример #1
0
 /// <summary>
 /// gets or sets the trail amount for a given symbol
 /// </summary>
 /// <param name="sym"></param>
 /// <returns></returns>
 public OffsetInfo this[string sym]
 {
     get
     {
         // get index
         int idx = symidx(sym);
         // if not there, get default
         if (idx == NOSYM)
         {
             return(_trailbydefault ? new OffsetInfo(_defaulttrail) : new OffsetInfo(0, 0));
         }
         // otherwise return whats there
         return(_trail[idx]);
     }
     set
     {
         // get index
         int idx = symidx(sym);
         // if not there, save this info
         if (idx == NOSYM)
         {
             _symidx.Add(sym, _trail.Count);
             _trail.Add(value);
             _ref.Add(0);
             firecount.addindex(sym, 0);
             esize.addindex(sym, pt[sym].UnsignedSize);
             _pendingfill.Add(false);
         }
         else // save it
         {
             _trail[idx] = value;
         }
         D("trail changed: " + sym + " " + value.ToString());
     }
 }
Пример #2
0
        public virtual void GotOrder(Order o)
        {
            if (o.id == 0)
            {
                debug(o.symbol + " can't track order with blank id!: " + o.ToString());
                return;
            }
            int idx = sent.getindex(o.id.ToString());

            if (idx < 0)
            {
                idx = orders.addindex(o.id.ToString(), o);
            }
            v(o.symbol + " order ack: " + o);
        }
Пример #3
0
        /// <summary>
        /// send order and track it
        /// </summary>
        /// <param name="o"></param>
        public void sendorder(Order o)
        {
            // ensure thread is running
            if (!_processorderq)
            {
                debug("Sendorder tracker has not been Started, orders will not be sent.");
            }
            //get index
            int idx = _loaded.getindex(o.symbol);

            if (idx == GenericTracker.UNKNOWN)
            {
                // add index
                _loaded.addindex(o.symbol, false);
                // first time for this symbol, subscribe
                if (SubscribeBeforeSend && subscribe(o.symbol))
                {
                    debug(o.symbol + " not subscribed, subscribing.");
                }
            }
            if (o.id == 0)
            {
                debug("No id, disabling max retry checking: " + o.ToString());
            }
            else
            {
                int oidx = _retries.addindex(o.id.ToString(), 0);
            }
            debug(o.symbol + " tracking order: " + o.ToString());
            // queoe order
            _orderq.Write(o);
        }
Пример #4
0
        /// <summary>
        /// takes all or part of quandl object and converts it into GT
        /// </summary>
        /// <param name="ro"></param>
        /// <param name="datecol"></param>
        /// <param name="valcol"></param>
        /// <param name="startrow"></param>
        /// <param name="endrow"></param>
        /// <returns></returns>
        public static GenericTracker <decimal> Qdl2GT(RootObject ro, string datecol, string valcol, int startrow, int endrow, DebugDelegate d)
        {
            // get columns
            var datecolidx = GetQdlColidx(ro, datecol);
            var valcolidx  = GetQdlColidx(ro, valcol);
            // slice out the data
            var subset = GetAllRows(ro, startrow, endrow, d);
            // get date column
            var dates = QdlCol2Dates(GetColumn(subset, datecolidx));
            var vals  = QdlCol2Vals(GetColumn(subset, valcolidx));
            // populate GT
            GenericTracker <decimal> gt = new GenericTracker <decimal>(dates.Count);

            for (int i = 0; i < dates.Count; i++)
            {
                var val = vals[i];
                var dt  = dates[i];
                if (val == qh.ERROR_VALUE)
                {
                    continue;
                }
                if (dt == qh.ERROR_DATE)
                {
                    continue;
                }
                var tldate = Util.ToTLDate(dt);
                gt.addindex(tldate.ToString("F0"), val);
            }
            return(gt);
        }
Пример #5
0
        public static bool PlayHistoricalTicks(Response r, string symbol, int currentdate, int daysback, int expecteddays, DebugDelegate deb)
        {
            GenericTracker <string> symbols = new GenericTracker <string>();

            symbols.addindex(symbol, symbol);
            // calculate stop date
            DateTime stop = Util.ToDateTime(currentdate, 0);
            // calculate start date
            DateTime start = stop.Subtract(new TimeSpan(daysback, 0, 0, 0));

            // return results
            return(PlayHistoricalTicks(r, symbols, start, stop, expecteddays, deb));
        }
Пример #6
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);
        }
Пример #7
0
 /// <summary>
 /// track a new symbol
 /// </summary>
 /// <param name="symbol"></param>
 /// <returns></returns>
 public int addindex(string symbol)
 {
     return(last.addindex(symbol, 0));
 }
Пример #8
0
        /// <summary>
        /// get or set current id by name.
        /// NOTE : generally you will want to call this with a symbol,
        /// EG idt["IBM","my entry market"]
        ///
        /// otherwise called like :
        /// (eg idt["myentrymkt"], idt["myentrylmt"], idt["myexitprofit"])
        /// Set name to zero to force reset on next use.
        /// </summary>
        /// <param name="idname"></param>
        /// <returns></returns>
        public override long this[string idname]
        {
            get
            {
                // see if we have this idname
                int idx = getindex(idname);

                // if we do, return the current numeric id
                if ((idx >= 0) && (base[idx] != 0))
                {
                    // test for max fire
                    if (idnamefires[idx] >= MaxNamedAssigns)
                    {
                        if (isMagicIdOnMaxName)
                        {
                            return(MagicId);
                        }
                        // otherwise return current id
                        return(base[idname]);
                    }
                    // otherwise reassign and fire
                    var newid = AssignId;
                    idnamefires[idx]++;
                    id2idname.addindex(newid.ToString(), idname);
                    base[idx] = newid;
                    debug("name: " + idname + " got new id: " + newid + " count: " + idnamefires[idx]);
                    return(newid);
                }
                else if ((idx >= 0) && (base[idx] == 0))
                {
                    // test for max fire
                    if (idnamefires[idx] >= MaxNamedAssigns)
                    {
                        if (isMagicIdOnMaxName)
                        {
                            return(MagicId);
                        }
                        // otherwise return current id
                        return(base[idname]);
                    }
                    var newid = AssignId;
                    base[idx] = newid;
                    id2idname.addindex(newid.ToString(), idname);
                    idnamefires[idx]++;
                    debug("name: " + idname + " was reset, assigning new id: " + newid + " count: " + idnamefires[idx]);
                    return(newid);
                }
                // if we don't, assign one... save and return it
                var newnameid = AssignId;
                idx = addindex(idname, newnameid);
                id2idname.addindex(newnameid.ToString(), idname);
                idnamefires.addindex(idname, 1);
                debug("name: " + idname + " never used, assigning new id: " + newnameid + " count: " + idnamefires[idx]);
                return(newnameid);
            }
            set
            {
                int idx = getindex(idname);
                if (idx < 0)
                {
                    addindex(idname, value);
                    id2idname.addindex(value.ToString(), idname);
                    idnamefires.addindex(idname, 0);
                    debug("idtracker idname: " + idname + " reset to: " + value);
                    return;
                }
                id2idname[idx]   = idname;
                idnamefires[idx] = 0;
                base[idx]        = value;
                debug("name: " + idname + " reset to: " + value);
            }
        }
Пример #9
0
 void FlipTracker_NewTxt(string txt, int idx)
 {
     prev.addindex(txt, false);
     cur.addindex(txt, false);
     vcount.addindex(txt, 0);
 }
Пример #10
0
 void RejectTracker_NewTxt(string txt, int idx)
 {
     ids.addindex(txt);
     times.addindex(txt);
     rejected.addindex(txt);
 }