npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smartapi-javascript-next

v1.0.1-4.6

Published

```bash npm i smartapi-javascript ```

Downloads

9

Readme

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: "smartapi_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"
});

// If user does not have valid access token and refresh token then use generateSession method 
smart_api.generateSession("CLIENT_CODE", "PASSWORD")
    .then((data) => {
        return smart_api.getProfile();

        // User Methods
        // return smart_api.getProfile()

        // return smart_api.logout()

        // return smart_api.getRMS();

        // Order Methods
        // 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"
        // });

        // return smart_api.getOrderBook();

        // return smart_api.getTradeBook();

      
        // Portfolio Methods
        // return smart_api.getHolding();

        // return smart_api.getPosition();

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


        // GTT Methods
        // return smart_api.createRule({
        //    "tradingsymbol" : "SBIN-EQ",
        //    "symboltoken" : "3045",
        //    "exchange" : "NSE", 
        //    "producttype" : "MARGIN",
        //    "transactiontype" : "BUY",
        //    "price" : 100000,
        //    "qty" : 10,
        //    "disclosedqty": 10,
        //    "triggerprice" : 200000,
        //    "timeperiod" : 365
        // })
        // return smart_api.modifyRule({
        //             "id" : 1000014,
        //             "symboltoken" : "3045",
        //             "exchange" : "NSE", 
        //             "qty" : 10

        // })
        // return smart_api.cancelRule({
        //      "id" : 1000014,
        //      "symboltoken" : "3045",
        //      "exchange" : "NSE"
        // })
        // return smart_api.ruleDetails({
        //     "id" : 25
        // })
        // return smart_api.ruleList({
        //      "status" : ["NEW","CANCELLED"],
        //      "page" : 1,
        //      "count" : 10 
        // })

      // Historical Methods
        // return smart_api.getCandleData({
        //     "exchange": "NSE",
        //     "symboltoken": "3045",
        //     "interval": "ONE_MINUTE",
        //     "fromdate": "2021-02-10 09:00",
        //     "todate": "2021-02-10 09:20"
        // })
    })
    .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 ###########################
// Old websocket

let web_socket = new WebSocket({
    client_code: "CLIENT_CODE",   
    feed_token: "FEED_TOKEN"
});

web_socket.connect()
    .then(() => {
        web_socket.runScript("SCRIPT", "TASK") // SCRIPT: nse_cm|2885, mcx_fo|222900  TASK: mw|sfi|dp

        setTimeout(function () {
            web_socket.close()
        }, 3000)
    })

web_socket.on('tick', receiveTick)


function receiveTick(data) {
    console.log("receiveTick:::::", data)
}

 ########################### Socket Sample Code Ends Here ###########################

 ########################### Socket Sample Code Starts Here ###########################
// New websocket

let web_socket = new WebSocketClient({
    clientcode: "CLIENT_CODE",    
    jwttoken: "jwt_token",
    apikey: "smartapi_key",
    feedtype: "order_feed",
});

web_socket.connect()
    .then(() => {
        web_socket.fetchData("ACTION_TYPE", "FEED_TYPE");  // ACTION_TYPE: subscribe | unsubscribe FEED_TYPE: order_feed

        setTimeout(function () {
            web_socket.close()
        }, 60000)
    });

web_socket.on('tick', receiveTick);


function receiveTick(data) {
    console.log("receiveTick:::::", data);
}

 ########################### Socket Sample Code Ends Here ###########################