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
kite=None
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>)
kite.set_access_token(data["access_token"])
def getOrders():
return kite.orders()
Then calling getURL function from AFL,
PyLoadFromFile("connect1", "C:/Program Files/AmiBroker/xxxxxxx/xxxxxxx/xxxxx.py");
kiteUrl = PyEvalFunction("connect1", "getURL", <api_key>);
printf(kiteUrl);
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/xxxxx.py");
kiteUrl = PyEvalFunction("connect1", "getURL", <api_key>);
printf(kiteUrl);
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.