예제 #1
0
 void symindex()
 {
     for (int i = 0; i < qt.Rows.Count; i++)
     {
         if (qt.Rows[i].RowState == DataRowState.Deleted)
         {
             continue;
         }
         Security sec = SecurityImpl.Parse(qt.Rows[i]["Symbol"].ToString());
         string   sym = sec.Symbol;
         if (!symidx.ContainsKey(sec.FullName)) // if we've not seen this symbol add it's index
         {
             symidx.Add(sec.FullName, new int[] { i });
         }
         else
         {
             // otherwise create a new array with an extra spot
             int[] newidx = new int[symidx[sec.FullName].Length + 1];
             // copy the old indicies in
             symidx[sec.FullName].CopyTo(newidx, 0);
             // save this latest index
             newidx[symidx[sec.FullName].Length] = i;
             // replace the old with the new
             symidx[sec.FullName] = newidx;
         }
     }
 }
예제 #2
0
 void tl_gotTick(Tick t)
 {
     try
     {
         _tlt.newTick(t);
         _kt.newTick(t);
         if (spillTick != null)
         {
             spillTick(t);
         }
         RefreshRow(t);
         BarList bl = null;
         if (bardict.TryGetValue(t.symbol, out bl))
         {
             if (SecurityImpl.Parse(t.symbol).Type == SecurityType.CASH)
             {
                 Tick    k = _kt[t.symbol];
                 decimal p = usebidonfx ? k.bid : k.ask;
                 int     s = usebidonfx ? k.bs : k.os;
                 bardict[t.symbol].newPoint(t.symbol, p, k.time, k.date, s);
             }
             else
             {
                 bardict[t.symbol].newTick(t);
             }
         }
     }
     catch (System.Threading.ThreadInterruptedException) { }
 }
예제 #3
0
        bool addsymbol(string sym, bool dosubscribe)
        {
            Security sec = SecurityImpl.Parse(sym);

            try
            {
                // SYM,LAST,TSIZE,BID,ASK,BSIZE,ASIZE,SIZES,OHLC(YEST),CHANGE
                DataRow r = qt.Rows.Add(sym, "", "", "", "", "", "", "", "", "", "", "");
                qt.Rows[qt.Rows.Count - 1][AVGPRICE] = pt[sym].AvgPrice;
                qt.Rows[qt.Rows.Count - 1][POSSIZE]  = pt[sym].Size;
                qt.Rows[qt.Rows.Count - 1][CLOSEDPL] = pt[sym].ClosedPL;
            }
            catch { }

            if (!bardict.ContainsKey(sec.FullName))
            {
                bardict.Add(sec.FullName, new BarListImpl(sym));
            }
            status("Added " + sym);
            if (!hassym(sym))
            {
                mb.Add(sym);
            }
            symindex();
            if (dosubscribe)
            {
                return(subscribe());
            }
            return(true);
        }
예제 #4
0
        public void Parsing()
        {
            // tests to parse and generate user-supplied security specifiers
            SecurityImpl nyse = new SecurityImpl("LVS");
            string       p    = nyse.ToString();

            SecurityImpl t = SecurityImpl.Parse(p);

            Assert.That(t.Symbol == nyse.Symbol, t.Symbol);
            Assert.That(!t.hasDest, t.DestEx);
            Assert.That(t.Type == nyse.Type, t.Type.ToString());

            SecurityImpl crude = SecurityImpl.Parse("CLV8 FUT GLOBEX");

            Assert.That(crude.Symbol == "CLV8", crude.Symbol);
            Assert.That(crude.hasDest, crude.DestEx);
            Assert.That(crude.Type == SecurityType.FUT, crude.Type.ToString());
            SecurityImpl goog = SecurityImpl.Parse("GOOG");

            Assert.AreEqual("GOOG", goog.FullName);

            Security opt = SecurityImpl.Parse("IBM PUT 201004 100.00");

            Assert.That(opt.Type == SecurityType.OPT);
            Assert.AreEqual(100, opt.Strike);
            Assert.AreEqual("PUT", opt.Details);
            Assert.AreEqual(201004, opt.Date);
        }
