Пример #1
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);
        }
Пример #2
0
 /// <summary>
 /// gets entire sent order
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Order SentOrder(long id)
 {
     if (orders.getindex(id.ToString()) != GenericTracker.UNKNOWN)
     {
         return(orders[id.ToString()]);
     }
     else
     {
         return(new OrderImpl());
     }
 }
Пример #3
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);
        }
Пример #4
0
 /// <summary>
 /// get index of an existing symbol
 /// </summary>
 /// <param name="symbol"></param>
 /// <returns></returns>
 public int getindex(string symbol)
 {
     return(last.getindex(symbol));
 }
Пример #5
0
        void _ordersend_DoWork(object sender, DoWorkEventArgs e)
        {
            // process queue on seperate thread
            while (_processorderq)
            {
                // process not yet sent, add to resend
                while (_orderq.hasItems)
                {
                    _resendq.Write(_orderq.Read());
                }
                // prepare new resends
                List <Order> add2resend = new List <Order>(_estsymcount);
                // process resends
                while (_resendq.hasItems)
                {
                    Order o = _resendq.Read();
                    // if symbol is not loaded and subscribe is requested, wait
                    if (SubscribeBeforeSend && !_loaded[o.symbol])
                    {
                        Thread.Sleep(_SUBSCRIBEPAUSE);
                    }
                    // get retry index
                    int oidx = _retries.getindex(o.id.ToString());
                    // get maximum retry
                    int maxretry = MaxRetries == 0 ? int.MaxValue : MaxRetries;
                    int tries    = oidx < 0 ? 0 : _retries[oidx];
                    if (tries++ < maxretry)
                    {
                        // send
                        int err = sendordernow(o);
                        // if error, add to resend
                        if ((err != 0) && ResendOnError)
                        {
                            debug(o.symbol + " queing for resend " + o.id);
                            add2resend.Add(o);
                        }
                        else if ((err != 0) && ResendOnSelectError && SelectedErrors.Contains(err))
                        {
                            debug(o.symbol + " queing for resend " + o.id);
                            add2resend.Add(o);
                        }
                        else if (err != 0)
                        {
                            debug(o.symbol + " no re-send requested.");
                        }
                    }
                    if (oidx >= 0)
                    {
                        _retries[oidx] = tries;
                    }
                    if (_resendq.hasItems)
                    {
                        Thread.Sleep(_WAITITEM);
                    }
                }
                // add new resends
                foreach (Order o in add2resend)
                {
                    _resendq.Write(o);
                }

                Thread.Sleep(_SLEEP);
            }
        }
Пример #6
0
        /// <summary>
        /// whether full symbol is present
        /// </summary>
        /// <param name="sym"></param>
        /// <returns></returns>
        public bool isFullSymbolPresent(string sym)
        {
            var idx = longsym2secidx.getindex(sym);

            return(idx >= 0);
        }
Пример #7
0
        /// <summary>
        /// whether short symbol is present
        /// </summary>
        /// <param name="sym"></param>
        /// <returns></returns>
        public bool isSymbolPresent(string sym)
        {
            var idx = shortsym2secidx.getindex(sym);

            return(idx >= 0);
        }
Пример #8
0
 /// <summary>
 /// see if an order was pending
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool isPending(long id)
 {
     return(isPending(sent.getindex(id.ToString())));
 }