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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@anjana_75/trade-lib

v1.3.4

Published

Reusable Angel One trading library for placing orders, modifying orders, fetching positions, order management and master data operations.

Readme

Trade Lib

A reusable Node.js trading library for broker integrations.

Currently supports Angel One SmartAPI and is designed to support additional brokers such as AliceBlue and Upstox in the future.


Features

Trading

  • Place Orders
  • Place Stop Loss Orders
  • Place Target Orders
  • Modify Orders
  • Fetch Order Book
  • Fetch Positions
  • Check Open Orders
  • Check Open Positions
  • Exit All Open Positions

Master Data & Contracts

  • Download Master Data
  • Store Contracts Locally
  • Symbol → Token Search
  • Token → Contract Search
  • Option Contract Search
  • Exchange-wise Contract Storage

Redis Integration

  • Redis Contract Cache
  • Symbol Lookup Index
  • Token Lookup Index
  • Option Lookup Index
  • Automatic Redis Cache Rebuild

Automation

  • Daily Master Data Download
  • Automatic Log Cleanup
  • Scheduled Cron Jobs

Logging

  • Order Logs
  • Error Logs
  • Master Data Download Errors
  • Log Retention Management

Installation

npm install @anjana_75/trade-lib

Environment Variables

Create a .env file in your project:

ANGEL_API_KEY=YOUR_API_KEY
ANGEL_CLIENT_ID=YOUR_CLIENT_ID
ANGEL_PIN=YOUR_PIN
ANGEL_TOTP_SECRET=YOUR_TOTP_SECRET

REDIS_URL=redis://localhost:6379

Redis Setup (Docker)

This library uses Redis for fast contract and option searches.

Docker Compose

Create a docker-compose.yml file:

services:
  redis:
    image: redis:latest
    container_name: trade_lib_redis
    ports:
      - "6379:6379"

  redisinsight:
    image: redis/redisinsight:latest
    container_name: trade_lib_redisinsight
    ports:
      - "5540:5540"

Start Services

docker compose up -d

Verify Containers

docker ps

RedisInsight

Open:

http://localhost:5540

Create a connection:

Host: localhost
Port: 6379

Stop Services

docker compose down

Order Tag Support

Order tags can be passed while placing orders for easier tracking and logging.

const result = await placeOrder('angelone', {
    tradingsymbol: 'SBIN-EQ',
    symboltoken: '3045',
    transactiontype: 'BUY',
    exchange: 'NSE',
    quantity: 1,
    ordertype: 'MARKET',
    ordertag: 'strategy_1'
});

Contract Search Architecture

Local Storage

Full contract master data is stored locally:

contracts/
└── angelone/
    └── masterdata/
        ├── nse.json
        ├── nfo.json
        ├── bse.json
        ├── bfo.json
        ├── cds.json
        ├── mcx.json
        ├── ncdex.json
        └── nco.json

Redis Search Indexes

Redis stores only search indexes to reduce memory usage.

contracts:angelone:masterdata:nse:symbol:SBIN-EQ
contracts:angelone:masterdata:nse:token:3045

contracts:angelone:option:NIFTY:30JUN2026:30000:PE

Search Flow

Stock Search:

Symbol
 ↓
Redis
 ↓
Token
 ↓
Contract Details

Option Search:

Underlying + Expiry + Strike + Option Type
 ↓
Redis Option Index
 ↓
Token
 ↓
Contract Details

Redis Memory Optimization

The library stores:

  • Symbol → Token
  • Token → Contract
  • Option → Token

Full exchange master data remains in JSON files, reducing Redis memory usage while maintaining fast searches.


Broker Architecture

The library is designed to support multiple brokers through a common interface.

Current Structure:

brokers/
├── angelone.js
├── aliceblue.js
└── upstox.js

Currently Supported:

  • Angel One

Planned:

  • AliceBlue
  • Upstox

Usage

require('dotenv').config();

const {
    placeOrder,
    placeSLOrder,
    placeTPOrder,
    modifyOrder,
    getOrders,
    getPositions,
    hasOpenOrder,
    hasOpenPosition,
    loopExitPositions,
    downloadMasterData,
    readMasterData,
    downloadAndStoreContracts,
    getTokenBySymbol,
    getContractByToken,
    getOptionContract
} = require('@anjana_75/trade-lib');

Place Order

const result = await placeOrder('angelone', {
    tradingsymbol: 'SBIN-EQ',
    symboltoken: '3045',
    transactiontype: 'BUY',
    exchange: 'NSE',
    quantity: 1,
    ordertype: 'MARKET'
});

console.log(result);

Place Stop Loss Order

const result = await placeSLOrder('angelone', {
    tradingsymbol: 'SBIN-EQ',
    symboltoken: '3045',
    quantity: 1
});

Place Target Order

const result = await placeTPOrder('angelone', {
    tradingsymbol: 'SBIN-EQ',
    symboltoken: '3045',
    quantity: 1
});

Get Orders

const orders = await getOrders('angelone');

Get Positions

const positions = await getPositions('angelone');

Download Master Data

const result = await downloadMasterData('angelone');

console.log(result);

Download And Store Contracts

const result = await downloadAndStoreContracts(
    'angelone'
);

console.log(result);

Search Token By Symbol

