From 9ffb9de49f66f95b03bd6b5f31ef9ba655f760b5 Mon Sep 17 00:00:00 2001 From: Raghava Reddy Date: Wed, 27 Nov 2024 11:04:41 +0530 Subject: [PATCH] Updated the ReadMe and example with valid TOTP configuration. --- README.md | 15 +++++++++++++-- example/api_test.js | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4ce22d3..1e2f2d4 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,28 @@ npm i smartapi-javascript ```javascript let { SmartAPI, WebSocket,WebSocketV2 } = require('smartapi-javascript'); +const speakeasy = require('speakeasy'); + +const api_key = 'smartapi_key'; +const totp_hash = 'totp'; +const client_code = 'client_code'; +const password = 'password'; let smart_api = new SmartAPI({ - api_key: 'smartapi_key', // PROVIDE YOUR API KEY HERE + api_key: api_key, // PROVIDE YOUR API KEY HERE // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor. // access_token: "YOUR_ACCESS_TOKEN", // refresh_token: "YOUR_REFRESH_TOKEN" }); +const totp = speakeasy.totp({ + secret: totp_hash, + encoding: 'base32' // Ensure the secret is base32 encoded +}); + // If user does not have valid access token and refresh token then use generateSession method smart_api - .generateSession('CLIENT_CODE', 'PASSWORD', 'TOTP') + .generateSession(client_code, password, totp) .then((data) => { return smart_api.getProfile(); diff --git a/example/api_test.js b/example/api_test.js index b42cacb..60684ac 100644 --- a/example/api_test.js +++ b/example/api_test.js @@ -1,17 +1,28 @@ let { SmartAPI, WebSocketClient, WebSocketV2, WSOrderUpdates } = require('../lib'); +const speakeasy = require('speakeasy'); + +const api_key = 'smartapi_key'; +const totp_hash = 'totp'; +const client_code = 'client_code'; +const password = 'password'; + let smart_api = new SmartAPI({ - api_key: 'smartapi_key', // PROVIDE YOUR API KEY HERE + api_key: api_key, // PROVIDE YOUR API KEY HERE // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor // access_token: "YOUR_ACCESS_TOKEN", // refresh_token: "YOUR_REFRESH_TOKEN" }); +const totp = speakeasy.totp({ + secret: totp_hash, + encoding: 'base32' // Ensure the secret is base32 encoded +}); // // If user does not have valid access token and refresh token then use generateSession method // } // smart_api -// .generateSession('CLIENT_CODE', 'PASSWORD', 'TOTP') +// .generateSession(client_code, password, totp) // .then((data) => { // console.log(data); // return smart_api.getProfile();