Android Question Using alpha vantage api from b4a

shb777

Active Member
Licensed User
Longtime User
I want to use Alpha Vantage API to get stock quotes. I got a api key and was able to download a csv
using this code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim job1 As HttpJob
    
    
    Activity.LoadLayout("main")
    
    sf.Initialize
    
    job1.Initialize("Job1", Me)
    job1.Download("https://www.google.com")
    
    
    
    
    job3.Initialize("Job3", Me)
    
    
    job3.Download("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo&datatype=csv")
    
    
    
End Sub


But I don't know how to use the API from B4A. Do I need to use Java Objects, or do I need a library or what?

I found this https://github.com/zackurben/alphavantage on GITHUB. Steve
 

DonManfred

Expert
Licensed User
Longtime User
it returns a csv data.... You can use the b4a methods to parse the data. It is just text



Where is the problem?
 
Upvote 0

shb777

Active Member
Licensed User
Longtime User
that csv doesn't have the information i want. i want the value of stocks given they're symbols like FB, AAPL, AMZN
 
Upvote 0

shb777

Active Member
Licensed User
Longtime User
I just did it as an example of getting data from their api. It's not the data I want. I don't even know what it is. I looked at their documentation but I can't figure out how to use it it B4A.

What I want to do is pass their api a stock symbol, and get the stock price.


Steve
 
Upvote 0

shb777

Active Member
Licensed User
Longtime User
This question is sort of related. I'm running this code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim job1 As HttpJob
    
    
    Activity.LoadLayout("main")
    
    sf.Initialize
    
    job1.Initialize("Job1", Me)
    job1.Download("https://www.google.com")
    
    
    
    
    job3.Initialize("Job3", Me)

    job3.Download("http://online.wsj.com/public/resources/documents/Nasdaq.csv")
    
    
    job4.Initialize("Job4", Me)
    job4.Download("http://online.wsj.com/Public/resources/documents/NYSE.csv")
    
End Sub


this is what I get from the log:


JobName = Job4, Success = false
Error: Not Found
JobName = Job1, Success = true
JobName = Job3, Success = true


So job4 is failing every time, even though when I type it into the browser, it works.
 
Upvote 0

shb777

Active Member
Licensed User
Longtime User
I found out in my code, somehow the word public in the address got capitalized, even though I cut and paste it from my browser. when I changed it to lower case p it works. Thanks Manfred


PS I have a picture of my program working, but I can't insert it into this post. very frustrating! the picture filename has spaces in it. would this be the problem?

 
Last edited:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
This is what I want to call in B4A. Does anyone know how to? It;s from this page: https://github.com/zackurben/alphavantage



// Simple examples
alpha.data.intraday(`msft`).then(data => {
console.log(data);
});
The first thing you need to do is download the CSV file and save it to your device, once you have that file you can parse it and do whatever you like with it.

Walter
 
Upvote 0

shb777

Active Member
Licensed User
Longtime User
I just found out that I was getting the data I wanted, but I didn't know it. So hopefully I can make the stock program I want with this.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…