Exemplo n.º 1
0
        public bool TryGetStockSummary(string ticker, Exchange?exchange, AssetClass assetType, out Stock asset, out string errorMessage)
        {
            //https://api.nasdaq.com/api/quote/TQQQ/info?assetclass=etf
            //https://api.nasdaq.com/api/quote/AAPL/info?assetclass=stocks
            bool ok = NasdaqApiCaller.GetStockSummary(ticker, exchange, assetType, out HttpStatusCode statusCode, out NasdaqResponse nasdaqResponse, out string jsonResponse, out errorMessage);

            throw new NotImplementedException();
        }
Exemplo n.º 2
0
        public bool TryGetFinancialData(string ticker, Exchange?exchange, out FinancialStatements financialData, out string errorMessage)
        {
            //Example
            //https://api.nasdaq.com/api/company/AAPL/financials?frequency=1
            bool    ok      = NasdaqApiCaller.GetFinancialData(ticker, out string jsonResponse, out errorMessage);
            dynamic rawdata = JsonConvert.DeserializeObject(jsonResponse);

            throw new NotImplementedException();
        }
Exemplo n.º 3
0
        public bool TryGetOptionsChain(string ticker, Exchange?exchange, out OptionsChain optionChain, out string errorMessage)
        {
            DateTime from = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime to   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, GetLastDay(DateTime.Now.Month)).AddYears(3);
            bool     ok   = NasdaqApiCaller.GetOptionChain(ticker, from, to, out string jsonResponse, out errorMessage);

            optionChain = new OptionsChain();
            NasdaqResponse nasdaqResponse = JsonConvert.DeserializeObject <NasdaqResponse>(jsonResponse);

            foreach (var optionRow in nasdaqResponse.Data.OptionChainList.Rows)
            {
                if (optionRow.Call != null)
                {
                    var    call = optionRow.Call;
                    Option o    = new Option(OptionClass.Call, call.Symbol)
                    {
                        LastPrice      = call.Last.ToNullableDecimal(),
                        Strike         = call.Strike.ToDouble(-1),
                        ExpirationDate = call.ExpiryDate.ToDateTime(),
                    };

                    o.LastPrice    = call.Last.ToNullableDecimal();
                    o.Change       = call.Change.ToNullableDouble();
                    o.Bid          = call.Bid.ToNullableDouble();
                    o.Ask          = call.Ask.ToNullableDouble();
                    o.Volume       = call.Volume.ToNullableInt();
                    o.OpenInterest = call.Openinterest.ToNullableInt();

                    optionChain.Add(o);
                }

                if (optionRow.Put != null)
                {
                    var    put = optionRow.Put;
                    Option o   = new Option(OptionClass.Put, put.Symbol)
                    {
                        LastPrice      = put.Last.ToNullableDecimal(),
                        Strike         = put.Strike.ToDouble(-1),
                        ExpirationDate = put.ExpiryDate.ToDateTime(),
                    };
                    o.LastPrice    = put.Last.ToNullableDecimal();
                    o.Change       = put.Change.ToNullableDouble();
                    o.Bid          = put.Bid.ToNullableDouble();
                    o.Ask          = put.Ask.ToNullableDouble();
                    o.Volume       = put.Volume.ToNullableInt();
                    o.OpenInterest = put.Openinterest.ToNullableInt();

                    optionChain.Add(o);
                }
            }

            errorMessage = "ok";
            return(true);
        }
Exemplo n.º 4
0
        public bool TryGetLastPrice(string ticker, Exchange?exchange, AssetClass assetType, out HistoricalPrice lastPrice, out string message)
        {
            //https://api.nasdaq.com/api/quote/TQQQ/info?assetclass=etf
            //https://api.nasdaq.com/api/quote/AAPL/info?assetclass=stocks
            bool ok = NasdaqApiCaller.GetStockSummary(ticker, exchange, assetType, out HttpStatusCode statusCode, out NasdaqResponse nasdaqResponse, out string jsonResponse, out message);

            if (statusCode == HttpStatusCode.OK)
            {
                if (nasdaqResponse.Status.Code == 200)
                {
                    string temp = nasdaqResponse.Data.PrimaryData.LastSalePriceAsString;
                    lastPrice       = new HistoricalPrice();
                    lastPrice.Close = decimal.Parse(temp.Substring(1), ConvertionsExtensions.EnUs_CultureInfo);
                    temp            = nasdaqResponse.Data.PrimaryData.LastTradeTimestampAsString;
                    lastPrice.Date  = ParseDateTime(temp);

                    /*
                     * temp = rawdata.data.keyStats.Volume.value.ToString();
                     * lastPrice.Volume = int.Parse(temp, NumberStyles.Integer | NumberStyles.AllowThousands, enUsCultureInfo);
                     * temp = rawdata.data.keyStats.PreviousClose.value.ToString();
                     * lastPrice.PreviousClose = decimal.Parse(temp.Substring(1), enUsCultureInfo);
                     */

                    return(true);
                }
                else if (nasdaqResponse.Status.Code == 400 && nasdaqResponse.Status.CodeMessage.Count > 0)
                {
                    lastPrice = null;
                    var nasdaqMessage = nasdaqResponse.Status.CodeMessage[0];
                    message = $"{nasdaqMessage.ErrorMessage} (Code={nasdaqMessage.Code})";
                    return(false);
                }
            }
            lastPrice = null;
            return(false);
        }
Exemplo n.º 5
0
        public bool TryGetHistoricalPrices(string ticker, Exchange?exchange, DateTime?from, DateTime?to, PriceInterval interval, out PriceList prices, out string errorMessage)
        {
            //https://api.nasdaq.com/api/quote/AAPL/chart?assetclass=stocks&fromdate=2010-04-15&todate=2020-04-15
            if (from.HasValue == false)
            {
                from = DateTime.Now;
            }

            if (to.HasValue == false)
            {
                to = DateTime.Now;
            }

            bool ok = NasdaqApiCaller.GetPrices(ticker, exchange, from.Value, to.Value, interval, out HttpStatusCode statusCode, out NasdaqResponse nasdaqResponse, out string jsonResponse, out errorMessage);

            prices = new PriceList();
            foreach (var nasdaqPrice in nasdaqResponse.Data.Prices)
            {
                HistoricalPrice price = new HistoricalPrice();
                price.Close = nasdaqPrice.Price;
                prices.Add(price);
            }
            return(true);
        }