Using AmiPy to create API Access Token through Python

Dear Tomasz,
I am Trying to connect to a broker API from Amibroker through Python.
As the initial setup, Saved AmiPy dll to the Plugins folder. Installed Python 3.8. This setup is tested and is working fine.

The Python code is :

from kiteconnect import KiteConnect
def GetURL(apiKey):
    global kite
    kite = KiteConnect(api_key=<api_key>)
    return kite.login_url()
def ConnectToApi(token,secretKey):
    data = kite.generate_session(token, api_secret=<api_key>)
def getOrders():
    return kite.orders()

Then calling getURL function from AFL,

PyLoadFromFile("connect1", "C:/Program Files/AmiBroker/xxxxxxx/xxxxxxx/");

kiteUrl = PyEvalFunction("connect1", "getURL", <api_key>);

In manual mode, the output is copied and pasted to a browser address bar to get a Token Response from API.

However,I am not able to get the Token from API from Amibroker. Tried using InternetOpenURL() and InternetPostRequest() functions but not successful.

PyLoadFromFile("connect1", "C:/Program Files/AmiBroker/xxxxxxx/xxxxxx/");
kiteUrl = PyEvalFunction("connect1", "getURL", <api_key>);

ih = InternetOpenURL( kiteUrl ); 
printf( "Access Token generated: " ); 
if( ih ) 
      while( ( str = InternetReadString( ih ) ) != "" ) 
          printf( "%s", str ); 
      InternetClose( ih ); 

This Token is used to generate <access_token> by calling ConnectToApi Python function and passing newly generated Token and API secret. I am stuck at this point as I could not find a way to collect the Token returned by API call.

Please guide.

I am NOT doing Python support.

Thank you Tomasz for approving the post. I understand that you would not be in a position to make python support. The situation is that I have to use either Python/Java/JSON/PHP/Rust/Go/.Net to make the interaction with this particular broker API, since there are no bridges for Amibroker available.

Both the Python and AFL code were posted here to bring out the actual scenario. I am looking for a way to get the Response Token returned by the url call by using the internet functions of AFL.

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