How to use a symbol with a "." in the URL with Alphavantage?

Viewed 2926

I am using the Alpha Vantage API and have come across a problem, every time I try to send an API request where the symbol (ticker) has a "." in it, the API call returns an Invalid API call error.

How do I get past this?

For example, to search for BT Group on the London Stock Exchange, you would use "LON:BT.A" which I would expect the formulate the URL like below:

https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=LON:BT.A&apikey=API_KEY

This does not work, but equally if I wanted to search for a ticker without a dot then it works perfectly fine, for example Sky plc is "LON:SKY" so the below works:

https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=LON:SKY&apikey=API_KEY
2 Answers

Most of the tickers that have a "." in them seem to require that you replace them with a "-", so this worked for me, however I have found that this is not always the case. I couldn't find any documentation with a comprehensive list of tickers (I guess probably because it's dynamic) so stopped using the API.

You could URL-Encode the dot as %2E. Same technique as encoding a space as %20. Your URL would look like this with the encoded dot:

https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=LON:BT%2EA&apikey=API_KEY

More information about URL-Encoding can be found here:
https://www.w3schools.com/tags/ref_urlencode.asp

Still wondering why the plain dot is not allowed in the URL though. Think the webserver just cannot handle it. According to RFC3986 paragraph 2.3 dots are allowed and don't have any special meaning.

Related