Lianja
Lianja
Finnhub API - Get Stock Quote
See more AI Examples
Demonstrates how to get a stock quote from the Finnhub API.Chilkat Lianja Downloads
llSuccess = .F.
// Replace with your actual Finnhub API key.
lcApiKey = "YOUR_FINNHUB_API_KEY"
lcSymbol = "AAPL"
loHttp = createobject("CkHttp")
// This is the URL without params.
lcUrlWithoutParams = "https://finnhub.io/api/v1/quote"
loReq = createobject("CkHttpRequest")
// Add params that will be sent in the URL.
loReq.AddParam("symbol",lcSymbol)
loReq.AddParam("token",lcApiKey)
loReq.HttpVerb = "GET"
// Send the request to get the JSON response.
loResp = createobject("CkHttpResponse")
llSuccess = loHttp.HttpReq(lcUrlWithoutParams,loReq,loResp)
if (llSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loReq
release loResp
return
endif
loJson = createobject("CkJsonObject")
loResp.GetBodyJson(loJson)
lnStatusCode = loResp.StatusCode
? "response status code: " + str(lnStatusCode)
loJson.EmitCompact = .F.
? loJson.Emit()
// 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 (lnStatusCode = 200) then
// Add the symbol to the top of the result.
loJson.AddStringAt(0,"symbol",lcSymbol)
// Rename members for clarification.
loJson.Rename("c","currentPrice")
loJson.Rename("d","change")
loJson.Rename("dp","percentChange")
loJson.Rename("h","high")
loJson.Rename("l","low")
loJson.Rename("o","open")
loJson.Rename("pc","prevClose")
loJson.Rename("t","unixTime")
? loJson.Emit()
else
? "Failed"
endif
release loHttp
release loReq
release loResp
release loJson