@stoqey/finnhub
Version:
NodeJS Finhubb wrapper
91 lines (65 loc) • 1.63 kB
Markdown
<img alt="NPM" src="https://circleci.com/gh/stoqey/finnhub.svg?style=svg"></img>
- Candles
- Tick
- Quote
- Real-time price updates
- Company Profile2
- Recommendation Trends
- Peers
```
npm i @stoqey/finnhub
or
yarn add @stoqey/finnhub
```
Set env variable `FINNHUB_KEY` with the token you get from Finnhub.
or simply assign it from the constructors
```ts
import FinnhubAPI, { FinnhubWS } from '@stoqey/finnhub';
// For API
const finnhubAPI = new FinnhubAPI(finnHubKey);
// For Websockets
const finnhubWs = new FinnhubWS(finnHubKey); // or leave finnHubKey blank if process.env.FINNHUB_KEY is set
```
```ts
const candles = await finnhubAPI.getCandles(symbol, startDate, endDate, '1');
```
```ts
const ticks = await finnhubAPI.getTick(symbol, date);
```
```ts
const quote = await finnhubAPI.getQuote(symbol);
```
```ts
const companyProfile = await finnhubAPI.getCompanyProfile2(symbol);
```
```ts
const recommendations = await finnhubAPI.GetRecommendationTrends(symbol);
```
```ts
const peers = await finnhubAPI.getPeers(symbol);
```
```ts
finnhubWs.on("onReady", async () => {
console.log('WS is ready');
});
finnhubWs.on("onData", async (data: TickData) => {
console.log('WS onData', data);
});
// Add symbol to streaming list
finnhubWs.addSymbol("AAPL");
// Stop streaming symbol
finnhubWs.removeSymbol("AAPL");
```
Set `process.env.DEBUG = "finnhub*"` to see all logs