const result = await getTokenBySymbol(
    'angelone',
    'nse',
    'SBIN-EQ'
);

console.log(result);

Search Contract By Token

const result = await getContractByToken(
    'angelone',
    'nse',
    '3045'
);

console.log(result);

Search Option Contract

const result = await getOptionContract(
    'angelone',
    'NIFTY',
    '30JUN2026',
    30000,
    'PE'
);

console.log(result);

Contract Storage Structure

contracts/
└── angelone/
    └── masterdata/
        ├── nse.json
        └── nfo.json

Redis Structure

contracts:angelone:masterdata:nse:symbol:SBIN-EQ
contracts:angelone:masterdata:nse:token:3045

contracts:angelone:option:NIFTY:30JUN2026:30000:PE

Cron Jobs

Master Data Download

Runs daily and downloads the latest contract master data.

Log Cleanup

Automatically removes logs older than the configured retention period.


Supported Brokers

Currently Supported:

  • Angel One ✅
  • AliceBlue ✅

Planned:

  • Upstox 🚧


AliceBlue Support

Trade Lib now supports AliceBlue Open API alongside Angel One.

AliceBlue Environment Variables

Add the following values to your .env file:

ALICEBLUE_BASE_URL=https://a3.aliceblueonline.com/open-api/od/v1

ALICEBLUE_USER_ID=YOUR_USER_ID
ALICEBLUE_API_KEY=YOUR_API_KEY
ALICEBLUE_API_SECRET=YOUR_API_SECRET
ALICEBLUE_AUTH_CODE=YOUR_AUTH_CODE

AliceBlue Login

const { aliceblue } = require('@anjana_75/trade-lib');

const result = await aliceblue.login();

console.log(result);

AliceBlue Place Order

const result = await placeOrder('aliceblue', {
    exchange: 'NSE',
    tradingsymbol: 'SBIN',
    transactiontype: 'BUY',
    quantity: 1,
    ordertype: 'MARKET',
    producttype: 'INTRADAY'
});

console.log(result);

AliceBlue Modify Order

const result = await modifyOrder('aliceblue', {
    brokerOrderId: 'ORDER_ID',
    quantity: 1,
    price: 100
});

console.log(result);

AliceBlue Get Orders

const orders = await getOrders('aliceblue');

console.log(orders);

AliceBlue Get Positions

const positions = await getPositions('aliceblue');

console.log(positions);

AliceBlue Check Open Orders

const hasOpenOrder = await hasOpenOrder(
    'aliceblue'
);

console.log(hasOpenOrder);

Check specific token:

const hasOpenOrder = await hasOpenOrder(
    'aliceblue',
    '123456'
);

console.log(hasOpenOrder);

AliceBlue Check Open Positions

const hasOpenPosition = await hasOpenPosition(
    'aliceblue'
);

console.log(hasOpenPosition);

Check specific token:

const hasOpenPosition = await hasOpenPosition(
    'aliceblue',
    '123456'
);

console.log(hasOpenPosition);

AliceBlue Exit All Positions

const result = await loopExitPositions(
    'aliceblue'
);

console.log(result);

AliceBlue Profile

const result = await aliceblue.getProfile();

console.log(result);

AliceBlue Limits

const result = await aliceblue.getLimits();

console.log(result);

AliceBlue Cancel Order

const result = await aliceblue.cancelOrder(
    'BROKER_ORDER_ID'
);

console.log(result);

AliceBlue Master Data

Download latest master data:

const result = await downloadMasterData(
    'aliceblue'
);

console.log(result);

AliceBlue Contract Download

Download contracts and build Redis indexes:

const result = await downloadAndStoreContracts(
    'aliceblue'
);

console.log(result);

Example Response:

{
    success: true,
    broker: 'aliceblue',
    total: 50000,
    nseTotal: 20000,
    nfoTotal: 30000,
    storedCount: 50000,
    optionIndexCount: 25000
}

AliceBlue Token Search

const result = await getTokenBySymbol(
    'aliceblue',
    'nse',
    'SBIN'
);

console.log(result);

AliceBlue Contract Search

const result = await getContractByToken(
    'aliceblue',
    'nse',
    '123456'
);

console.log(result);

AliceBlue Option Contract Search

const result = await getOptionContract(
    'aliceblue',
    'NIFTY',
    '31JUL2026',
    25000,
    'CE'
);

console.log(result);

AliceBlue Contract Storage

contracts/
└── aliceblue/
    └── masterdata/
        ├── nse.json
        └── nfo.json

AliceBlue Redis Contract Structure

contracts:aliceblue:masterdata:nse:symbol:SBIN

contracts:aliceblue:masterdata:nse:token:123456

contracts:aliceblue:masterdata:nfo:option:NIFTY:31JUL2026:25000:CE

AliceBlue Redis Auth Tokens

Trade Lib automatically stores AliceBlue authentication tokens in Redis after successful login.

auth:aliceblue:userSession
auth:aliceblue:clientId

Account specific keys:

auth:aliceblue:2675340:userSession
auth:aliceblue:2675340:clientId

AliceBlue Rate Limiting

Trade Lib automatically applies broker-safe delays when fetching:

await getOrders('aliceblue');

await getPositions('aliceblue');

This helps prevent broker API throttling and excessive request rates.


License

MIT License


Author

Anjana George