コード例 #1
0
ファイル: QuoteController.cs プロジェクト: Lornestar/pfx
 public QuoteCollection FetchAll()
 {
     QuoteCollection coll = new QuoteCollection();
     Query qry = new Query(Quote.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
コード例 #2
0
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog loadDialog = new OpenFileDialog();

            loadDialog.Filter = "Quote File|*.quo";
            loadDialog.Title  = "Load the QuoteCollection now binary file ...";

            if (loadDialog.ShowDialog() == DialogResult.OK)
            {
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(loadDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                History = (QuoteCollection)formatter.Deserialize(stream);
                stream.Close();

                if (History != null && History.Count != 0)
                {
                    loadQuoteInformation();
                    Ephemeris.CurrentEphemeris.Load(History.Since, History.Until);

                    launchDetailForm();
                }
            }

            //if (this.FormClosed != null)
            //{

            //}
        }
コード例 #3
0
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "*.txt";
            openFileDialog1.Filter   = "Text Files|*.txt";
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            int start = openFileDialog1.FileName.LastIndexOf('\\');

            textBoxPath.Text = openFileDialog1.FileName.Substring(0, start + 1);
            string fileName = openFileDialog1.FileName.Substring(start);

            int upIndex = openFileDialog1.FileName.Substring(0, start).LastIndexOf('\\');

            textBoxOutput.Text = openFileDialog1.FileName.Substring(0, upIndex + 1);

            CommodityInfomation commodity = CommodityInfomation.CommodityOf(fileName);

            if (commodity == null)
            {
                textBoxDescription.Text = "Failed to get Commodity Information from " + openFileDialog1.FileName;
                return;
            }
            else
            {
                textBoxDescription.Text = string.Format("{0}\r\n", commodity);
            }

            SortedDictionary <ContractInfomation, QuoteCollection> theSortedQuotes = new SortedDictionary <ContractInfomation, QuoteCollection>();

            foreach (string filename in openFileDialog1.FileNames)
            {
                ContractInfomation theContract = commodity.ContractOf(filename.Substring(start));
                List <Quote>       items       = TextDataImporter.Import(filename);

                if (items == null)
                {
                    continue;
                }

                QuoteCollection quotes = new QuoteCollection(theContract, filename, RecordType.DayRecord, items);

                theSortedQuotes.Add(theContract, quotes);
            }

            quoteGroup = new GroupedQuoteCollection(commodity, theSortedQuotes);

            textBoxDescription.AppendText(String.Format("{0} Contracts: from {1} to {2}", theSortedQuotes.Count, theSortedQuotes.First().Value.Since, theSortedQuotes.Last().Value.Until));

            checkedListBoxMonths.Items.Clear();

            foreach (MonthCodes code in commodity.Months)
            {
                checkedListBoxMonths.Items.Add(code);
                checkedListBoxMonths.SetItemChecked(checkedListBoxMonths.Items.Count - 1, false);
            }
        }
コード例 #4
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            try
            {
                if (importQuoteFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                List <Quote> items   = null;
                int          pos     = importQuoteFileDialog.FileName.LastIndexOf('.');
                string       dirName = importQuoteFileDialog.FileName.Substring(0, pos);

                pos = dirName.LastIndexOf('\\');
                string name = dirName.Substring(pos + 1, dirName.Length - pos - 1);

                if (importQuoteFileDialog.FileName.EndsWith("txt"))
                {
                    textBoxFileName.Text = "";

                    items = TextImporter.Import(importQuoteFileDialog.FileName);

                    //foreach (string filename in importQuoteFileDialog.FileNames)
                    //{
                    //    textBoxFileName.Text += filename + " ";
                    //}

                    //int pos = importQuoteFileDialog.FileNames[0].LastIndexOf(importQuoteFileDialog.FileNames.Count() == 1 ? '.' : '\\');
                    //string dirName = importQuoteFileDialog.FileNames[0].Substring(0, pos);

                    //foreach (string fileName in importQuoteFileDialog.FileNames)
                    //{
                    //    List<Quote> newItems = TextImporter.Import(fileName);
                    //    items.AddRange(newItems);
                    //}
                }
                else if (importQuoteFileDialog.FileName.EndsWith(PoboImporter.FilePostfix))
                {
                    items = PoboImporter.Import(importQuoteFileDialog.FileName);
                }

                History = new QuoteCollection(name, items);

                if (History.Count != 0)
                {
                    loadQuoteInformation();
                    Ephemeris.CurrentEphemeris.Load(History.Since, History.Until);
                }

                launchDetailForm();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
コード例 #5
0
        private void buttonLoadPobo_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "*.da1";
            openFileDialog1.Filter   = "Pobo Day Files|*.da1";
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            int start = openFileDialog1.FileName.LastIndexOf('\\');

            int upIndex = openFileDialog1.FileName.Substring(0, start).LastIndexOf('\\');

            CommodityInfomation commodity = CommodityInfomation.CommodityOf(openFileDialog1.FileName.Substring(start));

            if (quoteGroup == null)
            {
                throw new Exception("Please import records from text files first.");
            }

            if (commodity == null)
            {
                textBoxDescription.Text = "Failed to get Commodity Information from " + openFileDialog1.FileName;
                return;
            }
            else if (commodity != quoteGroup.Commodity)
            {
                textBoxDescription.Text = "Different commodity: " + openFileDialog1.FileName;
                return;
            }
            else
            {
                textBoxDescription.Text = string.Format("{0}\r\n", commodity);
            }

            foreach (string filename in openFileDialog1.FileNames)
            {
                ContractInfomation theContract = commodity.ContractOf(filename.Substring(start));

                if (theContract.Month == 0 && (openFileDialog1.FileNames.Length > 1))
                {
                    continue;
                }

                List <Quote> items = PoboDataImporter.Import(filename, RecordType.DayRecord);

                if (items == null)
                {
                    continue;
                }

                QuoteCollection quotes = new QuoteCollection(theContract, filename, RecordType.DayRecord, items);

                quoteGroup.Group.Add(theContract, quotes);
            }
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: sharespy/Astroder
        private void browsePoboToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PoboBrowser browser = new PoboBrowser();

            if (browser.ShowDialog() == DialogResult.OK && browser.SelectedFileName != "")
            {
                List <Quote> items = PoboImporter.Import(browser.SelectedFileName);

                History = new QuoteCollection(browser.FutureName, items);

                if (History.Count != 0)
                {
                    Ephemeris.CurrentEphemeris.Load(History.Since, History.Until);
                }

                launchDetailForm();
            }
        }
コード例 #7
0
ファイル: CyclesPresenter.cs プロジェクト: sharespy/Astroder
        public CyclesPresenter(ZedGraphControl control, QuoteCollection history)
        {
            Zed     = control;
            History = history;
            Orbits  = GeocentricOrbits;

            Frame = AngleFrame.Natural;
            Clock = TimeAngleConverter.SolarClock;

            ClocksDict = new Dictionary <string, TimeAngleConverter>();

            DateTimeOffset floorDate   = History.DataCollection[History.FloorIndex].Date;
            DateTimeOffset ceilingDate = History.DataCollection[History.CelingIndex].Date;

            ClocksDict.Add("FloorCeiling", new TimeAngleConverter(floorDate, Math.Abs((floorDate - ceilingDate).TotalDays)));
            ClocksDict.Add("FirstNatural", new TimeAngleConverter(History.Since));
            ClocksDict.Add("First360", new TimeAngleConverter(History.Since, 360));
            ClocksDict.Add("LowestNatural", new TimeAngleConverter(floorDate));
            ClocksDict.Add("Lowest360", new TimeAngleConverter(floorDate, 360));
            ClocksDict.Add("HighestNatural", new TimeAngleConverter(ceilingDate));
            ClocksDict.Add("Highest360", new TimeAngleConverter(ceilingDate, 360));

            PriceDict = new Dictionary <string, PriceAdapter>();
            double floor   = History.Floor;
            double ceiling = History.Ceiling;

            for (PriceMappingRules rule = PriceMappingRules.Filled; rule <= PriceMappingRules.FloorStep; rule++)
            {
                PriceDict.Add(rule.ToString(), new PriceAdapter(rule, floor, ceiling));
            }

            //Curves = new Dictionary<PlanetId, Dictionary<OrbitInfoType, OrbitSpec>>();

            //for (PlanetId id = PlanetId.SE_SUN; id <= PlanetId.SE_PLUTO; id++)
            //{
            //    Curves.Add(id, new Dictionary<OrbitInfoType, OrbitSpec>());
            //}

            InitiateGraphControl();
            Zed.ZoomEvent += new ZedGraphControl.ZoomEventHandler(Control_ZoomEvent);

            PlusOrbits  = new List <OrbitSpec>();
            MinusOrbits = new List <OrbitSpec>();
        }
コード例 #8
0
ファイル: QuoteManager.cs プロジェクト: bsschwar/StockTracker
        public async Task<QuoteCollection> GetQuotes(IEnumerable<string> symbols)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://finance.yahoo.com/webservice/v1/symbols/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.Timeout = new TimeSpan(0, 0, 10);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.GetAsync(String.Format("{0}/quote?format=json", String.Join(",", symbols)));
                response.EnsureSuccessStatusCode();
                JObject obj = await response.Content.ReadAsAsync<JObject>();

                var quotes = new QuoteCollection();
                foreach (var item in obj["list"]["resources"])
                {
                    JToken q = item["resource"]["fields"];
                    String symbol = q["symbol"].ToObject<string>();
                    decimal price = q["price"].ToObject<decimal>();
                    quotes[symbol] = price;
                }
                return quotes;
            }
        }
