Coder Social home page Coder Social logo

finnhub-stock-api / finnhub-js Goto Github PK

View Code? Open in Web Editor NEW
42.0 3.0 10.0 1.73 MB

Finnhub Javascript API Client. Finnhub API provides institutional-grade financial data to investors, fintech startups and investment firms. We support real-time stock price, global fundamentals and alternative data. https://finnhub.io/docs/api

Home Page: https://finnhub.io/

License: Apache License 2.0

Shell 0.15% JavaScript 99.85%
finnhub stock api

finnhub-js's People

Contributors

dependabot[bot] avatar finnhubio avatar nongdenchet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

finnhub-js's Issues

Cannot access "fs.ReadStream" in client code.

I am trying to set it up.
Following the docs with basic example.

import * as finnhub from 'finnhub'
const api_key = finnhub.ApiClient.instance.authentications['api_key'];
api_key.apiKey = "my_api_key"
const finnhubClient = new finnhub.DefaultApi()

finnhubClient.stockCandles("AAPL", "D", 1590988249, 1591852249, (error, data, response) => {
    console.log(data)
});

I keep getting the following error:

Uncaught Error: Module "fs" has been externalized for browser compatibility. Cannot access "fs.ReadStream" in client code.

Same error with other api calls (symbolSearch, stockSymbols ...)

Do you know why?

Module not found: Error: Can't resolve 'querystring'

I got this error in an electron environment.

ERROR in ./node_modules/finnhub/dist/ApiClient.js 10:42-64
Module not found: Error: Can't resolve 'querystring' in '*******\node_modules\finnhub\dist'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "querystring": require.resolve("querystring-es3") }'
    - install 'querystring-es3'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "querystring": false }

Example for stockCandles in README.md is incorrect

Readme shows example for stockCandles as:

// Stock candles
finnhubClient.stockCandles("AAPL", "D", 1590988249, 1591852249, {}, (error, data, response) => {
    console.log(data)
});

There is an extra empty object shown in the parameters, just before the callback, causing an error:

c:\Users\Glenn\Documents\node_modules\finnhub\dist\ApiClient.js:545
          callback(error, data, response);
          ^

TypeError: callback is not a function
    at c:\Users\Glenn\Documents\node_modules\finnhub\dist\ApiClient.js:545:11
    at Request.callback (c:\Users\Glenn\Documents\node_modules\superagent\lib\node\index.js:905:3)
    at c:\Users\Glenn\Documents\node_modules\superagent\lib\node\index.js:1126:20
    at IncomingMessage.<anonymous> (c:\Users\Glenn\Documents\node_modules\superagent\lib\node\parsers\json.js:22:7)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Process exited with code 1

ping pong documentation

Hello,

Where is the ping documentation, websocket keep disconnecting me after a while, no mention of returning ping/pong but I bet that is the problem, I look at finnhub code, and nowhere do I find any mention of ping pong

server send me {"type":"ping"} every 1-2 mins

I try sending a websocket.ping() or .pong() or {"type":"ping"} or {"type":"pong"} but I still keep getting disconnected. so my question is simple.

Where is the ping pong documentation, what is it exactly do I need to keep telling the finnhub websocket server so my connection stay alive?

Thank you.

stockCandles is not attaching API key to the https request

stockCandles not attaching my API key to the request, causing and "Unauthorized" error. Here is my code, with my API key removed.:

const finnhub = require('finnhub');

const apiKey = finnhub.ApiClient.instance.authentications['api_key'];
apiKey.apikey = '<my api key here>';
const finnhubClient = new finnhub.DefaultApi();

finnhubClient.stockCandles('GOOG', '1', 1631022248, 1631627048, (error, data, response) => {
  console.log('error: ' + error);
  console.log(data);
});

I tried the API call in a browser with my API key and got the response no problem, but when I run the code above, the console shows:

C:\Program Files\nodejs\node.exe .\stock-query.js
error: Error: Unauthorized
null

Here is a chunk of the returned error object, appearing to indicate that the API key was not present in the request:

