Documentation
HomeGithubDiscordBlog
  • What is OpenAlgo?
  • OpenAlgo Architecture
  • Mini FOSS Universe
  • Community Support
  • OpenAlgo GPT
  • New Features
    • Fast Scalper
    • API Analyzer
    • Traffic/Latency Monitor
    • Chartink Integration
  • Monetization
  • Connect Brokers
    • Brokers
      • 5Paisa
      • 5paisa (XTS)
      • AliceBlue
      • AngelOne
      • Compositedge
      • Dhan
      • Firstock
      • FlatTrade
      • Fyers
      • Groww
      • IIFL (XTS)
      • Jainam Retail (XTS)
      • Jainam Dealer (XTS)
      • Kotak Securities
      • Paytm
      • Pocketful
      • Shoonya
      • Upstox
      • Wisdom Capital
      • Zebu
      • Zerodha
  • Installation Guidelines
  • Getting Started
    • Windows Installation
      • Pre-Requesites
      • Setup
      • Install Dependencies
      • Ngrok Config
      • Environmental Variables
      • Start OpenAlgo
      • SSL Verification Failed
      • Accessing OpenAlgo
    • Windows Server Installation
    • Mac OS Installation
      • Pre-Requesties
      • Setup
      • Install Dependencies
      • Ngrok Config
      • Environmental Variables
      • Start OpenAlgo
      • Install certifi
      • Accessing OpenAlgo
    • Amazon Elastic Beanstalk
    • Ubuntu Server Installation
    • Docker Development
    • Testing OpenAlgo in Cloud
    • Upgrade
  • Latency
  • API Documentation
    • V1
      • Accounts API
        • Funds
        • Orderbook
        • Tradebook
        • PositionBook
        • Holdings
      • Orders API
        • Placeorder
        • PlaceSmartOrder
        • BasketOrder
        • SplitOrder
        • ModifyOrder
        • CancelOrder
        • CancelAllOrder
        • ClosePosition
        • OrderStatus
        • OpenPosition
      • Data API
        • Quotes
        • Depth
        • History
        • Intervals
        • Symbol
        • Ticker
      • Order Constants
      • HTTP Status Codes
      • Rate Limiting
      • API Collections
  • Symbol Format
  • MCP
  • Trading Platform
    • Amibroker
      • AmiQuotes
      • Button Trading Module
      • Button Trading with Split Orders
      • Button Trading with Stoploss
      • SmartOrder Chart Module
      • Trailing Stoploss Execution Module
      • Line Trading Module
      • Equity Exploration Module
      • CSV Exploration Module
      • Options Button Trading Module
      • Spot/Futures to Options Module (Single Leg)
      • Spot/Futures to Options Module (Two Leg)
      • Time Based Execution
    • Tradingview
    • ChartInk
    • Python
      • Strategy Management
      • EMA Crossover Strategy
      • Supertrend Strategy
      • Supertrend Strategy with yfinance data
      • Voice Based Orders
    • NodeJS
    • Metatrader 5
      • Download & Install Library
      • OpenAlgo MQL5 Functions
      • Include the Header File
      • Sample Expert Advisor
    • Excel
    • Google Spreadsheets
    • N8N
    • Chrome Extension
  • Strategy Management
  • Developers
    • Design Documentation
      • Architecture
      • API Layer
      • Broker Integerations
      • Database Layer
      • Authentication Platforms
      • Configuration
      • Utilities
      • Broker Integration Checklist
  • Change Log
    • Version 1.0.0.24 Launched
    • Version 1.0.0.23 Launched
    • Version 1.0.0.22 Launched
    • Version 1.0.0.21 Launched
    • Version 1.0.0.20 Launched
    • Version 1.0.0.19 Launched
    • Version 1.0.0.18 Launched
    • Version 1.0.0.17 Launched
    • Version 1.0.0.16 Launched
    • Version 1.0.0.15 Launched
    • Version 1.0.0.14 Launched
    • Version 1.0.0.13 Launched
    • Version 1.0.0.12 Launched
    • Version 1.0.0.11 Launched
    • Version 1.0.0.10 Launched
    • Version 1.0.0.9 Launched
    • Version 1.0.0.8 Launched
    • Version 1.0.0.7 Launched
    • Version 1.0.0.6 Launched
    • Version 1.0.0.5 Launched
    • Version 1.0.0.4 Launched
    • Version 1.0.0.3 Launched
    • Version 1.0.0.2 Launched
    • Version 1.0.0.1 Launched
    • Version 1.0.0.0 Launched
Powered by GitBook
On this page
  • OpenAlgo Node.js Library Documentation
  • Get the OpenAlgo API Key
  • Getting Started with OpenAlgo
  • Check OpenAlgo Version
  • PlaceOrder Example
  • PlaceSmartOrder Example
  • BasketOrder Example
  • SplitOrder Example
  • ModifyOrder Example
  • CancelOrder Example
  • CancelAllOrder Example
  • ClosePosition Example
  • OrderStatus Example
  • OpenPosition Example
  • Quotes Example
  • Depth Example
  • History Example
  • Intervals Example
  • Symbol Example
  • Funds Example
  • OrderBook Example
  • TradeBook Example
  • PositionBook Example
  • Holdings Example
  1. Trading Platform

