Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// create fliptracker
 /// </summary>
 /// <param name="name"></param>
 /// <param name="estlabels"></param>
 public FlipTracker(string name, int estlabels)
     : base(name)
 {
     vcount  = new GenericTracker <int>(name);
     prev    = new GenericTracker <bool>(name);
     cur     = new GenericTracker <bool>(name);
     NewTxt += new TextIdxDelegate(FlipTracker_NewTxt);
 }
Ejemplo n.º 3
0
        public static bool PlayHistoricalTicks(Response r, GenericTracker <string> symbols, int currentdate, int daysback, int expecteddays, DebugDelegate deb)
        {
            // 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));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// provide the estimated # of symbols and the client to use
 /// </summary>
 /// <param name="tl"></param>
 /// <param name="estSymbols"></param>
 public SendorderTracker(TLClient tl, int estSymbols)
 {
     _tl                = tl;
     _estsymcount       = estSymbols;
     _ordersend.DoWork += new DoWorkEventHandler(_ordersend_DoWork);
     _loaded            = new GenericTracker <bool>(estSymbols);
     _loaded.NewTxt    += new TextIdxDelegate(_loaded_NewTxt);
     _resendq           = new RingBuffer <Order>(estSymbols);
     _orderq            = new RingBuffer <Order>(estSymbols);
     _retries           = new GenericTracker <int>(estSymbols * 10);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// flat a symbol and flag it to allow prevention of future trading with status and supplied reason
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="activesym"></param>
        /// <param name="_pt"></param>
        /// <param name="sendorder"></param>
        /// <param name="D"></param>
        /// <param name="reason"></param>
        public static void shutdown(string sym, GenericTracker <bool> activesym, PositionTracker _pt, OrderDelegate sendorder, DebugDelegate D, string reason)
        {
            if (!activesym[sym])
            {
                return;
            }
            Order o = new MarketOrderFlat(_pt[sym]);

            if (D != null)
            {
                string r = reason == string.Empty ? string.Empty : " (" + reason + ")";
                D("symbol shutdown" + r + ", flat order: " + o.ToString());
            }
            sendorder(o);
            activesym[sym] = false;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// create ticktracker with some approximate # of symbols to track
 /// </summary>
 /// <param name="estlabels"></param>
 public TickTracker(int estlabels)
 {
     _estlabels = estlabels;
     bid        = new GenericTracker <decimal>(_estlabels);
     ask        = new GenericTracker <decimal>(_estlabels);
     last       = new GenericTracker <decimal>(_estlabels);
     bs         = new GenericTracker <int>(_estlabels);
     be         = new GenericTracker <string>(_estlabels);
     oe         = new GenericTracker <string>(_estlabels);
     os         = new GenericTracker <int>(_estlabels);
     ts         = new GenericTracker <int>(_estlabels);
     ex         = new GenericTracker <string>(_estlabels);
     date       = new GenericTracker <int>(_estlabels);
     time       = new GenericTracker <int>(_estlabels);
     // setup generic trackers to track tick information
     last.NewTxt += new TextIdxDelegate(last_NewTxt);
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// flat a symbol and flag it to allow prevention of future trading with status
 /// </summary>
 /// <param name="sym"></param>
 /// <param name="activesym"></param>
 /// <param name="_pt"></param>
 /// <param name="sendorder"></param>
 /// <param name="D"></param>
 public static void shutdown(string sym, GenericTracker <bool> activesym, PositionTracker _pt, OrderDelegate sendorder, DebugDelegate D)
 {
     shutdown(sym, activesym, _pt, sendorder, D, string.Empty);
 }
 /// <summary>
 /// flat a symbol and flag it to allow prevention of future trading with status
 /// </summary>
 /// <param name="sym"></param>
 /// <param name="activesym"></param>
 /// <param name="_pt"></param>
 /// <param name="sendorder"></param>
 /// <param name="D"></param>
 public static void shutdown(string sym, GenericTracker <bool> activesym, PositionTracker _pt, OrderDelegate sendorder, DebugDelegate D)
 {
     //send_event(MimeType.shutdown, "foo", "boo".ToJson());
     shutdown(sym, activesym, _pt, sendorder, D, string.Empty);
 }