[Python] How can I Authenticate?
Hello, I'm a python newbie and trying to get the account balance with a python script but I'm getting this error:
{"echo_req":{"balance":"1"},"error":{"code":"AuthorizationRequired","message":"Please log in."},"msg_type":"balance"}
Please, could someone clarify for me how can I do this procedure?
Thank you for your attention!
Comments
Quite obviously, the balance request has been sent before the authorize request has been processed.
If you don't post any code, we can't tell you what is wrong with it.
Hello Jymmy, yes I realised that, thats why my question is "How can I Authenticate?".
I tried sending by the websocket the oath link but this does not authenticate, do you know how to do it in python?
I recommend reading the API Guide.
There are two methods of authentication.
1. Using API tokens.
2. Using oauth
The first method is easiest. Go to this page https://www.binary.com/fr/user/security/api_tokenws.html and create an API token for your account. Then your python app can simply send "authorize": "your-api-token".
The second method is rather more involved. You have to register your app specifying a redirect url. Then you send your users to the web page https://oauth.binary.com/oauth2/authorize?app_id=[..insert app_id..] so that they can sign in to binary.com's website. When they are logged in binary.com will send them to http(s)://your.redirect.url/?token=an-api-token. That way your web server can collect the api token, and finally your python app can send "authorize": "their-api-token".