inves-broker
inves-broker
provides a unified interface for dealing with multiple broker APIs in the Indian stock market.
Currently supported brokers
- Kite by Zerodha
- Paytm Money
Quick Start
npm install inves-broker
import { IConnect, BrokerName } from 'inves-broker';
const kite = IConnect(BrokerName.KITE, {
kiteAPIKey: process.env.KITE_API_KEY,
kiteAPISecret: process.env.KITE_API_SECRET
});
const kiteUrl = await kite.getLoginURL({});
const paytm = IConnect(BrokerName.PAYTM_MONEY, {
paytmMoneyAPIKey: process.env.PAYTM_API_KEY,
paytmMoneyAPISecret: process.env.PAYTM_API_SECRET
});
const paytmUrl = await paytm.getLoginURL({});
Why
Building a platform to support order placement and retrieval via multiple brokers is an exhaustive task. To achieve the same end goal, each broker has a slightly different way of doing things. Integrating each broker would require extensive reading of all the documentation followed by a tedious implementation.
How do we solve for multiple brokers under a common interface?
We enforce a standard of how you should place an order, get order information, etc. This standard closely conforms to Zerodha's way of doing things. If you are familiar with using the Kite API, you will find inves-broker
's interface to be similar. For exceptional cases where a broker cannot fit within a standard, we provide an extended support for that. Hence, all brokers under inves-broker
follow the Open-closed principle.
Usage
Each broker class will provide the methods listed here. In some cases, it will be necessary to deviate from the standard. This is described below.
Paytm Money and Dhan
Paytm Money and Dhan identify an instrument via its list of security ids. This list needs to be downloaded once a day. By default, when you place an order, this list is downloaded and stored in memory for the next 24 hours. Hence, the first call to place an order would be slow. Subsequent calls would just hit the cache. However, if you wish to pre-fetch this list, even before you invoke the placeOrder
method, you can do this via following:
import { IConnect, BrokerName, PaytmMoneyBroker } from 'inves-broker';
const broker = IConnect(BrokerName.PAYTM_MONEY, config);
if (broker instanceof PaytmMoneyBroker) {
await broker.triggerMemoizationOfSecurityList();
}
Contributing
- We follow the conventional commit message spec. It's recommended that you read more about on conventionalcommits.org.
- Each accepted pull request will be squashed and merged.