smartapi-typescript
Version:
TypeScript library for Angel One SmartAPI broker API
165 lines • 7.6 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmartAPI = void 0;
const apiUrls_1 = require("../constants/apiUrls");
const http = __importStar(require("../utils/http"));
// Import modules
const auth_1 = require("../modules/auth");
const orders_1 = require("../modules/orders");
const gtt_1 = require("../modules/gtt");
const portfolio_1 = require("../modules/portfolio");
const brokerage_1 = require("../modules/brokerage");
const misc_1 = require("../modules/misc");
const instruments_1 = require("../modules/instruments");
/**
* SmartAPI client for interacting with Angel One broker API
*/
class SmartAPI {
/**
* Initialize a new SmartAPI client
* @param config SmartAPI configuration
*/
constructor(config) {
this.debug = config.debug || false;
// Initialize HTTP client with base URL
this.httpClient = http.createHttpClient(apiUrls_1.API_URLS.BASE_URL);
// Initialize all modules
this._auth = new auth_1.Auth(config, this.httpClient, this.debug);
this._orders = new orders_1.Orders(this._auth, this.httpClient, this.debug);
this._gtt = new gtt_1.GTT(this._auth, this.httpClient, this.debug);
this._portfolio = new portfolio_1.Portfolio(this._auth, this.httpClient, this.debug);
this._brokerage = new brokerage_1.Brokerage(this._auth, this.httpClient, this.debug);
this._marketData = new misc_1.MarketData(this._auth, this.httpClient, this.debug);
this._instruments = new instruments_1.Instruments(this._auth, this.httpClient, this.debug);
// Bind forward compatibility methods after modules are initialized
this.login = this._auth.login.bind(this._auth);
this.generateSession = this._auth.generateSession.bind(this._auth);
this.getFeedToken = this._auth.getFeedToken.bind(this._auth);
this.logout = this._auth.logout.bind(this._auth);
this.getProfile = this._auth.getProfile.bind(this._auth);
this.placeOrder = this._orders.placeOrder.bind(this._orders);
this.placeBracketOrder = this._orders.placeBracketOrder.bind(this._orders);
this.placeCoverOrder = this._orders.placeCoverOrder.bind(this._orders);
this.modifyOrder = this._orders.modifyOrder.bind(this._orders);
this.cancelOrder = this._orders.cancelOrder.bind(this._orders);
this.getOrderBook = this._orders.getOrderBook.bind(this._orders);
this.getTradeBook = this._orders.getTradeBook.bind(this._orders);
this.getPositions = this._portfolio.getPositions.bind(this._portfolio);
this.getHoldings = this._portfolio.getHoldings.bind(this._portfolio);
this.getAllHoldings = this._portfolio.getAllHoldings.bind(this._portfolio);
this.getLTP = this._marketData.getLTP.bind(this._marketData);
this.getMultiLTP = this._marketData.getMultiLTP.bind(this._marketData);
this.getQuote = this._marketData.getQuote.bind(this._marketData);
this.getMultiQuotes = this._marketData.getMultiQuotes.bind(this._marketData);
this.getHistoricalData = this._marketData.getHistoricalData.bind(this._marketData);
this.getHistoricalDataPaginated = this._marketData.getHistoricalDataPaginated.bind(this._marketData);
this.getFunds = this._portfolio.getFunds.bind(this._portfolio);
this.convertPosition = this._portfolio.convertPosition.bind(this._portfolio);
this.createGTT = this._gtt.createRule.bind(this._gtt);
this.modifyGTT = this._gtt.modifyRule.bind(this._gtt);
this.cancelGTT = this._gtt.cancelRule.bind(this._gtt);
this.getGTTDetails = this._gtt.getRuleDetails.bind(this._gtt);
this.getGTTList = this._gtt.getRuleList.bind(this._gtt);
this.getPublisherLoginUrl = this._auth.getPublisherLoginUrl.bind(this._auth);
this.getWebhookInfo = this._marketData.getWebhookInfo.bind(this._marketData);
this.calculateBrokerage = this._brokerage.calculate.bind(this._brokerage);
this.calculateMargin = this._brokerage.calculateMargin.bind(this._brokerage);
this.getOrderDetails = this._orders.getOrderDetails.bind(this._orders);
this.getOptionGreeks = this._marketData.getOptionGreeks.bind(this._marketData);
// Bind new instruments methods
this.getInstruments = this._instruments.getInstruments.bind(this._instruments);
this.searchScrip = this._instruments.searchScrip.bind(this._instruments);
this.getLtp = this._instruments.getLtp.bind(this._instruments);
this.getNseIntradayScrips = this._instruments.getNseIntradayScrips.bind(this._instruments);
this.getBseIntradayScrips = this._instruments.getBseIntradayScrips.bind(this._instruments);
// Bind new TOTP methods
this.generateTOTP = this._auth.generateTOTP.bind(this._auth);
this.setTOTPSecret = this._auth.setTOTPSecret.bind(this._auth);
}
/**
* Authentication module
* Handles login, session management, logout, and user profile
*/
get auth() {
return this._auth;
}
/**
* Orders module
* Handles placing, modifying, cancelling orders and fetching order details
*/
get orders() {
return this._orders;
}
/**
* GTT (Good Till Triggered) module
* Handles creating, modifying, and cancelling GTT rules
*/
get gtt() {
return this._gtt;
}
/**
* Portfolio module
* Handles positions, holdings, funds and related functionality
*/
get portfolio() {
return this._portfolio;
}
/**
* Brokerage module
* Handles brokerage calculation
*/
get brokerage() {
return this._brokerage;
}
/**
* Market Data module
* Handles data operations like historical candles, LTP, quotes, etc.
*/
get marketData() {
return this._marketData;
}
/**
* Instruments module
* Handles operations related to market instruments, scrips and LTP data
*/
get instruments() {
return this._instruments;
}
}
exports.SmartAPI = SmartAPI;
// Static methods
SmartAPI.parseWebhookData = misc_1.MarketData.parseWebhookData;
//# sourceMappingURL=SmartAPI.js.map