コード例 #9
0
        private void buttonGo_Click(object sender, EventArgs e)
        {
            string destPath = textBoxOutput.Text;

            int fileCount = 0;

            foreach (object obj in checkedListBoxMonths.CheckedItems)
            {
                MonthCodes code = obj as MonthCodes;

                List <QuoteCollection> monthlyContracts = quoteGroup[code.Month];

                string formatString = "yyyy-MM-dd";

                foreach (QuoteCollection contract in monthlyContracts)
                {
                    string       txtname = destPath + contract.Name + ".txt";
                    FileStream   stream  = new FileStream(txtname, FileMode.Create, FileAccess.Write);
                    StreamWriter sw      = new StreamWriter(stream);
                    sw.AutoFlush = true;

                    sw.WriteLine("Date,Open,High,Low,Close,Volume");
                    for (int i = 0; i < contract.DataCollection.Count; i++)
                    {
                        Quote quote = contract.DataCollection[i];
                        //sw.WriteLine(quote.ToString());
                        sw.WriteLine(String.Format("{0},{1},{2},{3},{4},{5}", quote.Time.ToString(formatString),
                                                   quote.Open, quote.High, quote.Low, quote.Close, quote.Volume));
                    }
                    stream.Close();

                    fileCount++;
                }
            }

            if (panelContinuous.Enabled)
            {
                foreach (GroupingFlag flag in this.methodFlags)
                {
                    bool            isVolumeBased = checkBoxVolumeBased.Checked;
                    QuoteCollection continous     = quoteGroup[flag, isVolumeBased];

                    string formatString = "yyyy-MM-dd";

                    string       txtname = destPath + continous.Name + ".txt";
                    FileStream   stream  = new FileStream(txtname, FileMode.Create, FileAccess.Write);
                    StreamWriter sw      = new StreamWriter(stream);
                    sw.AutoFlush = true;

                    sw.WriteLine("Date,Open,High,Low,Close,Volume");
                    for (int i = 0; i < continous.DataCollection.Count; i++)
                    {
                        Quote quote = continous.DataCollection[i];
                        //sw.WriteLine(quote.ToString());
                        sw.WriteLine(String.Format("{0},{1},{2},{3},{4},{5}", quote.Time.ToString(formatString),
                                                   quote.Open, quote.High, quote.Low, quote.Close, quote.Volume));
                    }
                    stream.Close();

                    fileCount++;
                }
            }

            MessageBox.Show(fileCount.ToString() + " files are geneerated.");
        }
コード例 #10
0
ファイル: QuoteController.cs プロジェクト: Lornestar/pfx
 public QuoteCollection FetchByQuery(Query qry)
 {
     QuoteCollection coll = new QuoteCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
コード例 #11
0
ファイル: QuoteController.cs プロジェクト: Lornestar/pfx
 public QuoteCollection FetchByID(object QuotesKey)
 {
     QuoteCollection coll = new QuoteCollection().Where("quotes_key", QuotesKey).Load();
     return coll;
 }