Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i get P/E ratio of a stock? #96

Closed
AlexRajvandary opened this issue Feb 4, 2021 · 7 comments
Closed

How can i get P/E ratio of a stock? #96

AlexRajvandary opened this issue Feb 4, 2021 · 7 comments
Labels
bug Either the bug, or the bug fix

Comments

@AlexRajvandary
Copy link

I tried this:
string ticker = "appl"// for example
IEXCloudClient client = new new IEXCloudClient(.....);
var stock = await client.StockFundamentals.AdvancedFundamentalsAsync(ticker);

why stock is null?

@vslee
Copy link
Owner

vslee commented Feb 4, 2021

Try using AAPL instead of APPL

@vslee vslee added the question Posing a question rather than a bug label Feb 4, 2021
@AlexRajvandary
Copy link
Author

Still null

@AlexRajvandary
Copy link
Author

class Program
{
private static string public_token ="";
private static string private_token = "";
static async void GetStock(string ticker,IEXCloudClient client)
{
var stock = await client.StockFundamentals.AdvancedFundamentalsAsync(ticker);
Console.WriteLine(stock.Data.symbol);

    }
   
    static void Main(string[] args)
    {
        string ticker = "AAPL";
        public_token = File.ReadAllText("public_token.txt");
        private_token = File.ReadAllText("private_token.txt");

     

        IEXCloudClient client = new IEXCloudClient(public_token, private_token, false, false);
      
        GetStock(ticker, client);

        Console.ReadKey();

    }
}

}

System.NullReferenceException

@JamiePrentice
Copy link
Collaborator

JamiePrentice commented Feb 4, 2021

@AlexRajvandary, you appear to be trying to access https://iexcloud.io/docs/api/#advanced-fundamentals, and endpoint that is only available with paid IEX Cloud plans. I think this could be your problem.

Failing that, you could log out error messages to help identify the issue by modifying your existing code like so:

static async void GetStock(string ticker, IEXCloudClient client)
{
    IEXResponse<AdvancedFundamentalsResponse> iexResponse = 
                               await client.StockFundamentals.AdvancedFundamentalsAsync(ticker);
    if (iexResponse.ErrorMessage != null)
    {
        Console.WriteLine(iexResponse.ErrorMessage);
        return;
    }
    
    Console.WriteLine(iexResponse.Data.symbol);
}

@vslee vslee closed this as completed in 4be2db2 Feb 4, 2021
@vslee vslee added bug Either the bug, or the bug fix and removed question Posing a question rather than a bug labels Feb 4, 2021
@vslee
Copy link
Owner

vslee commented Feb 4, 2021

Looks like there was a bug in our code, where AdvancedFundamentals returns an array and not a single value.
But unrelated to that bug, it looks like IEX Cloud does not return anything for many companies when the period is set to Quarter instead of Annual. So you can try it again, but modify your code to be:

            var stock = await client.StockFundamentals.AdvancedFundamentalsAsync(ticker, IEXSharp.Model.Shared.Request.Period.Annual);

Make sure you use the latest prerelease or wait for the next official NuGet.

@JamiePrentice
Copy link
Collaborator

@vslee huh, not the angle I went for, but good catch on that, you're right.

@vslee
Copy link
Owner

vslee commented Feb 4, 2021

@JamiePrentice I liked where you were going with teaching people how to help us w/ error messages though.
And also that some data is not available to the lower plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Either the bug, or the bug fix
Projects
None yet
Development

No branches or pull requests

3 participants