To install the OpenAlgo Node.js library, use npm:
Getting Started with OpenAlgo
Make Sure that your OpenAlgo Application is running. Login to OpenAlgo Application with valid credentials and get the OpenAlgo apikey
For detailed function parameters refer to the API Documentation
First, import the OpenAlgo class from the OpenAlgo library and initialize it with your API key:
Copy const OpenAlgo = require ( 'openalgo' );
// Replace 'your_api_key_here' 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 apiKey = 'your_api_key_here' ;
const host = 'http://127.0.0.1:5000' ;
const openalgo = new OpenAlgo (apiKey , host);
Check OpenAlgo Version
To check the version of the OpenAlgo Node.js library:
Copy const openalgo = require ( 'openalgo' );
console .log ( openalgo .version);
Examples
PlaceOrder Example
To place a new order:
Copy openalgo .placeOrder ({
strategy : 'Test Strategy' ,
symbol : 'RELIANCE' ,
action : 'BUY' ,
exchange : 'NSE' ,
priceType : 'MARKET' ,
product : 'MIS' ,
quantity : 1
}) .then (order => console .log ( 'Order Response:' , order));
PlaceSmartOrder Example
To place a smart order considering the current position size:
Copy openalgo.placeSmartOrder({
strategy: 'Test Strategy',
symbol: 'TATAMOTORS',
action: 'SELL',
exchange: 'NSE',
priceType: 'MARKET',
product: 'MIS',
quantity: 1,
positionSize: 5
}).then(order => console.log('Smart Order Response:', order));
ModifyOrder Example
To modify an existing order:
Copy openalgo .modifyOrder ({
orderId : '123456789' ,
strategy : 'Test Strategy' ,
symbol : 'INFY' ,
action : 'SELL' ,
exchange : 'NSE' ,
priceType : 'LIMIT' ,
product : 'CNC' ,
quantity : 2 ,
price : 1500
}) .then (response => console .log ( 'Modify Order Response:' , response));
ModifyOrder Example
To modify an existing order:
Copy openalgo .modifyOrder ({
orderId : '123456789' ,
strategy : 'Test Strategy' ,
symbol : 'INFY' ,
action : 'SELL' ,
exchange : 'NSE' ,
priceType : 'LIMIT' ,
product : 'CNC' ,
quantity : 2 ,
price : 1500
}) .then (response => console .log ( 'Modify Order Response:' , response));
CancelOrder Example
To cancel an existing order:
Copy openalgo .cancelOrder ({
orderId : '123456789' ,
strategy : 'Test Strategy'
}) .then (response => console .log ( 'Cancel Order Response:' , response));
CancelAllOrder Example
To cancel all open orders and trigger pending orders:
Copy openalgo .cancelAllOrder ({
strategy : 'Test Strategy'
}) .then (response => console .log ( 'Cancel All Orders Response:' , response));
ClosePosition Example
To close all open positions across various exchanges:
Copy openalgo .closePosition ({
strategy : 'Test Strategy'
}) .then (response => console .log ( 'Close Position Response:' , response));
Last updated 3 months ago