Beispiel #1
0
        public async Task <ActionResult <string> > Put(string id, [FromBody] string value)
        {
            StockDataHandler handler = new StockDataHandler();
            StockSymbol      data    = await handler.UpsertStockDataAsync(id);

            return(JsonConvert.SerializeObject(data));
        }
Beispiel #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((StockSymbol != null ? StockSymbol.GetHashCode() : 0) * 397) ^ LastDividend.GetHashCode());
     }
 }
        private static IEnumerable <double> GetPrices(StockSymbol stockSymbol, PriceType[] priceTypes)
        {
            if (!priceTypes.Any())
            {
                return(new[] { stockSymbol.Open, stockSymbol.Close, stockSymbol.High, stockSymbol.Low });
            }

            List <double> prices = new List <double>();

            if (priceTypes.Contains(PriceType.Open))
            {
                prices.Add(stockSymbol.Open);
            }
            if (priceTypes.Contains(PriceType.Close))
            {
                prices.Add(stockSymbol.Close);
            }
            if (priceTypes.Contains(PriceType.High))
            {
                prices.Add(stockSymbol.High);
            }
            if (priceTypes.Contains(PriceType.Low))
            {
                prices.Add(stockSymbol.Low);
            }

            return(prices);
        }
Beispiel #4
0
        public async Task <ActionResult <string> > Get(string id)
        {
            StockDataHandler handler = new StockDataHandler();
            StockSymbol      symbol  = await handler.GetStockDataAsync(id, new TimeSpan(7, 0, 0, 0));

            return(JsonConvert.SerializeObject(symbol));
        }
Beispiel #5
0
        public Task UpdateStockAsync(StockSymbol Symbol)
        {
            FilterDefinition <StockSymbol> filter = Builders <StockSymbol> .Filter.Eq("Symbol", Symbol.Symbol);

            IMongoCollection <StockSymbol> collection = _database.GetCollection <StockSymbol>(_stockCollectionName);

            return(collection.ReplaceOneAsync(filter, Symbol));
        }
Beispiel #6
0
        public void AddStock(StockSymbol Symbol)
        {
            Symbol.Added = DateTime.UtcNow;

            IMongoCollection <StockSymbol> collection = _database.GetCollection <StockSymbol>(_stockCollectionName);

            collection.InsertOne(Symbol);
        }
Beispiel #7
0
        public StockSymbol GetStock(FilterDefinition <StockSymbol> Filter)
        {
            IMongoCollection <StockSymbol> collection = _database.GetCollection <StockSymbol>(_stockCollectionName);

            StockSymbol result = collection.Find(Filter).FirstOrDefault();

            return(result);
        }
        public void Set(string symbol)
        {
            Console.WriteLine("set: name=" + symbol);

            // I don't even...
            // WTF: http://stackoverflow.com/questions/28031832/how-can-i-reload-the-data-in-a-watchkit-tableview
            StockSymbol.SetText(@"");             // this fixes the issue I was having :-\
            StockSymbol.SetText(symbol);
        }
Beispiel #9
0
 public Stock(StockSymbol stockSymbol, StockType stockType, double lastDividend, double fixedDividend, double parValue, double price)
 {
     this.StockSymbol   = stockSymbol;
     this.StockType     = stockType;
     this.LastDividend  = lastDividend;
     this.FixedDividend = fixedDividend;
     this.ParValue      = parValue;
     this.Price         = price;
 }
Beispiel #10
0
        public ActionResult AddStockSymbol(StockSymbol symbol)
        {
            if (ModelState.IsValid && _stockSymbolService.SaveStockSymbol(symbol))
            {
                return(RedirectToAction("StockSymbols"));
            }

            return(View(symbol));
        }
Beispiel #11
0
 void Upsert(StockSymbol symbol)
 {
     if (symbol._id == ObjectId.Empty)
     {
         _symbols.InsertOne(symbol);
     }
     else
     {
         _symbols.ReplaceOne(x => x.Symbol == symbol.Symbol, symbol);
     }
 }
Beispiel #12
0
        public ActionResult DeleteStockSymbol(List <Guid> ids)
        {
            if (ModelState.IsValid && _stockSymbolService.DeleteStockSymbol(ids))
            {
                return(RedirectToAction("StockSymbols"));
            }

            StockSymbol symbol = new StockSymbol();

            return(View(symbol));
        }
