HTTP REST API Call from AFL Algo


I am very new to Amibroker and AFL language.
I am trying to call a REST GET API from my algo written in AFL, but it ends up opening the endpoint in new browser tabs for every call.
I am trying something like this -
AlertIf( True, "EXEC", "Hello World", 2 );

Can some please help me with this?

Thanks in advance.


Use InternetOpenURL() function

See also other threads on this forum:


@myselfshiv, here is an example you can test with a working (fake) server:

Version (6.28); // tested version
// Fake Online REST API for Testing and Prototyping powered by JSON Server and lowdb 
URL = "";

_TRACE("Getting 100 posts");
ih = InternetOpenURL( URL + "posts/");
if( ih )
     while( ( str = InternetReadString( ih ) ) != "" )
         _TRACEF( "%s", str );
     InternetClose( ih );

_TRACE("Getting 10 users");
ih = InternetOpenURL( URL + "users/");
if( ih )
     while( ( str = InternetReadString( ih ) ) != "" )
         _TRACEF( "%s", str );
     InternetClose( ih );

Thanks @Tomasz and @beppe

I was trying your suggestion and I am getting syntax errors. Do I need a specific version of Amibroker to be able to use the InternetOpenURL() ?
OR do I need to include/import any package to make this work?

Context - I am from Java background, trying my hands at AFL :expressionless:

In my example, I used version 6.28.0 Beta 64-bit, but the official documentation says that:

  • InternetOpenURL()
  • InternetReadString()
  • InternetClose()

were officially introduced in AmiBroker version 6.20.

No includes or imports are needed: ALL the AFL documented functions are directly callable from your formulas.


Is there any where I can download a trial verision for 6.20 or above?

No, the trial version is only 6.00. Any higher version requires license (purchase) .

ok thanks, this helps

Would it be possible to use InternetOpenUrl() to do the following please:

  • First AB finds buy signal
  • for each buy signal, query the REST API service for data such as market depth, VWAP etc
  • if buy depth >10 and VWAP <5, then send buy signal to the API to execute order

@C_M using InternetOpenURL() to query some data from a REST server is entirelye possible as demonstrated by the code samples I posted previously.

The data you'll receive will very probably be in JSON format, so you need to parse it and extract the relevant information for your formula. Then you can do whatever you want with such data!

There is one important caveat: be sure that your REST server will provide headers with "no-cache" otherwise you'll see stale data.
I did some test using a very basic nodejs/express and found that the AmiBroker function will not force a refresh of data for repeated requests of the same resources, but will simply get them from the cache. On the express server, I had to use a middleware function to avoid the issue.


@beppe I'm not 100% sure if this is applicable in this case, but I do a lot of web scraping / web data extraction (using also AmiBroker Internet functions for that) and at the beginning I had similar problems with stale/cached data in case of repetitive queries, but these problems were solved when I changed Temporary Internet Files settings - "Check for newer versions of stored pages" to Every time I visit the webpage


If you haven't done that already, you can check if this helps.

InternetOpenURL() is a WinINet function and WinINet is a part of Operating System also used by IE:

Best :slight_smile:


If remote REST server does not deliver fresh content, you can force it by adding extra dummy parameter with random value. This effectively disables any caching.

ih = InternetOpenURL( URL + "&dummy=" + 100 * mtRandom() );

In 6.30 you can use "no cache" (INTERNET_FLAG_RELOAD) flag, see:

Version( 6.30 ); // required version


// Example don't use cached content and don't use cookies

InternetClose( ih );

HI, My broker requires checksum(SHA-256 OF api_key + request_token + api_secret) to further POST (REST API) request for issuing session token in the following format:-
-H "X-Kite-Version: 3"
-d "api_key=xxx"
-d "request_token=yyy"
-d "checksum=zzz"
I have value of xxx and yyy. Please suggests how to go about it in AFL. Thank you !Login Flow REST API