Question: Can we auto trade using just AFL and a REST API?

This has arisen out of my attempts to try and use the Python-Binance connector to post trades to Binance. I won’t go into details here as it’s not important.

Summary

Long story short, I don’t have the skill level to integrate AmiPy using the PyEvalFunction without generating some kind of error code for every line of code. When I run the scripts just in Python, they work fine, and AFL, works fine. But I don’t have the insight to know if/how I move information from AFL into my Python script or if it is pull only etc, lots of issues that I don’t yet know how to solve, and I really want to move on to writing and testing strategies soon. I can pull in information from my account and display that in the output window, and I can combine strings and variables to create scripts which I then launch and post orders, but I suspect I’m adding unnecessary steps.

Is it possible, just using AFL by itself, to pull information from and push information to generic REST APIs, and, do most brokers publish generic REST APIs?

for public endpoints you could go with AFL only, however you'd need to parse required information from json response

for private endpoints (account information, sending orders) you'd additionally need to compute cryptographic hash function and sign your requests

if you want to know further details about how to send orders to a crypto exchange using AFL please message me directly via a DM

1 Like

Yes you can talk directly to REST APIS

GET
https://www.amibroker.com/f?internetopenurl

POST
https://www.amibroker.com/f?internetpostrequest

Processing JSON:

Raw-stings (Python like) available in 6.41.0 as well.

4 Likes

Thanks for that.

I have been playing with the AFL function and got it working so far. I can call data from Public endpoints now, which is great.

The issue I am having is how to use the function to sign secure APIs, for example, if I wanted to call from my binance account, my current asset base.

The documentation for the signed API is here and the endpoint I am trying to access is here

_SECTION_BEGIN("Binance API Assets");

ih = InternetOpenURL( "https://testnet.binance.vision/sapi/v3/asset/getUserAsset ?X-MBX-APIKEY=ubup***************CSXfkk1MgM ?signature=7j0gW9***************PI4MhPancY");
printf( " Binance Assets " );
if( ih )
{
     while( ( str = InternetReadString( ih ) ) != "" )
     {
         printf( "%s", str );
     }
     InternetClose( ih );
}
_SECTION_END();

As you can see, here I have included my API key and secret, which I'm guessing is probably not the most secure way to transmit the key, but even that is not working and I'm not getting anything returned, so I am not sure what syntax I should be using or how to encode (HMAC SHA256) and then send that to Binance.

Thanks in advance for any direction.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.