Beispiel #13
0
        public ActionResult <IEnumerable <string> > Get()
        {
            StockDataHandler handler = new StockDataHandler();
            //handler.UpsertStockData("MSFT");
            StockSymbol symbol = handler.GetStockData("MSFT");

            if (symbol == null)
            {
                return new string[] { "null", "value2" }
            }
            ;
            return(new string[] { symbol.Symbol, "value2" });
        }
Beispiel #14
0
        public ActionResult FilterIndex(string symbol, string range)
        {
            if (symbol == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //StocksData sd = new StocksData();
            //sd.GetDataPerSymbol(symbol);
            ViewBag.Range  = range;
            ViewBag.Symbol = symbol;
            //return View(db.Stocks.ToList().Where(s => s.Symbol == symbol));
            StockSymbol stock = db.StockSymbols.Where(s => s.Symbol == symbol).FirstOrDefault();

            return(View(stock));
        }
Beispiel #15
0
        public override bool Equals(object obj)
        {
            var stock2 = obj as Stock;

            if (stock2 == null)
            {
                return(false);
            }

            if (StockSymbol == null)
            {
                return(false);
            }

            return(StockSymbol.Equals(stock2.StockSymbol));
        }
Beispiel #16
0
        public async Task <StockSymbol> FindStock(string name, string symbol)
        {
            List <StockSymbol> stockList = await LoadSymbols();

            StockSymbol stockSymbol = new StockSymbol();

            foreach (StockSymbol stockItem in stockList)
            {
                if (stockItem.Name == name || stockItem.Symbol == symbol)
                {
                    stockSymbol = stockItem;
                }
            }

            return(stockSymbol);
        }
Beispiel #17
0
        public async Task <StockSymbol> GetStockSymbolDataAsync(FilterDefinition <StockSymbol> Filter, FilterDefinition <StockValue> DataFilter)
        {
            IMongoCollection <StockSymbol> collection = _database.GetCollection <StockSymbol>(_stockCollectionName);

            StockSymbol symbol = await collection.Find(Filter).FirstOrDefaultAsync();

            if (symbol != default(StockSymbol))
            {
                IMongoCollection <StockValue> dataCollection = _database.GetCollection <StockValue>(_stockDataCollectionName);
                FilterDefinition <StockValue> dataFilter     =
                    (
                        Builders <StockValue> .Filter.Eq("ParentId", symbol.Id) &
                        DataFilter
                    );
                symbol.Values = await dataCollection.Find(dataFilter).ToListAsync();
            }
            return(symbol);
        }
        protected override void Execute(CodeActivityContext context)
        {
            DateTime startLookup = DateTime.Now;

            string symbol = StockSymbol.Get(context);
            double price  = knownSymbols[symbol];

            Value.Set(context, price);

            DateTime endLookup = DateTime.Now;

            TimeSpan             lookupTime = endLookup - startLookup;
            CustomTrackingRecord userRecord = new CustomTrackingRecord("QuoteLookupEvent");

            userRecord.Data.Add("LookupTime", lookupTime.TotalMilliseconds);
            userRecord.Data.Add("Units", "Milliseconds");
            context.Track(userRecord);
        }
        private static StockSymbolStatistics CreateStatistics(StockSymbol symbol, PriceType[] priceTypes)
        {
            List <double> prices = GetPrices(symbol, priceTypes).ToList();

            return(new StockSymbolStatistics
            {
                Name = symbol.Name,
                Date = symbol.Date,
                Min = prices.Min(p => p),
                Avg = prices.Average(p => p),
                Max = prices.Max(p => p),
                Median = prices.Percentile(0.5),
                Percentile95 = prices.Percentile(0.95),
                Open = symbol.Open,
                Close = symbol.Close,
                High = symbol.High,
                Low = symbol.Low
            });
        }
Beispiel #20
0
        public async Task <StockSymbol> UpsertStockDataAsync(String Symbol)
        {
            StockSymbol symbol = GetStockData(Symbol);

            if (symbol == null)
            {
                symbol = new StockSymbol()
                {
                    Symbol = Symbol
                };
                _repository.AddStock(symbol);
            }
            StockDataUpdater updater = new StockDataUpdater(_repository);

            symbol = await updater.UpdateStockSymbolDataAsync(symbol);

            await _repository.UpdateStockAsync(symbol);

            return(symbol);
        }
Beispiel #21
0
        public ActionResult AddStockSymbol()
        {
            StockSymbol symbol = new StockSymbol();

            return(View(symbol));
        }
 internal static string Name(this StockSymbol _this)
 {
     return(Enum.GetName(typeof(StockSymbol), (int)_this).Replace('_', '.').ToLower());
 }
 public void UpdateStockSymbolData(StockSymbol Symbol)
 {
     throw new NotImplementedException();
 }
        public async Task <StockSymbol> UpdateStockSymbolDataAsync(StockSymbol Symbol)
        {
            //String baseUrl = null;
            String apiKey = null;

            try
            {
                //baseUrl = _config.Configuration["AlphavantageBaseUrl"];
                apiKey = _config.Configuration["AlphavantageApiKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
            if (String.IsNullOrWhiteSpace(apiKey))
            {
                throw new Exception("AlphavantageApiKey null or empty!");
            }

            AlphaVantageCoreClient      client = new AlphaVantageCoreClient();
            Dictionary <string, string> query  = new Dictionary <string, string>()
            {
                { "symbol", Symbol.Symbol },
                { "interval", "5min" },
                { "outputsize", "full" }
            };

            JObject result = await client.RequestApiAsync(apiKey, ApiFunction.TIME_SERIES_INTRADAY, query);

            DateTime lastRefresh    = Symbol.LastRefresh ?? DateTime.MinValue;
            string   timeZoneString = (string)result["Meta Data"]["6. Time Zone"];

            //TODO: Move elsewhere
            if ("US/Eastern".Equals(timeZoneString))
            {
                timeZoneString = "US Eastern Standard Time";
            }
            TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneString);

            Symbol.Values = new List <StockValue>();
            List <Task> waitingTasks = new List <Task>();

            foreach (JObject timeSerie in result["Time Series (5min)"].Values())
            {
                JProperty prop           = (JProperty)timeSerie.Parent;
                String    timestampProp  = prop.Name;
                DateTime  localTimeStamp = DateTime.ParseExact(timestampProp, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                DateTime  utcTimeStamp   = TimeZoneInfo.ConvertTimeToUtc(localTimeStamp, timeZone);

                if (utcTimeStamp < lastRefresh)
                {
                    continue;
                }

                StockValue value = new StockValue()
                {
                    TimeStamp = utcTimeStamp,
                    Open      = Decimal.Parse(timeSerie.Value <string>("1. open")),
                    High      = Decimal.Parse(timeSerie.Value <string>("2. high")),
                    Low       = Decimal.Parse(timeSerie.Value <string>("3. low")),
                    Close     = Decimal.Parse(timeSerie.Value <string>("4. close")),
                    Volume    = Decimal.Parse(timeSerie.Value <string>("5. volume")),
                    ParentId  = Symbol.Id
                };

                Symbol.Values.Add(value);

                waitingTasks.Add(_repository.AddStockSymbolDataAsync(value));
                if (waitingTasks.Count > 4)
                {
                    int i = Task.WaitAny(waitingTasks.ToArray());
                    waitingTasks.RemoveAt(i);
                }
            }
            Task.WaitAll(waitingTasks.ToArray());
            waitingTasks.Clear();

            DateTime localRefresh = DateTime.ParseExact((string)result["Meta Data"]["3. Last Refreshed"], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

            Symbol.LastRefresh = TimeZoneInfo.ConvertTimeToUtc(localRefresh, timeZone);

            return(Symbol);
        }
Beispiel #25
0
 public IActionResult Put(string symbol, [FromBody] StockSymbol update)
 {
     update.Symbol = symbol;
     Upsert(update);
     return(Ok());
 }
Beispiel #26
0
 public IActionResult Post([FromBody] StockSymbol symbol)
 {
     Upsert(symbol);
     return(Ok());
 }
Beispiel #27
0
 public async Task <FundHistory> GetFundHistoryAsync(StockSymbol symbol, DateTime startDate, DateTime endDate)
 {
     return(await GetFundHistoryAsync(symbol.Name(), startDate, endDate));
 }
Beispiel #28
0
 public FundHistory GetFundHistory(StockSymbol symbol, DateTime startDate, DateTime endDate)
 {
     return(GetFundHistory(symbol.Name(), startDate, endDate));
 }
Beispiel #29
0
 public FundData GetFund(StockSymbol symbol)
 {
     return(GetFund(symbol.Name()));
 }
Beispiel #30
0
 public async Task <FundData> GetFundAsync(StockSymbol symbol)
 {
     return(await GetFundAsync(symbol.Name()));
 }
    private void FixupStockSymbol2(StockSymbol previousValue)
    {
        if (IsDeserializing)
        {
            return;
        }

        if (previousValue != null && ReferenceEquals(previousValue.StockSymbol1, this))
        {
            previousValue.StockSymbol1 = null;
        }

        if (StockSymbol2 != null)
        {
            StockSymbol2.StockSymbol1 = this;
            ID = StockSymbol2.ID;
        }

        if (ChangeTracker.ChangeTrackingEnabled)
        {
            if (ChangeTracker.OriginalValues.ContainsKey("StockSymbol2")
                && (ChangeTracker.OriginalValues["StockSymbol2"] == StockSymbol2))
            {
                ChangeTracker.OriginalValues.Remove("StockSymbol2");
            }
            else
            {
                ChangeTracker.RecordOriginalValue("StockSymbol2", previousValue);
            }
            if (StockSymbol2 != null && !StockSymbol2.ChangeTracker.ChangeTrackingEnabled)
            {
                StockSymbol2.StartTracking();
            }
        }
    }
    private void FixupStockSymbol1(StockSymbol previousValue)
    {
        // This is the principal end in an association that performs cascade deletes.
        // Update the event listener to refer to the new dependent.
        if (previousValue != null)
        {
            ChangeTracker.ObjectStateChanging -= previousValue.HandleCascadeDelete;
        }

        if (StockSymbol1 != null)
        {
            ChangeTracker.ObjectStateChanging += StockSymbol1.HandleCascadeDelete;
        }

        if (IsDeserializing)
        {
            return;
        }

        if (previousValue != null && ReferenceEquals(previousValue.StockSymbol2, this))
        {
            previousValue.StockSymbol2 = null;
        }

        if (StockSymbol1 != null)
        {
            StockSymbol1.StockSymbol2 = this;
        }

        if (ChangeTracker.ChangeTrackingEnabled)
        {
            if (ChangeTracker.OriginalValues.ContainsKey("StockSymbol1")
                && (ChangeTracker.OriginalValues["StockSymbol1"] == StockSymbol1))
            {
                ChangeTracker.OriginalValues.Remove("StockSymbol1");
            }
            else
            {
                ChangeTracker.RecordOriginalValue("StockSymbol1", previousValue);
                // This is the principal end of an identifying association, so the dependent must be deleted when the relationship is removed.
                // If the current state of the dependent is Added, the relationship can be changed without causing the dependent to be deleted.
                if (previousValue != null && previousValue.ChangeTracker.State != ObjectState.Added)
                {
                    previousValue.MarkAsDeleted();
                }
            }
            if (StockSymbol1 != null && !StockSymbol1.ChangeTracker.ChangeTrackingEnabled)
            {
                StockSymbol1.StartTracking();
            }
        }
    }
Beispiel #33
0
    private void FixupStockSymbol(StockSymbol previousValue)
    {
        if (IsDeserializing)
        {
            return;
        }

        if (previousValue != null && previousValue.StockFiles.Contains(this))
        {
            previousValue.StockFiles.Remove(this);
        }

        if (StockSymbol != null)
        {
            if (!StockSymbol.StockFiles.Contains(this))
            {
                StockSymbol.StockFiles.Add(this);
            }

            StockId = StockSymbol.ID;
        }
        if (ChangeTracker.ChangeTrackingEnabled)
        {
            if (ChangeTracker.OriginalValues.ContainsKey("StockSymbol")
                && (ChangeTracker.OriginalValues["StockSymbol"] == StockSymbol))
            {
                ChangeTracker.OriginalValues.Remove("StockSymbol");
            }
            else
            {
                ChangeTracker.RecordOriginalValue("StockSymbol", previousValue);
            }
            if (StockSymbol != null && !StockSymbol.ChangeTracker.ChangeTrackingEnabled)
            {
                StockSymbol.StartTracking();
            }
        }
    }