The official Node.js library for the SnapTrade API.
Contact us to schedule a demo and get a consumer key: api@snaptrade.com
- ⚙️ Requirements
- 🚀 Getting Started
- 🕵🏼♂️ Authentication
- 📑 Full Documentation
- 👨🏼⚖️ License & Copyrights
- Node 17 or later
- You need to have a clientID and a consumerKey. If you don't have one, please send us an email.
npm install snaptrade-node
Note : Your consumerKey should always remain a secret! Never hard code it!
import { SnapTradeFetch } from 'snaptrade-node';
const snapTrade = new SnapTradeFetch('CLIENT_ID', 'CONSUMER_KEY');
Register user with SnapTrade in order to create secure brokerage authorizations.
registerUser(data: {
userId: string;
rsaPublicKey?: string;
}): Promise<RegisterUserResponseType>
const registerUser = async () => {
const registeredUser = await snapTrade.registerUser({
userId: 'USER_ID',
rsaPublicKey: 'ssh-rsa RSA_PUBLIC_KEY', //only required if RSA is enabled for the partner
});
return registeredUser;
};
Generate a redirect URI to securely login a user to the SnapTrade Connection Portal.
- optional parameters:
- broker: provide a
broker slug
to redirect user directly to the broker portal (or show the auth modal) - immediateRedirect: if set to
true
, user gets redirected back to the partner's app immediately after making a connection. - customRedirect: if need to use a different
redirect url
than the default one. - reconnect: provide a
authorization id
of a broken connection to reconnect.
- broker: provide a
generateRedirectURI({
userId,
userSecret,
}: DefaultQueryParams, data: {broker: string; immediateRedirect: boolean; customRedirect: string, reconnect: string}): Promise<RedirectURIResponseType>
const redirectURI = async () => {
const uri = await snapTrade.generateRedirectURI(
{
userId: 'USER_ID',
userSecret: 'USER_SECRET',
},
{
broker: 'ALPACA',
immediateRedirect: true,
customRedirect: 'https://passiv.com',
reconnect: 'b5f262d-4bb9-365d-888a-202bd3b15fa1',
}
);
return uri;
};
Delete user from SnapTrade, disabling all brokerage authorizations and permanently deleting all data associated with the user.
deleteUser({
userId,
userSecret,
}: DefaultQueryParams): Promise<DeleteUserResponseType>
const deleteUser = async () => {
const deletedUser = await snapTrade.deleteUser({
userId: 'USER_ID',
userSecret: 'USER_SECRET',
});
return deletedUser;
};
Documentations for making requests to other SnapTrade API endpoints using this sdk:
- Helper Functions
- Account Information Endpoints
- Trading Endpoints
- Connections Endpoints
- Reference Data Endpoints
- Transaction and Reporting Endpoints
Licensed under Apache License 2.0.