NodeJS

PreviousVoice Based OrdersNextMetatrader 5

Last updated 1 month ago

To install the OpenAlgo Node.js library, use npm:

npm install openalgo

OpenAlgo Node.js Library Documentation

Get the OpenAlgo API Key

Make sure that your OpenAlgo Application is running. Login to the OpenAlgo Application with valid credentials and get the OpenAlgo API key.

For detailed function parameters, refer to the .

Getting Started with OpenAlgo

First, import the OpenAlgo class from the library and initialize it with your API key:

import OpenAlgo from 'openalgo';

// Replace 'YOUR_API_KEY' with your actual API key
// Specify the host URL with your hosted domain or ngrok domain.
// If running locally in Windows then use the default host value.
const openalgo = new OpenAlgo('YOUR_API_KEY', 'http://127.0.0.1:5000');

Check OpenAlgo Version

import { version } from 'openalgo';
console.log(version);

PlaceOrder Example

To place a new order:

const response = await openalgo.placeOrder({
    strategy: "NodeJS",
    symbol: "RELIANCE", 
    action: "BUY",
    exchange: "NSE",
    pricetype: "MARKET",
    product: "MIS",
    quantity: 1
});
console.log(response);

PlaceSmartOrder Example

To place a smart order considering the current position size:

const response = await openalgo.placeSmartOrder({
    strategy: "NodeJS",
    symbol: "TATAMOTORS",
    action: "SELL",
    exchange: "NSE",
    pricetype: "MARKET",
    product: "MIS",
    quantity: 1,
    positionSize: 5
});
console.log(response);

BasketOrder Example

To place a new basket order:

const basketOrders = [
    {
        symbol: "RELIANCE",
        exchange: "NSE",
        action: "BUY",
        quantity: 1,
        pricetype: "MARKET",
        product: "MIS"
    },
    {
        symbol: "INFY",
        exchange: "NSE",
        action: "SELL",
        quantity: 1,
        pricetype: "MARKET",
        product: "MIS"
    }
];

const response = await openalgo.basketOrder({
    strategy: "NodeJS",
    orders: basketOrders
});
console.log(response);

SplitOrder Example

To place a new split order:

const response = await openalgo.splitOrder({
    symbol: "YESBANK",
    exchange: "NSE",
    action: "SELL",
    quantity: 105,
    splitSize: 20,
    pricetype: "MARKET",
    product: "MIS",
    strategy: "NodeJS"
});
console.log(response);

ModifyOrder Example

To modify an existing order:

const response = await openalgo.modifyOrder({
    orderId: "123456789",
    strategy: "NodeJS",
    symbol: "INFY",
    action: "SELL",
    exchange: "NSE",
    pricetype: "LIMIT",
    product: "CNC",
    quantity: 2,
    price: 1900
});
console.log(response);

CancelOrder Example

To cancel an existing order:

const response = await openalgo.cancelOrder({
    orderId: "123456789",
    strategy: "NodeJS"
});
console.log(response);

CancelAllOrder Example

To cancel all open orders and trigger pending orders:

const response = await openalgo.cancelAllOrder({
    strategy: "NodeJS"
});
console.log(response);

ClosePosition Example

To close all open positions across various exchanges:

const response = await openalgo.closePosition({
    strategy: "NodeJS"
});
console.log(response);

OrderStatus Example

To get the current order status:

const response = await openalgo.orderStatus({
    orderId: "123456789",
    strategy: "NodeJS"
});
console.log(response);

OpenPosition Example

To get the current open position:

const response = await openalgo.openPosition({
    strategy: "NodeJS",
    symbol: "YESBANK",
    exchange: "NSE",
    product: "CNC"
});
console.log(response);

Quotes Example

To get real-time quotes:

const response = await openalgo.quotes({
    symbol: "RELIANCE", 
    exchange: "NSE"
});
console.log(response);

Depth Example

To get market depth data:

const response = await openalgo.depth({
    symbol: "SBIN", 
    exchange: "NSE"
});
console.log(response);

History Example

To get historical data:

const response = await openalgo.history({
    symbol: "SBIN",
    exchange: "NSE",
    interval: "5m",
    startDate: "2025-01-01",
    endDate: "2025-01-05"
});
console.log(response);

Intervals Example

To get supported time intervals:

const response = await openalgo.intervals();
console.log(response);

Symbol Example

To get symbol information:

const response = await openalgo.symbol({
    symbol: "RELIANCE",
    exchange: "NSE"
});
console.log(response);

Funds Example

To get account funds information:

const response = await openalgo.funds();
console.log(response);

OrderBook Example

To get the order book:

const response = await openalgo.orderbook();
console.log(response);

TradeBook Example

To get the trade book:

const response = await openalgo.tradebook();
console.log(response);

PositionBook Example

To get the position book:

const response = await openalgo.positionbook();
console.log(response);

Holdings Example

To get holdings:

const response = await openalgo.holdings();
console.log(response);

Please refer to the documentation and consult the API reference for details on optional parameters:

API Documentation
API Documentation
Order Constants