예제 #5
0
파일: TikReader.cs 프로젝트: mpvyard/Core
        /// <summary>
        /// Read file header for TIK file information
        /// </summary>
        private void ReadHeader()
        {
            // get version id
            ReadByte();

            // get version
            _fileversion = ReadInt32();
            if (_fileversion != TikConst.Filecurrentversion)
            {
                throw new BadTikFile("version: " + _fileversion + " expected: " + TikConst.Filecurrentversion);
            }

            // get real symbol
            _realsymbol = ReadString();

            // get security from symbol
            _sec      = SecurityImpl.Parse(_realsymbol);
            _sec.Date = SecurityImpl.SecurityFromFileName(_path).Date;

            // get short symbol
            _sym = _sec.Name;

            // get end of header
            ReadByte();

            // make sure we read something
            if (_realsymbol.Length <= 0)
            {
                throw new BadTikFile("no symbol defined in tickfile");
            }

            // flag header as read
            _haveheader = true;
        }
예제 #6
0
        int[] GetSymbolRows(string sym)
        {
            int[] res = new int[0];
            if (symidx.TryGetValue(sym, out res))
            {
                return(res);
            }
            List <int> rows = new List <int>();

            for (int i = 0; i < qt.Rows.Count; i++)
            {
                if (qt.Rows[i].RowState == DataRowState.Deleted)
                {
                    continue;
                }
                Security sec  = SecurityImpl.Parse(qt.Rows[i]["Symbol"].ToString());
                Security csec = SecurityImpl.Parse(sym);
                if (sec.Symbol == csec.Symbol)
                {
                    rows.Add(i);
                }
            }

            return(rows.ToArray());
        }
예제 #7
0
        Security GetVisibleSecurity(int row)
        {
            if ((row < 0) || (row >= qg.Rows.Count))
            {
                return(new SecurityImpl());
            }
            Security s = SecurityImpl.Parse(qt.Rows[row]["Symbol"].ToString());

            return(s);
        }
예제 #8
0
        private void recordbut_Click(object sender, EventArgs e)
        {
            int          size = mb.Count;
            SecurityImpl sec  = SecurityImpl.Parse(symbox.Text);

            if (sec.isValid)
            {
                mb.Add(sec);
            }
            refreshlist(size);
        }
예제 #9
0
        void workingres_SendOrder(Order o)
        {
            // process order coming from a response

            // set account on order
            if (o.Account == string.Empty)
            {
                o.Account = _ao._account.Text;
            }
            try
            {
                // set the security
                if (o.Security == SecurityType.NIL)
                {
                    o.Security = _seclist[o.symbol].Type;
                }
                // set the exchange
                if (o.Exchange == string.Empty)
                {
                    o.Exchange = _seclist[o.symbol].DestEx;
                }
            }
            catch (KeyNotFoundException)
            {
                string       sym = SecurityImpl.Parse(o.symbol).Symbol;
                SecurityImpl sec = null;
                if (_seclist.TryGetValue(sym, out sec))
                {
                    o.Security = sec.Type;
                    o.Exchange = sec.DestEx;
                }
                else
                {
                    debug("security and exchange missing on: " + o.symbol);
                }
            }
            // set the local symbol
            if (o.LocalSymbol == string.Empty)
            {
                o.LocalSymbol = o.symbol;
            }
            // assign master order if necessary
            assignmasterorderid(ref o);
            // send order and get error message
            int res = tl.SendOrder(o);

            // if error, display it
            if (res != (int)MessageTypes.OK)
            {
                debug(Util.PrettyError(tl.BrokerName, res) + " " + o.ToString());
            }
        }
예제 #10
0
        public void Parsing()
        {
            // tests to parse and generate user-supplied security specifiers
            SecurityImpl nyse = new SecurityImpl("LVS");
            string p = nyse.ToString();

            SecurityImpl t = SecurityImpl.Parse(p);
            Assert.True(t.Name == nyse.Name, t.Name);
            Assert.True(t.Type == nyse.Type, t.Type.ToString());

            SecurityImpl crude = SecurityImpl.Parse("CLV8 FUT GLOBEX");
            Assert.True(crude.Name == "CLV8", crude.Name);
            Assert.True(crude.HasDest, crude.DestEx);
            Assert.True(crude.Type == SecurityType.Future, crude.Type.ToString());
            SecurityImpl goog = SecurityImpl.Parse("GOOG");
            Assert.Equal("GOOG", goog.Name);
        }
