betcode-org / betfair

betfairlightweight - Betfair API-NG python wrapper (with streaming)
MIT License
428 stars 148 forks source link

Session management on azure #527

Closed yboloSwiss closed 1 year ago

yboloSwiss commented 1 year ago

Hello,

I recently received an email from betfair telling me that I was creating too many logins on the platform. They advised me to use the keep_alive method to keep the connections active. But my scripts are developed to be executed using azure functions. Azure functions do not persist values in memory, each script execution is independent. The keep_alive() method therefore has no effect in my case.

On the other hand, I am able to persist the value of session_token in order to re-use it for each connection and thus not generate new sessions at betfair. Except that with betfairlightweight I can't pass the session value to the APIClient object.

I tried 2 approch :


my_session_token = "vepevuc2rw0L9Hn4R1flIOCGqsuKRdbUB/XXXXXXXXX"
# Connexion avec Betfair
trading = betfairlightweight.APIClient(username=my_username,
                                        password=my_password,
                                     app_key=my_app_key,
                                     certs=os.getcwd(),
                                     session=my_session_token )
trading.login()
logging.info(f'Betfair Login with {trading.session_token}')

in this case the trading object does not know how to use a string as a session token.


my_session_token = "vepevuc2rw0L9Hn4R1flIOCGqsuKRdbUB/XXXXXXXXX"
logging.info(f'Gived session token : {my_session_token}')

# Connexion avec Betfair
trading = betfairlightweight.APIClient(username=my_username,
                                     password=my_password,
                                     app_key=my_app_key,
                                     certs=os.getcwd())

trading.set_session_token(session_token=my_session_token)
logging.info(f'{self.trading.session_token}')
self.trading.login()
logging.info(f'Betfair Login with {trading.session_token}')

In this case trading.set_session_token(session_token=my_session_token) seems to be ignored by the login() method

Thanks for your helps

liampauling commented 1 year ago

I am a bit confused? If you set the session token manually like you have done correctly you then don't need to call .login() again, why are you?

FYI join the slack group for quicker responses.

yboloSwiss commented 1 year ago

Oh sorry for the mistake ! Thanks for the slack chanel.