Trading 212 API error code
Trading 212 API error: HTTP 401
What does HTTP 401 mean on the Trading 212 API?
Trading 212 did not accept the credentials on the request. The endpoint reference lists 401 as a response but gives it no description. On the community forum it came back when only the API key was sent without the secret, when the Base64 string had a line break in it, and when a key was sent to a host other than the one for the account it was made on.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
How do I fix HTTP 401?
Send the header Authorization: Basic followed by base64(API_KEY:API_SECRET) with no line breaks, and use the key pair made for the account you are calling. The help centre says key versions may differ between real and demo accounts.