예제 #11
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            if (VerboseDebugging)
            {
                debug("client subscribe request received: " + symbols);
            }

            Basket rem = new BasketImpl();

            // if we had something before, check if something was removed
            if (org.Count > 0)
            {
                rem = BasketImpl.Subtract(org, tl.AllClientBasket);
            }

            SubscriptionFlags flags = SubscriptionFlags.Prints;

            flags |= SubscriptionFlags.Quotes;
            flags |= SubscriptionFlags.Best;

            List <string> syms = new List <string>();

            syms.AddRange(tl.AllClientBasket.ToSymArray());

            List <string> orgs = new List <string>(org.ToSymArray());

            // add current
            foreach (string sym in tl.AllClientBasket.ToSymArray())
            {
                // subscribe what we don't have
                if (!orgs.Contains(sym))
                {
                    // get the security
                    Security sec = SecurityImpl.Parse(sym);
                    string   ex  = sec.hasDest ? sec.DestEx : "NYSE";
                    oEngine.subscribe(ex, sec.Symbol, flags, null);
                }
            }

            // remove old
            foreach (Security s in rem)
            {
                oEngine.unsubscribe(string.Empty, s.Symbol);
            }
        }
예제 #12
0
        public void Serialization()
        {
            BasketImpl mb = new BasketImpl();

            mb.Add(new SecurityImpl("IBM"));
            BasketImpl compare = BasketImpl.Deserialize(mb.ToString());

            Assert.That(compare.Count == 1);
            mb.Clear();
            compare = BasketImpl.Deserialize(mb.ToString());
            Assert.That(compare.Count == 0);

            mb.Clear();
            SecurityImpl longform = SecurityImpl.Parse("CLZ8 FUT NYMEX");

            mb.Add(longform);
            compare = BasketImpl.Deserialize(mb.ToString());
            Assert.AreEqual(longform.ToString(), compare[0].ToString());
        }
예제 #13
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            D("got subscribe request: " + client + ": " + symbols);


            // ensure new symbols are added
            Basket newb = tl.AllClientBasket;

            // ensure we have an id
            foreach (string sym in newb.ToSymArray())
            {
                Security sec = SecurityImpl.Parse(sym);
                char     p;
                if (sec.Type == SecurityType.STK)
                {
                    p = 'e';
                }
                else if (sec.Type == SecurityType.BND)
                {
                    p = 'b';
                }
                else if (sec.Type == SecurityType.FUT)
                {
                    p = 'f';
                }
                else if (sec.Type == SecurityType.IDX)
                {
                    p = 'i';
                }
                else if (sec.Type == SecurityType.OPT)
                {
                    p = 'o';
                }
                else if (sec.Type == SecurityType.CASH)
                {
                    p = 'c';
                }
                else if (sec.Type == SecurityType.FOP)
                {
                    p = 'p';
                }
                else
                {
                    p = 'e';
                }
                string nxsym = p + sec.symbol;
                int    idx   = _nxsyms.addindex(nxsym, true);
                _realsym2nxidx.addindex(sec.symbol, idx);
            }
            // ensure old symbols are removed
            if (old.Count > 0)
            {
                Basket rem = BasketImpl.Subtract(old, newb);
                foreach (Security s in rem)
                {
                    int idx = _realsym2nxidx.getindex(s.symbol);
                    if (idx < 0)
                    {
                        debug("Unable to locate subscription for: " + s.symbol);
                        continue;
                    }
                    _nxsyms[idx] = false;
                }
            }
            // save new as old
            old = newb;
        }
