I am currently doing a project where I am learning how to get data from a public endpoint API (specifically binance) with a view to eventually being able to autotrade.
The method I have chosen is to create a folder, and in that folder create a html file, and place a string input into that file.
It works and I am getting the data I want from Binance API.
fmkdir("C:\\Program Files\\AmiBroker\\Export\\");
path= "C:\\Program Files\\AmiBroker\\Export\\" + Name() + ".html";
fh = fopen(path,"w");
if(fh)
{
filecontent = StrFormat(
"<html>"
+"\n<body>"
+"\n</body>"
+"\n<script>"
+"\nvar burl ='https://api1.binance.com';"
+"\nvar query = '/api/v3/klines';"
+"\nquery += '?symbol="
+ Name() + "&interval=1d&limit=20';"
+"\nvar url = burl + query;"
+"\nvar ourRequest = new XMLHttpRequest();"
+"\nourRequest.open('GET',url,true);"
+"\nourRequest.onload = function(){"
+ "\nconsole.log(ourRequest.responseText);"
+"\n}"
+"\nourRequest.send();"
+"\n</script>"
+"\n</html>;");
fputs(filecontent,fh);
fclose(fh);
ShellExecute(path,"","",1);
}
However, I needed to click through some menus to open the developer console, which was cumbersome.
After an internet trawl, I found that by entering "C:\Program Files\Google\Chrome\Application\chrome.exe" -auto-open-devtools-for-tabs , into the command prompt, I get a browser launched into the developer console, but still, this relies on me first manually doing this.
So then I started playing with batch, and if I create a batch;
Action: Execute and Wait,
Parameter/File: "C:\Program Files\Google\Chrome\Application\chrome.exe" -auto-open-devtools-for-tabs
and run it, again, I get the developer tab in Chrome. Great.
So next, I saved the command as a batch file and I used this code...
ShellExecute("runbatch","C:\\Program Files\\AmiBroker\\Scripts\\Batch\\Load Chrome.abb","",1);
That works, when it is executed by itself. I get a single browser tab, opened in the developer consoler.
However, this still does not solve my problem. When I run it combined with the code write the html file for the binance API, I don't get what it is I am looking for....
ShellExecute("runbatch","C:\\Program Files\\AmiBroker\\Scripts\\Batch\\Load Chrome.abb","",1);
fmkdir("C:\\Program Files\\AmiBroker\\Export\\");
path= "C:\\Program Files\\AmiBroker\\Export\\" + Name() + ".html";
fh = fopen(path,"w");
if(fh)
{
filecontent = StrFormat(
"<html>"
+"\n<body>"
+"\n</body>"
+"\n<script>"
+"\nvar burl ='https://api1.binance.com';"
+"\nvar query = '/api/v3/klines';"
+"\nquery += '?symbol="
+ Name() + "&interval=1d&limit=20';"
+"\nvar url = burl + query;"
+"\nvar ourRequest = new XMLHttpRequest();"
+"\nourRequest.open('GET',url,true);"
+"\nourRequest.onload = function(){"
+ "\nconsole.log(ourRequest.responseText);"
+"\n}"
+"\nourRequest.send();"
+"\n</script>"
+"\n</html>;");
fputs(filecontent,fh);
fclose(fh);
ShellExecute(path,"","",1);
}
I end up with 2 browsers, neither of which are opened in the console.
Any idea, critique or suggested alternative approaches, would be hugely welcome.
Thanks so much.
Spandy.