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

timestamp,open,high,low,close,volume
2018-02-08 16:00:00,85.4100,85.4700,84.7600,85.0100,5794980
2018-02-08 15:59:00,85.6550,85.6550,85.3600,85.4200,730241
2018-02-08 15:58:00,85.8200,85.8300,85.6500,85.6600,274764
2018-02-08 15:57:00,85.8400,85.9200,85.7500,85.8201,304590
2018-02-08 15:56:00,85.9800,86.1000,85.8150,85.8300,326190
2018-02-08 15:55:00,85.8400,86.0400,85.8000,85.9950,215556
2018-02-08 15:54:00,85.8299,85.9690,85.8200,85.8300,294860
2018-02-08 15:53:00,86.0200,86.1100,85.8000,85.8300,306687
2018-02-08 15:52:00,86.2000,86.2050,85.9000,86.0150,323630
2018-02-08 15:51:00,86.1000,86.2500,86.0200,86.2100,275416
2018-02-08 15:50:00,86.1400,86.2700,86.0100,86.1000,260376
2018-02-08 15:49:00,86.1100,86.3500,86.0400,86.1400,194706
2018-02-08 15:48:00,86.0500,86.3500,86.0000,86.0920,207140
2018-02-08 15:47:00,86.0600,86.2200,85.9800,86.0400,220238
2018-02-08 15:46:00,86.5600,86.5600,85.9356,86.0520,413371
2018-02-08 15:45:00,86.0900,86.6300,86.0500,86.5600,197127
2018-02-08 15:44:00,86.0650,86.1400,86.0100,86.0900,137590
2018-02-08 15:43:00,86.1800,86.2400,86.0400,86.0700,160945
2018-02-08 15:42:00,86.2650,86.3300,86.1600,86.2000,132255
2018-02-08 15:41:00,86.2100,86.3000,86.0700,86.2600,169806
2018-02-08 15:40:00,86.2500,86.3900,86.2000,86.2000,186107
2018-02-08 15:39:00,86.2350,86.3600,86.1700,86.2490,171443
2018-02-08 15:38:00,86.4380,86.4400,86.1700,86.2300,175708
2018-02-08 15:37:00,86.4300,86.5200,86.3500,86.4400,104790
2018-02-08 15:36:00,86.4100,86.5350,86.3400,86.4100,124281
2018-02-08 15:35:00,86.5700,86.6000,86.3800,86.4000,120217
2018-02-08 15:34:00,86.5700,86.6902,86.4900,86.5800,207153
2018-02-08 15:33:00,86.5200,86.6900,86.5100,86.5650,230745
2018-02-08 15:32:00,86.8100,86.8100,86.5000,86.5100,180032
2018-02-08 15:31:00,86.7000,86.8900,86.6600,86.8100,128567
2018-02-08 15:30:00,86.9000,86.9100,86.6700,86.6950,142692
2018-02-08 15:29:00,87.0700,87.0701,86.8900,86.9000,81720
2018-02-08 15:28:00,87.0223,87.0800,86.9200,87.0700,67457
2018-02-08 15:27:00,86.9300,87.0300,86.8600,87.0200,80515
2018-02-08 15:26:00,86.6300,87.0300,86.6300,86.9400,115593
2018-02-08 15:25:00,86.7800,86.8150,86.6200,86.6200,58806
2018-02-08 15:24:00,86.8000,86.8100,86.6200,86.7800,76466
2018-02-08 15:23:00,86.5900,86.8905,86.5600,86.8100,155762
2018-02-08 15:22:00,86.5200,86.7000,86.4600,86.5900,140106
2018-02-08 15:21:00,86.5500,86.5550,86.3300,86.5200,161294
2018-02-08 15:20:00,86.5700,86.5800,86.4600,86.5500,69485
2018-02-08 15:19:00,86.5600,86.7400,86.5600,86.5800,74266
2018-02-08 15:18:00,86.5700,86.6900,86.4800,86.5600,114845
2018-02-08 15:17:00,86.7100,86.7100,86.5000,86.5600,103888
2018-02-08 15:16:00,86.6060,86.7600,86.5650,86.7200,119777
2018-02-08 15:15:00,86.3900,86.6200,86.3900,86.6000,203739
2018-02-08 15:14:00,86.5348,86.6000,86.3800,86.4000,198000
2018-02-08 15:13:00,86.6500,86.6500,86.5000,86.5400,101324
2018-02-08 15:12:00,86.6500,86.7200,86.5700,86.6600,56505
2018-02-08 15:11:00,86.5500,86.6700,86.5100,86.6400,101890
2018-02-08 15:10:00,86.7400,86.8700,86.5300,86.5300,108129
2018-02-08 15:09:00,86.7700,86.8250,86.6800,86.7500,67330
2018-02-08 15:08:00,86.8800,86.9000,86.7400,86.7700,69421
2018-02-08 15:07:00,87.0100,87.0300,86.8100,86.8800,102626
2018-02-08 15:06:00,87.1300,87.1800,86.9300,87.0000,135696
2018-02-08 15:05:00,87.1000,87.1600,87.0200,87.1100,78724
2018-02-08 15:04:00,86.9840,87.1700,86.8800,87.1100,111088
2018-02-08 15:03:00,87.0800,87.1000,86.9200,86.9800,76582
2018-02-08 15:02:00,86.7700,87.0876,86.7100,87.0600,166440
2018-02-08 15:01:00,86.8700,86.8800,86.6100,86.7800,123274
2018-02-08 15:00:00,86.7900,86.8900,86.7500,86.8700,56839
2018-02-08 14:59:00,86.7700,86.8600,86.6709,86.7800,74670
2018-02-08 14:58:00,86.7100,86.7951,86.6400,86.7700,65041
2018-02-08 14:57:00,86.5800,86.8500,86.5500,86.7200,110458
2018-02-08 14:56:00,86.7565,86.7565,86.5600,86.5900,104152
2018-02-08 14:55:00,86.8600,86.8600,86.6200,86.7200,72879
2018-02-08 14:54:00,86.7500,86.8700,86.6600,86.8640,120590
2018-02-08 14:53:00,86.9100,86.9200,86.6900,86.7500,131718
2018-02-08 14:52:00,87.0000,87.0500,86.8800,86.9100,208074
2018-02-08 14:51:00,87.0060,87.0350,86.8900,87.0000,87109
2018-02-08 14:50:00,86.9300,87.0300,86.8900,87.0000,43343
2018-02-08 14:49:00,86.9975,86.9975,86.8800,86.9300,84181
2018-02-08 14:48:00,86.9400,87.0300,86.9195,87.0100,55273
2018-02-08 14:47:00,87.0900,87.0900,86.9200,86.9400,92325
2018-02-08 14:46:00,86.8100,87.1650,86.7600,87.0800,128100
2018-02-08 14:45:00,86.9200,86.9400,86.7800,86.8100,62510
2018-02-08 14:44:00,86.9100,86.9800,86.8700,86.9200,69396
2018-02-08 14:43:00,86.9200,87.0300,86.8100,86.9100,89742
2018-02-08 14:42:00,87.0000,87.0250,86.8100,86.9300,104005
2018-02-08 14:41:00,87.0900,87.0900,86.8600,87.0000,112050
2018-02-08 14:40:00,86.9500,87.1200,86.8900,87.1000,149170
2018-02-08 14:39:00,86.9000,86.9800,86.8234,86.9600,90499
2018-02-08 14:38:00,86.7500,86.9650,86.7400,86.9100,89937
2018-02-08 14:37:00,86.9200,86.9300,86.7400,86.7500,165357
2018-02-08 14:36:00,86.8900,86.9900,86.8500,86.9100,85096
2018-02-08 14:35:00,87.0400,87.0400,86.8900,86.9100,51330
2018-02-08 14:34:00,86.9700,87.0900,86.9500,87.0500,62458
2018-02-08 14:33:00,87.0800,87.0800,86.9300,86.9600,65581
2018-02-08 14:32:00,86.9500,87.1600,86.8500,87.0800,114017
2018-02-08 14:31:00,87.0800,87.1223,86.9500,86.9550,160831
2018-02-08 14:30:00,87.1676,87.2000,87.0300,87.1000,75427
2018-02-08 14:29:00,87.1400,87.2800,87.1321,87.1800,56775
2018-02-08 14:28:00,87.3300,87.3300,87.0700,87.1495,115977
2018-02-08 14:27:00,87.2900,87.3800,87.2600,87.3200,54419
2018-02-08 14:26:00,87.4400,87.4400,87.2500,87.3000,70948
2018-02-08 14:25:00,87.4000,87.5400,87.3860,87.4500,48869
2018-02-08 14:24:00,87.5500,87.5800,87.3500,87.3900,78814
2018-02-08 14:23:00,87.6300,87.6300,87.4200,87.5300,77729
2018-02-08 14:22:00,87.6700,87.7300,87.5900,87.6400,57725
2018-02-08 14:21:00,87.6470,87.8000,87.6470,87.6700,40745


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

DonManfred

Expert
Licensed User
Longtime User
how will a javascript api help here?
YOU are requesting exactly this csv data.
If they do not contain what you need then you maybe need to check their documentation on how to retrieve the correct data.

https://www.alphavantage.co/documentation/
 
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
Stocks_20180211_061955.png
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?

Stocks_20180211_061955.png
 
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
Top