I am learning how to build a system which will eventually communicate with Binance using .html in a browser.
The code creates a folder and in that folder, a new html file for the current symbol, then launches that file. The file contents are a XML http request. In this example, klines on the Binance API is the OHLC and vol data. The result is returned in the developer console of Chrome.
Line 57 I was able to use the Name() function as that is pretty standard. However, Binance uses a different nomenclature to Amibroker when referencing intervals. I am trying to define 'interv' depending on the current chart interval, but I always get returned the data for the first definition. So, for example;
{
if(Interval(1)==in5Minute)
interv = "5m";
else
{
if(Interval(1)==in15minute)
interv = "15m";
else
{
if(Interval(1)==inhourly)
interv = "1h";
else
{
if(Interval(1)==inDaily)
interv = "1d";
else
{
if(Interval(1)==inWeekly)
interv = "1w";
else
{
interv="1d";
}
}
}
}
}
}
would return the 5 minute data, regardless of whether a 15 min, 1 hour, 1 day or 1 week chart is displayed.
The whole code is here;
{
if(Interval(1)==in5Minute)
interv = "5m";
else
{
if(Interval(1)==in15minute)
interv = "15m";
else
{
if(Interval(1)==inhourly)
interv = "1h";
else
{
if(Interval(1)==inDaily)
interv = "1d";
else
{
if(Interval(1)==inWeekly)
interv = "1w";
else
{
interv="1d";
}
}
}
}
}
}
fmkdir("C:\\Program Files\\AmiBroker\\Export\\");
path= "C:\\Program Files\\AmiBroker\\Export\\" + Name() + ".html";
path2= "file:///C:/Program%20Files/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="+interv+"&limit=1';"
+ "\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( "chrome", "-auto-open-devtools-for-tabs" + " " + path2, "", 1 );
}