public void Test_Serialization() { IStockDataDataSource stockDataDataSource = new ReutersDataSource(); IPricesDataSource pricesDataSource = new YahooDataSource(); IOptionChainDataSource optionChainDataSource = new NasdaqDataSource(); IFinancialDataSource financialDataSource = new NasdaqDataSource(); IRiskFreeRatesDataSource riskFreeRatesDataSource = null; IAssetTypeDataSource assetTypeDataSource = null; IStatisticsDataSource statisticsDataSource = null; IIndexesDataSource indexesDataSource = null; ICacheManager cacheManager = new FileCacheManager(); IDataSource dataSource = new DataSourceDispatcher(stockDataDataSource, pricesDataSource, optionChainDataSource, financialDataSource, riskFreeRatesDataSource, assetTypeDataSource, statisticsDataSource, indexesDataSource, cacheManager); bool ok = dataSource.TryGetCompleteAssetData("AAPL", Common.Entities.Exchange.NASDAQ, AssetClass.Stock, true, true, out AssetBase asset, out string message); Assert.IsTrue(ok); string json = JsonConvert.SerializeObject(asset); AssetBase a = JsonConvert.DeserializeObject <AssetBase>(json); }
private async Task CoreRunAsync(IHistoricalDataWaitingEntry entry, StockPriceHistoryInsertion insertion, CancellationToken token) { DateTime start = DateTime.Now; WriteToWorkerLog($"Start {entry.StockId}"); if (token.IsCancellationRequested) { return; } IReadOnlyList <IStockQuoteFromDataSource> records = await YahooDataSource.GetHistoricalQuotesAsync(entry.Country.ConvertToTTStockQuoteSourceCountry(), entry.StockId, entry.DataStartDate, entry.DataEndDate, WriteToErrorLog) .ConfigureAwait(false); if (records == null || records.Count == 0) { WriteToWorkerLog($"Data source returned NULL historical data of {entry.Country.GetShortName()}.{entry.StockId}"); return; } foreach (IStockQuoteFromDataSource record in records) { if (token.IsCancellationRequested) { return; } // insert records into database await insertion.InsertToDatabase(record).ConfigureAwait(false); } await DatabaseOperations.SetWaitingEntryToDoneAsync(entry.Country, entry.StockId).ConfigureAwait(false); TimeSpan timeSpan = DateTime.Now - start; WriteToWorkerLog($"Finish {entry.Country.GetShortName()}.{entry.StockId}. Total time = {timeSpan.TotalSeconds} seconds"); }