예제 #14
0
        private void Trade_Click(object sender, EventArgs e)
        {
            // user clicks on trade button

            // make sure a response is selected
            if (_availresponses.SelectedIndex == -1)
            {
                status("Please select a response.");
                return;
            }


            // get all the provided symbols
            string[] syms = _symstraded.Text.Split(',');
            // prepare a list of valid symbols
            List <string> valid = new List <string>();

            // process every provided symbol
            foreach (string symt in syms)
            {
                // make it uppercase
                string sym = symt.ToUpper();
                // parse out security information
                SecurityImpl sec = SecurityImpl.Parse(sym);
                // if it's an invalid security, ignore it
                if (!sec.isValid)
                {
                    status("Security invalid: " + sec.ToString());
                    continue;
                }
                // otherwise add the security
                _mb.Add(sec);
                // save simple symbol as valid
                valid.Add(sec.Symbol);
                // if we don't have this security
                if (!_seclist.ContainsKey(sec.Symbol))
                {
                    // lock so other threads don't modify seclist at same time
                    lock (_seclist)
                    {
                        // add security to our list
                        _seclist.Add(sec.Symbol, sec);
                    }
                }
            }
            // add working response to response list after obtaining a lock
            lock (_reslist)
            {
                _reslist.Add(_workingres);
            }
            // get index to this response
            int idx = _reslist.Count - 1;

            // send response current positions
            foreach (Position p in _pt)
            {
                _reslist[idx].GotPosition(p);
            }
            // subscribe to whatever symbols were requested
            try
            {
                tl.Subscribe(_mb);
            }
            catch (TLServerNotFound) { debug("subscribe failed because no TL server is running."); }
            // add name to user's screen
            _resnames.Items.Add(_workingres.FullName + " [" + string.Join(",", valid.ToArray()) + "]");
            // update their screen
            _resnames.Invalidate(true);
            // process all securities and build  a quick index for a security's name to the response that requests it
            foreach (SecurityImpl sec in _seclist.Values)
            {
                if (_symidx.ContainsKey(sec.FullName)) // we already had one requestor
                {
                    // get current length of request list for security
                    int len = _symidx[sec.FullName].Length;
                    // add one to it for our new requestor
                    int[] a = new int[len + 1];
                    // add our new requestor's index at the end
                    a[len] = idx;
                }
                else // otherwise it's just this guy so add him
                {
                    _symidx.Add(sec.FullName, new int[] { idx });
                }
            }
            // clear the symbol list
            _symstraded.Clear();
            // show we added response
            status(_workingres.FullName + " [" + string.Join(",", valid.ToArray()) + "]");
            // unselect response
            _availresponses.SelectedIndex = -1;
        }
예제 #15
0
        public void KeyUp(object sender, KeyEventArgs e)
        {
            string preface = "Adding symbol: ";

            if (e.KeyCode == Keys.Enter)
            {
                Security sec = SecurityImpl.Parse(newsymbol);
                if (sec.isValid)
                {
                    if (addsymbol(newsymbol))
                    {
                        newsymbol = "";
                    }
                }
                else
                {
                    status("Invalid Security " + newsymbol);
                    newsymbol = "";
                }
            }
            else if (e.Shift && (e.KeyCode == Keys.OemPipe))
            {
                newsymbol += "|";
                status(preface + newsymbol);
            }
            else if (e.Shift && (e.KeyCode == Keys.OemQuestion))
            {
                newsymbol += "?";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.OemPipe))
            {
                newsymbol += "\\";
                status(preface + newsymbol);
            }
            else if (e.KeyCode == Keys.OemQuestion)
            {
                newsymbol += "/";
                status(preface + newsymbol);
            }
            else if (e.KeyCode == Keys.OemPeriod)
            {
                newsymbol += ".";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.OemMinus) && e.Shift)
            {
                newsymbol += "_";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.D4) && e.Shift)
            {
                newsymbol = "$";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.Escape) || (e.KeyCode == Keys.Delete))
            {
                newsymbol = "";
                status("Symbol add canceled...");
            }
            else if ((e.KeyCode == Keys.Back) && (newsymbol.Length > 0))
            {
                newsymbol = newsymbol.Substring(0, newsymbol.Length - 1);
                status(preface + newsymbol);
            }
            else if (((e.KeyValue >= (int)Keys.A) && (e.KeyValue <= (int)Keys.Z)) ||
                     ((e.KeyValue >= (int)Keys.D0) && (e.KeyValue <= (int)Keys.D9)) || e.Shift || (e.KeyData == Keys.Space))
            {
                string val = "";
                if (e.Shift)
                {
                    switch (e.KeyCode)
                    {
                    case Keys.D3: val = "#";
                        break;
                    }
                }
                else
                {
                    char v = (char)e.KeyValue;
                    val += v;
                }
                newsymbol += val;
                status("Adding symbol: " + newsymbol);
            }
            else if (e.KeyData == Keys.OemPeriod)
            {
                newsymbol += ".";
                status("Adding symbol: " + newsymbol);
            }
            else if (e.KeyData == Keys.Space)
            {
                newsymbol += " ";
                status("Adding symbol: " + newsymbol);
            }
            else if (e.KeyData == Keys.OemMinus)
            {
                newsymbol += "-";
                status("Adding symbol: " + newsymbol);
            }
        }
