Classic ASP
Classic ASP
Finnhub API - Get Stock Quote
See more AI Examples
Demonstrates how to get a stock quote from the Finnhub API.Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Replace with your actual Finnhub API key.
apiKey = "YOUR_FINNHUB_API_KEY"
symbol = "AAPL"
set http = Server.CreateObject("Chilkat.Http")
' This is the URL without params.
urlWithoutParams = "https://finnhub.io/api/v1/quote"
set req = Server.CreateObject("Chilkat.HttpRequest")
' Add params that will be sent in the URL.
req.AddParam "symbol",symbol
req.AddParam "token",apiKey
req.HttpVerb = "GET"
' Send the request to get the JSON response.
set resp = Server.CreateObject("Chilkat.HttpResponse")
success = http.HttpReq(urlWithoutParams,req,resp)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
Response.End
End If
set json = Server.CreateObject("Chilkat.JsonObject")
success = resp.GetBodyJson(json)
statusCode = resp.StatusCode
Response.Write "<pre>" & Server.HTMLEncode( "response status code: " & statusCode) & "</pre>"
json.EmitCompact = 0
Response.Write "<pre>" & Server.HTMLEncode( json.Emit()) & "</pre>"
' Sample result:
' {
' "c": 248.8,
' "d": -4.09,
' "dp": -1.6173,
' "h": 255.493,
' "l": 248.07,
' "o": 253.9,
' "pc": 252.89,
' "t": 1774641600
' }
If (statusCode = 200) Then
' Add the symbol to the top of the result.
success = json.AddStringAt(0,"symbol",symbol)
' Rename members for clarification.
success = json.Rename("c","currentPrice")
success = json.Rename("d","change")
success = json.Rename("dp","percentChange")
success = json.Rename("h","high")
success = json.Rename("l","low")
success = json.Rename("o","open")
success = json.Rename("pc","prevClose")
success = json.Rename("t","unixTime")
Response.Write "<pre>" & Server.HTMLEncode( json.Emit()) & "</pre>"
Else
Response.Write "<pre>" & Server.HTMLEncode( "Failed") & "</pre>"
End If
%>
</body>
</html>