private static void ParseHistorical(ObservableCollection <HistoricalQuote> quotes, XDocument doc) { if (doc.Root != null) { XElement results = doc.Root.Element("results"); foreach (XElement node in results.Elements("quote")) { var hq = new HistoricalQuote { Symbol = node.Attribute("Symbol").Value, Date = GetDateTime(node.Element("Date").Value), Open = GetDecimal(node.Element("Open").Value), High = GetDecimal(node.Element("High").Value), Low = GetDecimal(node.Element("Low").Value), Close = GetDecimal(node.Element("Close").Value), Volume = GetDecimal(node.Element("Volume").Value), AdjClose = GetDecimal(node.Element("Adj_Close").Value), }; quotes.Add(hq); new Logger().Log(hq); } } }
private void buttonGetQuote_Click(object sender, EventArgs e) { try { string ticker = textBox1.Text; DateTime date = dateTimePicker1.Value; string quoteType = comboBox1.SelectedItem.ToString(); labelOpen.Text = String.Empty; labelClose.Text = String.Empty; labelHigh.Text = String.Empty; labelLow.Text = String.Empty; labelWap.Text = String.Empty; labelVolume.Text = String.Empty; labelMsg.Text = String.Empty; HistoricalQuote quote = proxy.GetQuote(ticker, quoteType, date); labelOpen.Text = String.Format("{0}", quote.Open); labelClose.Text = String.Format("{0}", quote.Close); labelHigh.Text = String.Format("{0}", quote.High); labelLow.Text = String.Format("{0}", quote.Low); labelWap.Text = String.Format("{0}", quote.Wap); labelVolume.Text = String.Format("{0}", quote.Volume); labelMsg.Text = String.Format("{0}", quote.ErrorMessage); } catch (Exception ex) { labelMsg.Text = ex.Message; } }
// TODO: swagger and decimal (https://github.com/Azure/autorest/issues/83) public StochasticData(HistoricalQuote hq) { Date = hq.Date.Value; Open = (decimal)hq.Open.Value; High = (decimal)hq.High.Value; Low = (decimal)hq.Low.Value; Close = (decimal)hq.Close.Value; }
private void BuildHistoricalCacheForInstrument(Instrument InstrumentToCache) { HistoricalQuote oH = new HistoricalQuote(null, null, null); DateTime oDataFromNeeded = DateTime.Now; bool bReadMore = false; bool bAllHistoricalDataNeeded = true; string FullPath = GetFullPathOfHistoricalDataForInstrument(InstrumentToCache); if (File.Exists(FullPath)) { oH = (HistoricalQuote)DeserializeJSON.DeserializeObjectFromFile(FullPath); if (oH == null) { return; } //get the latest date to see if we need to add if (oH.HistoricalQuoteDetails != null && oH.HistoricalQuoteDetails.Count > 0 && (DateTime.Now.Date - oH.HistoricalQuoteDetails.Max(h => h.Date).Date.AddDays(1).Date).Days >= 1) { bReadMore = true; bAllHistoricalDataNeeded = false; oDataFromNeeded = oH.HistoricalQuoteDetails.Max(h => h.Date).Date.AddDays(1).Date; } else { //all is up to date! bAllHistoricalDataNeeded = false; } } if (!bReadMore && bAllHistoricalDataNeeded) { try { oH = GetHistoricalQuoteOnline(InstrumentToCache, m_oCurrentExchange); SerializeJSONdata.SerializeObject(oH, FullPath); } catch (Exception ex) { ImperaturGlobal.GetLog().Error(string.Format("Couldn't retreive and save data for {0}", InstrumentToCache.Symbol), ex); } } else if (bReadMore) { try { HistoricalQuote oHnew = GetHistoricalQuoteOnline(InstrumentToCache, m_oCurrentExchange, oDataFromNeeded); oH.HistoricalQuoteDetails.AddRange(oHnew.HistoricalQuoteDetails.Where(h => h.Date.Date > oDataFromNeeded.Date).ToList()); SerializeJSONdata.SerializeObject(oH, FullPath); } catch (Exception ex) { ImperaturGlobal.GetLog().Error(string.Format("Couldn't retreive and save data for {0}", InstrumentToCache.Symbol), ex); } } }
public static HistoricalQuote GetQuote(string ticker, string quoteType, DateTime date) { HistoricalQuote quote = null; using (Service1 proxy = new Service1()) { quote = proxy.GetQuote(ticker, quoteType, date); } return(quote); }
public async Task TestStart() { var countLoadHistoricalData = 0; var countSaveHistoricalData = 0; var countOnTickerListReceived = 0; var countOnTickerReceived = 0; _moqHist.Setup(d => d.LoadHistoricalData(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>())).Returns <string, int, long, int>((s, i, t, m) => { ++countLoadHistoricalData; return(null); }); _moqHist.Setup(d => d.SaveHistoricalData(It.IsAny <IQuoteBasic>())).Returns <IQuoteBasic>((q) => { ++countSaveHistoricalData; return(true); }); var moqDownload = new Mock <IDownloadQuoteBasic>(); moqDownload.Setup(d => d.Exchange).Returns("Bittrex"); //moqDownload.Setup(d => d.DownloadHistoricalData(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())).Returns<string, int, int>((s, i, t) => //{ // return null; //}); var hist = new HistoricalQuote(_folder, moqDownload.Object, 10000); var socketTicker = new MockSocketTicker(1); _capturer = new QuoteCapturer(_moqHist.Object, socketTicker, 100, 10); _capturer.OnTickerListReceived += (object sender, string exchange, List <CryptoCommon.DataTypes.Ticker> ticker) => { ++countOnTickerListReceived; }; _capturer.OnTickerReceived += (object sender, string exchange, CryptoCommon.DataTypes.Ticker ticker) => { ++countOnTickerReceived; }; _capturer.Start(); await Task.Delay(2000); //since timer interval = 50, there should around 80 OnTickerList events and around 80 elements in quote capture //_capturer.Stop(); var qc = _capturer.GetInMemoryQuoteCapture("A"); var qb = _capturer.GetInMemoryQuoteBasic("A", 60); Assert.IsTrue(countOnTickerListReceived == 1000); Assert.IsTrue(qc.Count > 0);//== countOnTickerListReceived); Assert.IsTrue(qb.Count > 0); Assert.IsTrue(countSaveHistoricalData > 0); }
public HistoricalQuote ProvideQuote(string ticker, string quoteType, DateTime date) { HistoricalQuote quote = new HistoricalQuote() { Ticker = ticker, Date = date }; TWSQuoteObject quoteObject = null; try { if (!Connect()) { quote.ErrorMessage = "Unable to connect to TWS"; } else { lock (m_quoteMapLock) { QuoteType quoteTypeEnum = (QuoteType)Enum.Parse(typeof(QuoteType), quoteType); int requestId = m_twsUtilities.GetHistoricalData(ticker, quoteTypeEnum, null, date); if (requestId < 0) { quote.ErrorMessage = "Unable to get historical quote"; } else { quoteObject = new TWSQuoteObject(requestId); m_quoteMap.Add(requestId, quoteObject); } } } if (quoteObject != null) { if (!m_host.WaitAny(null, quoteObject.WaitHandle)) { quote.ErrorMessage = "Request timed out"; } else { quoteObject.FillQuote(quote); } } } catch (Exception ex) { quote.ErrorMessage = ex.Message; } return(quote); }
public void FillQuote(HistoricalQuote quote) { if (Quote == null) { quote.ErrorMessage = "Internal error: HistoricalDataEventArgs is missing from TWSQuoteObject"; } else { quote.Open = Quote.Open; quote.Close = Quote.Close; quote.High = Quote.High; quote.Low = Quote.Low; quote.Wap = Quote.WAP; quote.Volume = Quote.Volume; quote.ErrorMessage = Quote.ErrorMessage; } }
public void PopulateLatestStockQuotesToHistoricalQuotesPerDay() { lock (Locker) { Task a = new Task(() => { Logger.Debug("Getting LatestStockQuoteInfo"); var tradeDate = DateTime.UtcNow; var lastWriteTime = MarketDataProvider.GetLastWriteTime(); if (lastWriteTime.ToShortDateString() != tradeDate.ToShortDateString()) { Logger.Debug("The show2003 Dbf doesn't change intraday."); return; } var stockQuotesInfo = _uow.StockQuotesInfo.GetAll().ToList(); foreach (var stockQuote in stockQuotesInfo) { var histQuotes = _uow.HistoricalQuotes.GetAll().Where(m => m.StockCode == stockQuote.SecurityCode).ToList(); if (histQuotes.Count > 0) { var latestQuote = histQuotes.OrderByDescending(m => m.TradeDate).First(); if (latestQuote.TradeDate < tradeDate) { HistoricalQuote historicalQuote = Mapper.Map <StockQuoteInfo, HistoricalQuote>(stockQuote); historicalQuote.Id = new MongoDB.Bson.ObjectId(); historicalQuote.TradeDate = tradeDate; _uow.HistoricalQuotes.Add(historicalQuote); } } else { HistoricalQuote historicalQuote = Mapper.Map <StockQuoteInfo, HistoricalQuote>(stockQuote); historicalQuote.Id = new MongoDB.Bson.ObjectId(); historicalQuote.TradeDate = tradeDate; _uow.HistoricalQuotes.Add(historicalQuote); } } Logger.Debug("PopulateLatestStockQuotesToHistoricalQuotesPerDay Completed"); }); a.Start(); Task.WaitAll(a); } }
public static void CreateInsertObject(HistoricalQuote historicalQuote) { var ds = new DataSet(); string commandString = "insert into quote("; commandString += HistoricalQuoteTable.Symbol + ','; commandString += HistoricalQuoteTable.Date + ','; commandString += HistoricalQuoteTable.Open + ','; commandString += HistoricalQuoteTable.High + ','; commandString += HistoricalQuoteTable.Low + ','; commandString += HistoricalQuoteTable.Close + ','; commandString += HistoricalQuoteTable.Volume + ','; commandString += HistoricalQuoteTable.AdjClose; commandString += ") values ("; commandString += ':' + HistoricalQuoteTable.Symbol + ','; commandString += ':' + HistoricalQuoteTable.Date + ','; commandString += ':' + HistoricalQuoteTable.Open + ','; commandString += ':' + HistoricalQuoteTable.High + ','; commandString += ':' + HistoricalQuoteTable.Low + ','; commandString += ':' + HistoricalQuoteTable.Close + ','; commandString += ':' + HistoricalQuoteTable.Volume + ','; commandString += ':' + HistoricalQuoteTable.AdjClose; commandString += ")"; var da = new NpgsqlDataAdapter("select * from historicalquote", Connection) { InsertCommand = new NpgsqlCommand(commandString, Connection) }; da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.Symbol, DbType.String)); da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.Date, DbType.DateTime)); da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.Open, DbType.Single)); da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.High, DbType.Single)); da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.Low, DbType.Single)); da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.Close, DbType.Single)); da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.Volume, DbType.Single)); da.InsertCommand.Parameters.Add(new NpgsqlParameter(HistoricalQuoteTable.AdjClose, DbType.Single)); foreach (NpgsqlParameter p in da.InsertCommand.Parameters) { p.Direction = ParameterDirection.Input; } da.InsertCommand.Parameters[0].SourceColumn = HistoricalQuoteTable.Symbol; da.InsertCommand.Parameters[1].SourceColumn = HistoricalQuoteTable.Date; da.InsertCommand.Parameters[2].SourceColumn = HistoricalQuoteTable.Open; da.InsertCommand.Parameters[3].SourceColumn = HistoricalQuoteTable.High; da.InsertCommand.Parameters[4].SourceColumn = HistoricalQuoteTable.Low; da.InsertCommand.Parameters[5].SourceColumn = HistoricalQuoteTable.Close; da.InsertCommand.Parameters[6].SourceColumn = HistoricalQuoteTable.Volume; da.InsertCommand.Parameters[7].SourceColumn = HistoricalQuoteTable.AdjClose; da.Fill(ds); DataTable dt = ds.Tables[0]; DataRow dr = dt.NewRow(); MapFields(dr, HistoricalQuoteTable.Symbol, historicalQuote.Symbol); MapFields(dr, HistoricalQuoteTable.Date, historicalQuote.Date); MapFields(dr, HistoricalQuoteTable.Open, historicalQuote.Open); MapFields(dr, HistoricalQuoteTable.High, historicalQuote.High); MapFields(dr, HistoricalQuoteTable.Low, historicalQuote.Low); MapFields(dr, HistoricalQuoteTable.Close, historicalQuote.Close); MapFields(dr, HistoricalQuoteTable.Volume, historicalQuote.Volume); MapFields(dr, HistoricalQuoteTable.AdjClose, historicalQuote.AdjClose); dt.Rows.Add(dr); DataSet ds2 = ds.GetChanges(); if (ds2 != null) { da.Update(ds2); ds.Merge(ds2); } ds.AcceptChanges(); }
public SecurityAnalysis(Instrument Instrument) { m_oH = ImperaturGlobal.HistoricalQuote(Instrument); m_oED = new ElliottWaveDefinition(); m_oCache = new List <Tuple <DateTime, List <HistoricalQuoteDetails>, int> >(); }