Sample code for 30+ languages & platforms
AutoIt

Finnhub API - Get Stock Quote

See more AI Examples

Demonstrates how to get a stock quote from the Finnhub API.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; Replace with your actual Finnhub API key.
Local $sApiKey = "YOUR_FINNHUB_API_KEY"
Local $symbol = "AAPL"

$oHttp = ObjCreate("Chilkat.Http")

; This is the URL without params.
Local $sUrlWithoutParams = "https://finnhub.io/api/v1/quote"

$oReq = ObjCreate("Chilkat.HttpRequest")

; Add params that will be sent in the URL.
$oReq.AddParam "symbol",$symbol
$oReq.AddParam "token",$sApiKey

$oReq.HttpVerb = "GET"

; Send the request to get the JSON response.
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpReq($sUrlWithoutParams,$oReq,$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oJson = ObjCreate("Chilkat.JsonObject")
$oResp.GetBodyJson($oJson)

Local $iStatusCode = $oResp.StatusCode
ConsoleWrite("response status code: " & $iStatusCode & @CRLF)

$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)

; 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 ($iStatusCode = 200) Then
    ; Add the symbol to the top of the result.
    $oJson.AddStringAt(0,"symbol",$symbol)

    ; Rename members for clarification.
    $oJson.Rename("c","currentPrice")
    $oJson.Rename("d","change")
    $oJson.Rename("dp","percentChange")
    $oJson.Rename("h","high")
    $oJson.Rename("l","low")
    $oJson.Rename("o","open")
    $oJson.Rename("pc","prevClose")
    $oJson.Rename("t","unixTime")

    ConsoleWrite($oJson.Emit() & @CRLF)

Else
    ConsoleWrite("Failed" & @CRLF)
EndIf