예제 #1
0
        private IEnumerable<string> FormatQuotes(IEnumerable<Quote> quotes, ContractSpecification contractSpecification)
        {
            var lines = new List<string>();
            lines.Add(string.Format("public static Market {0}", _forbiddenCharacters.Replace(contractSpecification.Name, string.Empty)));
            lines.Add("{");
            lines.Add("\tget {");
            lines.Add("\t return new Market(");
            lines.Add(string.Format("new ContractSpecification(\"{0}\",\"{1}\",{2},\"{3}\",\"{4}\",Category.{5},{6},\"{7}\"),",
                contractSpecification.Exchange, contractSpecification.Months,
                contractSpecification.PointValueUsd, contractSpecification.Symbol,
                contractSpecification.Name,contractSpecification.Category,
                contractSpecification.ContractSize, contractSpecification.SizeUnit));

            lines.Add("new List<Quote>{ ");
            foreach (var quote in quotes)
            {
                lines.Add(string.Format(
                    "\t\tnew Quote{{Symbol = \"{0}\",DateTime=new DateTime({1},{2},{3}),Close ={4},High = {5},Interest = {6},Low = {7},Open = {8},Period=Period.{9},Volume = {10}}},"
                    , quote.Symbol, quote.DateTime.Year, quote.DateTime.Month, quote.DateTime.Day, quote.Close, quote.High, quote.Interest,
                    quote.Low, quote.Open, Period.Weekly, quote.Volume));
            }
            lines.Add("\t\t});");
            lines.Add("\t}");
            lines.Add("}");
            return lines;
        }
예제 #2
0
 private string GetNearestExpirationMonth(ContractSpecification contractSpecification)
 {
     var currentMonth = "FGHJKMNQUVXZ"[DateTime.Now.Month - 1];
     var selected = contractSpecification.Months.FirstOrDefault(d => currentMonth <= d);
     if (selected == '\0')
     {
         selected = contractSpecification.Months.First();
     }
     return string.Format("{0}{1}{2:00}", contractSpecification.Symbol, selected, DateTime.Now.Year - 2000);
 }
예제 #3
0
 private IEnumerable<string> GetExpirationMonths(ContractSpecification contractSpecification)
 {
     var codes = new List<string>();
     for (var i = 09; i < DateTime.Now.Year - 2000; i += 5)
     {
         codes.Add(string.Format("{0}{1}{2:00}", contractSpecification.Symbol, contractSpecification.Months.First(), i));
     }
     codes.Add(GetNearestExpirationMonth(contractSpecification));
     return codes;
 }
예제 #4
0
 public Market(ContractSpecification contractSpecification, IEnumerable<Quote> quotes)
 {
     ContractSpecification = contractSpecification;
     Quotes = quotes;
 }
 public static bool TryParse(string symbol, out ContractSpecification contractSpecification)
 {
     contractSpecification = Data.FirstOrDefault(d => d.Symbol == symbol.ToUpperInvariant());
     return contractSpecification != null;
 }