Error: Unauthorized\n    at Request.callback (c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\index.js:883:15)\n    at c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\index.js:1126:20\n    at IncomingMessage.<anonymous> (c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\parsers\\json.js:22:7)\n    at IncomingMessage.emit (events.js:327:22)\n    at endReadableNT (internal/streams/readable.js:1327:12)\n    at processTicksAndRejections (internal/process/task_queues.js:80:21) {status: 401, response: Response, stack: 'Error: Unauthorized\n    at Request.callback (…tions (internal/process/task_queues.js:80:21)', message: 'Unauthorized'}
error:'Please use an API key.'
__proto__:Object
response:Response {_events: {…}, _eventsCount: 0, _maxListeners: undefined, res: IncomingMessage, request: Request, …}
_events:{}
_eventsCount:0
_maxListeners:undefined
accepted:false
badRequest:false
body:{error: 'Please use an API key.'}
buffered:true
clientError:true
created:false
error:Error: cannot GET /api/v1/stock/candle?symbol=GOOG&resolution=1&from=1631022248&to=1631627048 (401)\n    at Response.toError (c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\response.js:98:13)\n    at ResponseBase._setStatusProperties (c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\response-base.js:119:48)\n    at new Response (c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\response.js:44:8)\n    at Request._emitResponse (c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\index.js:930:18)\n    at c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\index.js:1126:42\n    at IncomingMessage.<anonymous> (c:\\Users\\Glenn\\Documents\\node_modules\\superagent\\lib\\node\\parsers\\json.js:22:7)\n    at IncomingMessage.emit (events.js:327:22)\n    at endReadableNT (internal/streams/readable.js:1327:12)\n    at processTicksAndRejections (internal/process/task_queues.js:80:21) {status: 401, text: '{"error":"Please use an API key."}', method:...
files:undefined
forbidden:false
header:{date: 'Fri, 19 Nov 2021 23:59:09 GMT', content-type: 'application/json', content-length: '34', connection: 'close', access-control-allow-credentials: 'true', …}
headers:{date: 'Fri, 19 Nov 2021 23:59:09 GMT', content-type: 'application/json', content-length: '34', connection: 'close', access-control-allow-credentials: 'true', …}
info:false
links:{}
noContent:false
notAcceptable:false
notFound:false

Extremely slow API calls

This takes 10-15 seconds from the console! Can it be sped up?

index.js:

let ticker = "VYGVF";

//Company profile2
finnhubClient.companyProfile2({'symbol': ticker}, (error, data, response) => {
  console.log(data)
});

//Quote
finnhubClient.quote(ticker, (error, data, response) => {
  console.log(data)
});

// Basic financials
finnhubClient.companyBasicFinancials(ticker, "margin", (error, data, response) => {
  console.log(data)
});

Run node index.js:

$ node index.js
CompanyProfile2 {
  country: 'US',
  currency: 'USD',
  exchange: 'CANADIAN NATIONAL STOCK EXCHANGE',
  name: 'Voyager Digital Ltd',
  ticker: 'VYGR.CN',
  ipo: 1993-06-25T00:00:00.000Z,
  marketCapitalization: 2757.036,
  shareOutstanding: 144.34809,
  logo: '',
  phone: '12125478807.0',
  weburl: 'https://www.investvoyager.com/',
  finnhubIndustry: 'Technology'
}
BasicFinancials {
  symbol: 'VYGR.CN',
  metricType: 'margin',
  metric: {
    'freeOperatingCashFlow/revenue5Y': -835.6595,
    'freeOperatingCashFlow/revenueTTM': 17.49161,
    grossMargin5Y: null,
    grossMarginAnnual: null,
    grossMarginTTM: null,
    netProfitMargin5Y: -3344.131,
    netProfitMarginAnnual: -884.4473,
    netProfitMarginTTM: -129.6673,
    operatingMargin5Y: -4352.564,
    operatingMarginAnnual: -976.558,
    operatingMarginTTM: 27.5644,
    pretaxMargin5Y: -3344.131,
    pretaxMarginAnnual: -884.4473,
    pretaxMarginTTM: -129.6673
  }
}
Quote {
  o: 15.947,
  h: 16.74,
  l: 15.9,
  c: 16.671,
  pc: 15.893,
  d: 0.778,
  dp: 4.8952
}

update deps

Any chance you guys can update your deps? Superagent 5.3.1 has been deprecated.

npm WARN deprecated [email protected]: Please upgrade to v7.0.2+ of superagent.  We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing.  See the releases tab for more information at <https://github.com/visionmedia/superagent/releases>.

Run this library in react native?

Is there a way to run this library in react native?

I'm getting the error:

Unable to resolve module querystring from /home/esferasoluciones/Documents/projects/esferasoluciones/worth/node_modules/finnhub/dist/ApiClient.js: querystring could not be found within the project or in these directories:
node_modules/finnhub/node_modules
node_modules
var _superagent = _interopRequireDefault(require("superagent"));

var _querystring = _interopRequireDefault(require("querystring"));
^

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

Running this code

      const finnhub = require('finnhub');
      const api_key = finnhub.ApiClient.instance.authentications['api_key'];
      api_key.apiKey = "my_sandbox_apikey"
      const finnhubClient = new finnhub.DefaultApi()
  
      finnhubClient.economicCalendar((error, data, response) => {
          console.log(data)
      });

Limit for API calls

Hi,

Within the documentation and the billing information, it says that the max number of API calls for the free tier is 60 API calls/minute. I've been testing out the API using finnhubClient.quote and I'm getting undefined and null back.

I haven't been hitting the API that much, so was wondering if the limit changed or maybe there's something on my end.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.