### Authentication Implementation with jQuery Source: https://tradernet.by/tradernet-api?site_lang=en A practical example of performing the authByLogin request using the jQuery library. ```javascript /** * @type {authByLogin} */ var exampleParams = { "cmd": "authByLogin", "params": { "login": "user@example.com", "password": "password", "rememberMe": 1, "getAccounts": false, "userId": 1234 }, }; function authByLogin(callback) { $.post("https://tradernet.com/api/", {q: JSON.stringify(exampleParams)}, callback); } /** * Get the object **/ authByLogin(function(json){ console.log(json); }); ``` -------------------------------- ### Authentication Response Format Source: https://tradernet.by/tradernet-api?site_lang=en The JSON structure returned upon successful authentication. ```json { "success": true, "logged": true, "SID": "skjdhfahdf2847928743kjsfhd", "isSecuritySessionOpened": false, "userId": 1234, "real": true, "account_type": "brokerage", "account_title": "Trading account", "reception_country": "RU", "reception_code": "RU", "reception_name": "RU", "reception_title": "Цифра брокер", "reception_type": "broker", "hasAdminPanel": true } ``` -------------------------------- ### POST authByLogin Source: https://tradernet.by/tradernet-api?site_lang=en Authenticates a user using their login and password. Supports optional parameters for session persistence and account selection. ```APIDOC ## POST authByLogin ### Description Authenticates a user using their login and password. If getAccounts is set to true, the system returns a list of available accounts, which can then be used to authorize a specific user by passing the userId. ### Method POST ### Endpoint https://tradernet.com/api/ ### Parameters #### Request Body - **cmd** (string) - Required - Request execution command: "authByLogin" - **params** (array) - Required - Request execution parameters - **params.login** (string) - Required - User login - **params.password** (string) - Required - User password - **params.rememberMe** (integer) - Optional - Remember the session for 2 weeks - **params.getAccounts** (boolean) - Optional - List all accounts associated with this login - **params.viewOnlyMode** (boolean) - Optional - Account access is limited to view-only mode - **params.userId** (integer) - Optional - Specify a specific User ID for authorization ### Request Example { "cmd": "authByLogin", "params": { "login": "user@example.com", "password": "password", "rememberMe": 1, "getAccounts": false, "userId": 1234 } } ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful - **logged** (boolean) - Indicates if the user is logged in - **SID** (string) - Session ID - **userId** (integer) - The authenticated user ID #### Response Example { "success": true, "logged": true, "SID": "skjdhfahdf2847928743kjsfhd", "userId": 1234 } ``` -------------------------------- ### Authentication Request Structure Source: https://tradernet.by/tradernet-api?site_lang=en The JSON structure required for the authByLogin command via HTTPS POST. ```json { "cmd" (string) : "authByLogin", "params" (array) : { "login" (string): "user@example.com", "password" (string): "password", "rememberMe" (integer|null): 1, "getAccounts" (boolean|null): false, "userId" (integer|null): 1234 }, } ``` -------------------------------- ### Authentication Error Response Source: https://tradernet.by/tradernet-api?site_lang=en The JSON structure returned when an error occurs during the request. ```json // Common error { "errMsg" : "Bad json", "code" : 2 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.