Last active
April 26, 2021 15:40
-
-
Save JoeGlines/8425ac691a724604c3922db80d15c2ff to your computer and use it in GitHub Desktop.
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
;******************************************************* | |
; Want a clear path for learning AutoHotkey; Take a look at our AutoHotkey Udemy courses. They're structured in a way to make learning AHK EASY | |
; Right now you can get a coupon code here: https://the-Automator.com/Learn | |
;******************************************************* | |
#SingleInstance, Force ;Limit one running version of this script | |
Endpoint:="https://www.bitstamp.net/api/transactions/" | |
;****************************** | |
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") ;Create COM Object | |
HTTP.Open("GET", Endpoint QS) ;GET & POST are most frequent, Make sure you UPPERCASE | |
HTTP.Send(Payload) ;If POST request put data in "Payload" variable | |
oAHK:=ParseJSON(HTTP.ResponseText) ;Make sure the ParseJSON function is in your library | |
fulldata:="Index`tDate`tPrice`tTID`tType`r`n" | |
for k, v in oAhk{ | |
fulldata.=k a_tab v.date A_tab v.price a_tab v.tid a_tab v.type "`r`n" | |
} | |
FileAppend,%Fulldata%,bitstamp,UTF-8 | |
DebugWindow(fulldata,Clear:=1,LineBreak:=1,Sleep:=500,AutoHide:=0) | |
return | |
;********************Parse Json*********************************** | |
ParseJSON(jsonStr){ | |
static SC:=ComObjCreate("ScriptControl"),C:=Chr(125) | |
SC.Language:="JScript",ComObjError(0),SC.ExecuteStatement("function arrangeForAhkTraversing(obj){if(obj instanceof Array){for(var i=0; i<obj.length; ++i)obj[i]=arrangeForAhkTraversing(obj[i]);return ['array',obj];" C "else if(obj instanceof Object){var keys=[],values=[];for(var key in obj){keys.push(key);values.push(arrangeForAhkTraversing(obj[key]));" C "return ['object',[keys,values]];" C "else return [typeof obj,obj];" C ";obj=" jsonStr) | |
return convertJScriptObjToAhks(SC.Eval("arrangeForAhkTraversing(obj)")) | |
}ConvertJScriptObjToAhks(JSObj){ | |
if(JSObj[0]="Object"){ | |
Obj:=[],Keys:=JSObj[1][0],Values:=JSObj[1][1] | |
while(A_Index<=Keys.length) | |
Obj[Keys[A_Index-1]]:=ConvertJScriptObjToAhks(Values[A_Index-1]) | |
return Obj | |
}else if(JSObj[0]="Array"){ | |
Array:=[] | |
while(A_Index<=JSObj[1].length) | |
Array.Push(ConvertJScriptObjToAhks(JSObj[1][A_Index-1])) | |
return Array | |
}else | |
return JSObj[1] | |
} | |
#Include XHR.AHK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment