Esempio n. 1
0
        public void ReadWatchListFromFile(string path)
        {
            var lines = File.ReadAllLines(path);

            char[] charToTrim = { ' ', '\t', '\r', '\n' };
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Trim(charToTrim) != String.Empty)
                {
                    string code   = lines[i].Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1];
                    string market = lines[i].Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0];
                    if (i == 0 && header)
                    {
                        continue;
                    }

                    int      j;
                    Security security = new Security();
                    if (Int32.TryParse(market, out j))
                    {
                        security.Market = (QotCommon.QotMarket)j;
                        security.Code   = code;
                        List.Add(new Quote()
                        {
                            Code = code, Security = security, Name = AllSymbols.Where(x => x.Code == code).Select(s => s.Name).DefaultIfEmpty("").First()
                        });
                    }
                }
            }
        }
Esempio n. 2
0
        public void LookupSymbols(string str)
        {
            var result = AllSymbols.Where(x => x.Code.ToUpper().Contains(str.ToUpper()) ||
                                          x.PinYin.Contains(str.ToUpper()) ||
                                          x.Name.ToUpper().Contains(str.ToUpper()));

            SymbolSearchResult = new List <Symbol>(result);
        }
Esempio n. 3
0
 private void FillInSymbols(List <Contract> contracts)
 {
     foreach (var contract in contracts)
     {
         AllSymbols.Add(new Symbol()
         {
             Security = contract.Security,
             Code     = contract.Security.Code,
             Name     = contract.Name,
             PinYin   = PinYin.GetSpellCode(contract.Name)
         });
     }
 }
Esempio n. 4
0
 protected override void ModifyCell(Cell cell, char symbol)
 {
     if (symbol == Origin.Symbol)
     {
         cell.AddTile(new Tile(TileIdSequence++, 0, Origin.Creature));
     }
     else if (symbol == Friend.Symbol)
     {
         cell.AddTile(new Tile(TileIdSequence++, 0, Friend.Creature));
     }
     else if (symbol == Enemy.Symbol)
     {
         cell.AddTile(new Tile(TileIdSequence++, 1, Enemy.Creature));
     }
     else
     {
         var(creature, cellString, _) = AllSymbols.Single(s => s.Symbol == symbol);
         var playerId = cellString.ToString().ToUpper() == cellString.ToString() ? 0 : 1;
         cell.AddTile(new Tile(TileIdSequence++, playerId, creature));
     }
 }
 public IObservableX <ISourceSymbol> SearchSymbol(string filter)
 {
     return(string.IsNullOrEmpty(filter)
                         ? AllSymbols
                         : AllSymbols.Where(symbol => symbol.DisplayText.Contains(filter)));
 }
        /// <summary>
        /// Applies filter selecting options contracts based on a range of strikes in relative terms
        /// </summary>
        /// <param name="minStrike">The minimum strike relative to the underlying price, for example, -1 would filter out contracts further than 1 strike below market price</param>
        /// <param name="maxStrike">The maximum strike relative to the underlying price, for example, +1 would filter out contracts further than 1 strike above market price</param>
        /// <returns>Universe with filter applied</returns>
        public OptionFilterUniverse Strikes(int minStrike, int maxStrike)
        {
            if (UnderlyingInternal == null)
            {
                return(this);
            }

            if (_refreshUniqueStrikes || _uniqueStrikes == null)
            {
                // each day we need to recompute the unique strikes list
                _uniqueStrikes = AllSymbols.Select(x => x.ID.StrikePrice)
                                 .Distinct()
                                 .OrderBy(strikePrice => strikePrice)
                                 .ToList();
                _refreshUniqueStrikes = false;
            }

            // new universe is dynamic
            IsDynamicInternal = true;

            // find the current price in the list of strikes
            var exactPriceFound = true;
            var index           = _uniqueStrikes.BinarySearch(UnderlyingInternal.Price);

            // Return value of BinarySearch (from MSDN):
            // The zero-based index of item in the sorted List<T>, if item is found;
            // otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item
            // or, if there is no larger element, the bitwise complement of Count.
            if (index < 0)
            {
                // exact price not found
                exactPriceFound = false;

                if (index == ~_uniqueStrikes.Count)
                {
                    // there is no greater price, return empty
                    AllSymbols = Enumerable.Empty <Symbol>();
                    return(this);
                }

                index = ~index;
            }

            // compute the bounds, no need to worry about rounding and such
            var indexMinPrice = index + minStrike;
            var indexMaxPrice = index + maxStrike;

            if (!exactPriceFound)
            {
                if (minStrike < 0 && maxStrike > 0)
                {
                    indexMaxPrice--;
                }
                else if (minStrike > 0)
                {
                    indexMinPrice--;
                    indexMaxPrice--;
                }
            }

            if (indexMinPrice < 0)
            {
                indexMinPrice = 0;
            }
            else if (indexMinPrice >= _uniqueStrikes.Count)
            {
                // price out of range: return empty
                AllSymbols = Enumerable.Empty <Symbol>();
                return(this);
            }

            if (indexMaxPrice < 0)
            {
                // price out of range: return empty
                AllSymbols = Enumerable.Empty <Symbol>();
                return(this);
            }
            if (indexMaxPrice >= _uniqueStrikes.Count)
            {
                indexMaxPrice = _uniqueStrikes.Count - 1;
            }

            var minPrice = _uniqueStrikes[indexMinPrice];
            var maxPrice = _uniqueStrikes[indexMaxPrice];

            AllSymbols = AllSymbols
                         .Where(symbol =>
            {
                var price = symbol.ID.StrikePrice;
                return(price >= minPrice && price <= maxPrice);
            }
                                ).ToList();

            return(this);
        }