New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

smartapi-javascript

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smartapi-javascript

## Installation ```bash npm i smartapi-javascript ```

Source
npmnpm
Version
1.0.6
Version published
Weekly downloads
1.1K
18.6%
Maintainers
1
Weekly downloads
 
Created
Source

SmartAPI Javascript Client SDK

Installation

npm i smartapi-javascript

Getting started with API

let { SmartAPI, WebSocket } = require("smartapi-javascript");

let smart_api = new SmartAPI({
    api_key: "YOUR_API_KEY",    // PROVIDE YOUR API KEY HERE
    // OPTIONAL
    // access_token: "YOUR_ACCESS_TOKEN",
    // refresh_token: "YOUR_REFRESH_TOKEN"
});

smart_api.generateSession("CLIENT_CODE", "PASSWORD")
    .then((data) => {
        return smart_api.getProfile();

        // return smart_api.getProfile()

        // return smart_api.logout()

        // return smart_api.placeOrder({
        //     "variety": "NORMAL",
        //     "tradingsymbol": "SBIN-EQ",
        //     "symboltoken": "3045",
        //     "transactiontype": "BUY",
        //     "exchange": "NSE",
        //     "ordertype": "LIMIT",
        //     "producttype": "INTRADAY",
        //     "duration": "DAY",
        //     "price": "19500",
        //     "squareoff": "0",
        //     "stoploss": "0",
        //     "quantity": "1"
        // })

        // return smart_api.modifyOrder({
        //     "orderid": "201130000006424",
        //     "variety": "NORMAL",
        //     "tradingsymbol": "SBIN-EQ",
        //     "symboltoken": "3045",
        //     "transactiontype": "BUY",
        //     "exchange": "NSE",
        //     "ordertype": "LIMIT",
        //     "producttype": "INTRADAY",
        //     "duration": "DAY",
        //     "price": "19500",
        //     "squareoff": "0",
        //     "stoploss": "0",
        //     "quantity": "1"
        // });

        // return smart_api.cancelOrder({
        //     "variety": "NORMAL",
        //     "orderid": "201130000006424"
        // });

        // V2 API'S
        // return smart_api.getOrderBook();

        // return smart_api.getTradeBook();

        // return smart_api.getRMS();

        // return smart_api.getHolding();

        // return smart_api.getPosition();

        // return smart_api.covertPosition({
        //     "exchange": "NSE",
        //     "oldproducttype": "DELIVERY",
        //     "newproducttype": "MARGIN",
        //     "tradingsymbol": "SBIN-EQ",
        //     "transactiontype": "BUY",
        //     "quantity": 1,
        //     "type": "DAY"
        // });

    })
    .then((data) => {
        // Profile details
    })
    .catch(ex => {
        //Log error
    })

    // TO HANDLE SESSION EXPIRY, USERS CAN PROVIDE A CUSTOM FUNCTION AS PARAMETER TO setSessionExpiryHook METHOD
    smart_api.setSessionExpiryHook(customSessionHook);

    function customSessionHook() {
        console.log("User loggedout");
        
        // NEW AUTHENTICATION CAN TAKE PLACE HERE
    }

Getting started with SmartAPI Websocket's

########################### Socket Sample Code Starts Here ###########################

let web_socket = new WebSocket({
    client_code: "CLIENT_CODE",
    feed_token: "FEED_TOKEN",
    script: "nse_cm|2885&nse_cm|1594"   //exchange|token for multi stocks use & seperator
});

web_socket.connect();
web_socket.on('tick', receiveTick)

// TO CLOSE THE SOCKET CONNECTION
setTimeout(function () {
    web_socket.close()
}, 3000)

function receiveTick(data) {
    console.log("Receive stock ticks::", data)
}
########################### Socket Sample Code Ends Here ###########################

FAQs

Package last updated on 08 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts