Created
July 12, 2016 03:41
-
-
Save errorseven/03744c5a57286657be18b9bd8bcbf9f4 to your computer and use it in GitHub Desktop.
/r/DailyProgrammer [2015-08-19] #228 [Intermediate] Use a Web Service to Find Bitcoin Prices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
endpoint := "http://api.bitcoincharts.com/v1/trades.csv" | |
market := "bitfinex" | |
currency := "USD" | |
Url := endpoint . "?symbol=" . market . currency | |
req := ComObjCreate("Msxml2.XMLHTTP") | |
; Open a request with async enabled. | |
req.open("GET", Url, true) | |
; Set our callback function (v1.1.17+). | |
req.onreadystatechange := Func("Ready") | |
; Send the request. Ready() will be called when it's complete. | |
req.send() | |
#Persistent | |
Ready() { | |
global req | |
if (req.readyState != 4) ; Not done yet. | |
return | |
if (req.status == 200 || req.status == 304) { ; OK. | |
values := req.responseText | |
For Each, Value in StrSplit(values, ",") { | |
if (A_index = 2) { | |
MsgBox % "Current Bitcoin price in USD: " Round(value, 2) | |
ExitApp | |
} | |
} | |
} | |
else | |
MsgBox 16,, % "Status " req.status | |
ExitApp | |
} | |
GetUnixTime() { | |
UnixTime := A_NowUTC | |
EnvSub, UnixTime, 1970, seconds | |
Return UnixTime | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment