示例#1
0
        private static void RequestStocks(string apiKey)
        {
            AvStockProvider provider     = new AvStockProvider(apiKey);
            var             sgoDailyData = provider.RequestDaily("SGO.PA", true);

            log.Info(sgoDailyData);
            var sgoWeeklyData = provider.RequestWeekly("SGO.PA");

            log.Info(sgoWeeklyData);
            var sgoMonthlyData = provider.requestMonthly("SGO.PA");

            log.Info(sgoMonthlyData);

            IDictionary <string, StockRealtime> batchData = provider.BatchRequest(new string[] { "MSFT", "IBM", "AAPL" });

            log.Info("Batch Request for MSFT, IBM and AAPL");
            foreach (var kvp in batchData)
            {
                log.InfoFormat("{0} : Price = {1}, Volume = {2}, Date = {3}", kvp.Key, kvp.Value.Price, kvp.Value.Volume, kvp.Value.Timestamp);
            }
            AvStockRequestManager requestManager = new AvStockRequestManager(provider);

            string[] stocks = new string[] { "SGO.PA", "GLE.PA", "BNP.PA", "VIV.PA", "RNO.PA", "CS.PA" };
            requestManager.Start();
            requestManager.Delay = 4000;
            foreach (var stock in stocks)
            {
                requestManager.Add(StockRequestType.Daily, stock, Callback);
                requestManager.Add(StockRequestType.Weekly, stock, Callback);
                requestManager.Add(StockRequestType.Monthly, stock, Callback);
            }
            requestManager.Stop(true);
        }
示例#2
0
        protected override void Execute(StockRequestData requestData)
        {
            var requestType = requestData.Item1;
            var symbol = requestData.Item2;
            var callback = requestData.Item3;

            try
            {
                switch (requestType)
                {
                    case StockRequestType.Daily:
                    case StockRequestType.DailyFull:
                    case StockRequestType.DailyAdjusted:
                    case StockRequestType.DailyAdjustedFull:
                        bool full = (requestType == StockRequestType.DailyFull || requestType == StockRequestType.DailyAdjustedFull);
                        var stockData = _avStcokProvider.RequestDaily(symbol, full);
                        callback(requestType, symbol, stockData);
                        break;
                    case StockRequestType.Weekly:
                    case StockRequestType.WeeklyAdjusted:
                        callback(requestType, symbol, _avStcokProvider.RequestWeekly(symbol));
                        break;
                    case StockRequestType.Monthly:
                    case StockRequestType.MonthlyAdjusted:
                        callback(requestType, symbol, _avStcokProvider.requestMonthly(symbol));
                        break;
                }
                ResetDelay();
            }
            catch (HighUsageException e)
            {
                if (CanRetry()) ReExecute(requestData);
                else
                {
                    log.ErrorFormat("Max retry count reached => Failed to execute request {0}/{1}",
                        requestType, symbol);
                    ResetDelay();
                }
            }

        }