예제 #16
0
        void qg_KeyUp(object sender, KeyEventArgs e)
        {
            // only pay attention when market tab is selected
            if (quoteTab.SelectedTab.Name != "Markets")
            {
                return;
            }
            string preface = "Adding symbol: ";

            if (e.KeyCode == Keys.Enter)
            {
                Security sec = SecurityImpl.Parse(newsymbol);
                if (sec.isValid)
                {
                    if (addsymbol(newsymbol))
                    {
                        newsymbol = "";
                        try
                        {
                            _bf.Subscribe(mb);
                        }
                        catch (TLServerNotFound) { debug("no broker or feed server running."); }
                    }
                }
                else
                {
                    status("Invalid Security " + newsymbol);
                    newsymbol = "";
                }
            }
            else if (e.Shift && (e.KeyCode == Keys.OemPipe))
            {
                newsymbol += "|";
                status(preface + newsymbol);
            }
            else if (e.Shift && (e.KeyCode == Keys.OemQuestion))
            {
                newsymbol += "?";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.OemPipe))
            {
                newsymbol += "\\";
                status(preface + newsymbol);
            }
            else if (e.KeyCode == Keys.OemQuestion)
            {
                newsymbol += "/";
                status(preface + newsymbol);
            }
            else if (e.KeyCode == Keys.OemPeriod)
            {
                newsymbol += ".";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.OemMinus) && e.Shift)
            {
                newsymbol += "_";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.D4) && e.Shift)
            {
                newsymbol = "$";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.Escape) || (e.KeyCode == Keys.Delete))
            {
                newsymbol = "";
                status("Symbol add canceled...");
            }
            else if ((e.KeyCode == Keys.Back) && (newsymbol.Length > 0))
            {
                newsymbol = newsymbol.Substring(0, newsymbol.Length - 1);
                status(preface + newsymbol);
            }
            else if (((e.KeyValue >= (int)Keys.A) && (e.KeyValue <= (int)Keys.Z)) ||
                     ((e.KeyValue >= (int)Keys.D0) && (e.KeyValue <= (int)Keys.D9)) || e.Shift || (e.KeyData == Keys.Space))
            {
                string val = "";
                if (e.Shift)
                {
                    switch (e.KeyCode)
                    {
                    case Keys.D3: val = "#";
                        break;
                    }
                }
                else
                {
                    char v = (char)e.KeyValue;
                    val += v;
                }
                newsymbol += val;
                status("Adding symbol: " + newsymbol);
            }
            else if (e.KeyData == Keys.OemPeriod)
            {
                newsymbol += ".";
                status("Adding symbol: " + newsymbol);
            }
            else if (e.KeyData == Keys.Space)
            {
                newsymbol += " ";
                status("Adding symbol: " + newsymbol);
            }
            else if (e.KeyData == Keys.OemMinus)
            {
                newsymbol += "-";
                status("Adding symbol: " + newsymbol);
            }
        }
예제 #17
0
        void qg_KeyUp(object sender, KeyEventArgs e)
        {
            // only pay attention when market tab is selected
            if (quoteTab.SelectedTab.Name != "Markets")
            {
                return;
            }
            string preface = "Adding symbol: ";

            if (newsymbol.Contains("$") || newsymbol.Contains("/"))
            {
                preface = "Adding index: ";
            }
            if (e.KeyCode == Keys.Enter)
            {
                Security sec = SecurityImpl.Parse(newsymbol);
                if (sec.isValid)
                {
                    mb.Add(sec);
                    addsymbol(newsymbol);
                    newsymbol = "";
                    tl.Subscribe(mb);
                }
                else
                {
                    status("Invalid Security " + newsymbol);
                    newsymbol = "";
                }
            }
            else if (e.KeyCode == Keys.OemQuestion)
            {
                newsymbol += "/";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.D4) && e.Shift)
            {
                newsymbol = "$";
                status(preface + newsymbol);
            }
            else if ((e.KeyCode == Keys.Escape) || (e.KeyCode == Keys.Delete))
            {
                newsymbol = "";
                status("Symbol add canceled...");
            }
            else if ((e.KeyCode == Keys.Back) && (newsymbol.Length > 0))
            {
                newsymbol = newsymbol.Substring(0, newsymbol.Length - 1);
                status(preface + newsymbol);
            }
            else if (((e.KeyValue >= (int)Keys.A) && (e.KeyValue <= (int)Keys.Z)) ||
                     ((e.KeyValue >= (int)Keys.D0) && (e.KeyValue <= (int)Keys.D9)) || e.Shift || (e.KeyData == Keys.Space))
            {
                string val = "";
                if (e.Shift)
                {
                    switch (e.KeyCode)
                    {
                    case Keys.D3: val = "#";
                        break;
                    }
                }
                else
                {
                    char v = (char)e.KeyValue;
                    val += v;
                }
                newsymbol += val;
                status("Adding symbol: " + newsymbol);
            }
        }