Giter VIP home page Giter VIP logo

node-iex-cloud's People

Contributors

emckay avatar jbooker10 avatar peterdee avatar rehandalal avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

node-iex-cloud's Issues

Tops function returns all symbols even if symbols are specified.

When I use the tops function I get back all symbols no matter what format I send the data in to the tops call. In the example below I expect to get only 3 symbols back. But I get all symbols in the response object res

const { IEXCloudClient } = require("node-iex-cloud");
const fetch = require("node-fetch");
const iex = new IEXCloudClient(fetch,{publishable: "pk_xxxxx", version: "stable"});

iex.tops("AAPL","GOOGL","AMZN").then(res => console.log(res));

Doc typo?

Hello, thanks for the project!

I noticed the doc specifies IEX only allows up to 10 symbols for batch request, but I think the official docs says 100? Maybe IEX made an update recently 🤔
image

Could you double-check ❓

Error: The API Key provided is not valid

``I'm currently attempting a nodeJS project using commonJS modules. Whenever I try to run my server it gives me the following error:

Error: The API key provided is not valid.
at IEXRequest. (D:\Coding\iib\node_modules\node-iex-cloud\lib\request.js:128:31)
at step (D:\Coding\iib\node_modules\node-iex-cloud\lib\request.js:32:23)
at Object.next (D:\Coding\iib\node_modules\node-iex-cloud\lib\request.js:13:53)
at fulfilled (D:\Coding\iib\node_modules\node-iex-cloud\lib\request.js:4:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

This is the code I used to install `node-iex-cloud

`const { IEXCloudClient } = require("node-iex-cloud");
const fetch = require("node-fetch");

const iex_module = new IEXCloudClient(fetch, {
  sandbox: true,
  publishable: "pk_API_KEY",
  version: "stable"
});`

Getting historical data for a specific date

Hi.
I'm trying to get some stock data for a specific date.
The official IEX Cloud documentation suggests the following format:

/stock/aapl/chart/date/20190109?chartByDay=true

The request for the chart data looks like this:

return _this.request('chart/' + range + (params
  ? '?' + Object.entries(params).map(param => `${param[0]}=${param[1]}`).join('&')
  : ''));

As I understand, it's not possible to load the stock data for a specific date.

Please let me know if I can do a PR that adds this functionality.

Doc example for getting the response and mapping it to a state object?

Hi,

I am still quite new to Javascript / Reactjs. I am trying to figure out the syntax for getting the iex response promise object and assigning it to a state object.

Having this as a doc example would be good for others.

This is broken syntax so I'd like to know what the recommend syntax should be...the responses already look like json so it doesn't seem like this would do anything.

    function getCurrentPriceOfBatchStocks(_stock) {
        iex
            .symbols(_stock)
            .price()
            .then(res => res.json());
    }

This gives me:

Unhandled Rejection (TypeError): res.json is not a function"

Called from a button:

<Button
onClick={() => getCurrentPriceOfBatchStocks("googl,amzn,fb,aapl")}>
Get Batch of Stocks - Price
</Button>

It seems to already be a json object though but other examples with fetch show this as valid syntax..

I want to have the response object mapped to a state object like this:

state = {
 stocks: [ { id: 1, name: 'AAPL', price: 329.99 }, { id: 2, name: 'AMZN', price: 2563.05 }]
}

How can I catch errors returned by the iex client?

I am calling the iex client from my own fastify server. However if I give the iex client bad input to cause an exception like an Unknown Symbol, I'm not able to catch the exception in the chain and pass it back on the response.

If I make a call to fastify like this which I expect to fail:
GET http://localhost:4000/batch_stock_prices/?stocks=12312

I get an error response of undefined. However in the node terminal output I can see the exception as seen below.

Is the iex client swallowing errors? Is there any documentation example for how to properly catch errors with this client?

Exception:

09:15:00 ✨ incoming request GET xxx /batch_stock_prices/?stocks=12312
12312
Error: Unknown symbol
    at IEXRequest.<anonymous> (C:\Users\Mclovin\Desktop\modfi-stock-api\node_modules\node-iex-cloud\lib\request.js:128:35)
    at step (C:\Users\Mclovin\Desktop\modfi-stock-api\node_modules\node-iex-cloud\lib\request.js:32:23)
    at Object.next (C:\Users\Mclovin\Desktop\modfi-stock-api\node_modules\node-iex-cloud\lib\request.js:13:53)
    at fulfilled (C:\Users\Mclovin\Desktop\modfi-stock-api\node_modules\node-iex-cloud\lib\request.js:4:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
ReferenceError: response is not defined
    at getCurrentPriceOfBatchStocks (C:\Users\Mclovin\Desktop\modfi-stock-api\src\services\batch_stocks\index.js:18:12)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.<anonymous> (C:\Users\Mclovin\Desktop\modfi-stock-api\src\services\batch_stocks\index.js:53:22)
09:15:00 ✨ request completed 322ms

Code:

'use strict'

const fetch = require('node-fetch')
const { IEXCloudClient } = require("node-iex-cloud")

const iex = new IEXCloudClient(fetch, {
  sandbox: true,
  // publishable: "pk_2f78524e53454cf88afba23c327e24b5",
  publishable: "pk_2f78524e53454cf88afba23c327e24b5",
  version: "stable"
})

async function getCurrentPriceOfBatchStocks(_stock) {

  const stocks_to_submit = _stock['stocks'];
  console.log(stocks_to_submit)

  response = await iex
    .batchSymbols(stocks_to_submit)
    .price()
    .catch(function (error) {
      console.log("Exception: " + error);
      throw error;
    })

  return Promise((resolve, reject) => {
    if (response) {
      resolve(response)
    } else {
      reject(response);
    }
  });
}

const batchStocksSchema = {
  querystring: {
    type: 'object',
    properties: {
      stocks: {
        type: 'string'
      }
    },
    required: ['stocks']
  }
}

module.exports = async function (fastify, opts) {

  fastify.get('/batch_stock_prices/', {
    schema: batchStocksSchema
  }, async function (request, reply) {
    try {
      var response = await getCurrentPriceOfBatchStocks(request.query)
      // console.log(response)
      return reply
        .code(200)
        .send(response);
    } catch (e) {
      console.log(e)
      return reply
        .code(400)
        .send('Bad Request, exception: ' + e)
    }
  })

}

`batchSymbols` fails on 3rd call

Hi.

When calling batchSymbols, I get an error: Error: Not Found when it is invoked for the 3rd time.
This does not happen for single symbols using symbol.

When overwriting fetch to output the request info, I see that the 3rd request has a bad url.

const debugFetch = (info) => {
	console.log(info);
	return fetch(info);
};

const iex = new IEXCloudClient(debugFetch, {...

Output (3 urls are logged at the top):

https://sandbox.iexapis.com/stable/stock/market/batch/batch?symbols=googl&types=balance-sheet,book,cash-flow,ceo-compensation,company,earnings,estimates,financials&range=1m&last=0&token=*****
https://sandbox.iexapis.com/stable/stock/market/batch/batch?symbols=googl&types=fund-ownership,income,largest-trades,logo,news,options,peers,price&range=1m&last=0&token=*****
https://sandbox.iexapis.com/stable/stock//batch?types=quote&range=1m&last=0&token=*****
Error: Not Found
    at IEXRequest.<anonymous> (/home/leedavidcs/projects/app_root/node_modules/node-iex-cloud/lib/request.js:128:35)
    at step (/home/leedavidcs/projects/app_root/node_modules/node-iex-cloud/lib/request.js:32:23)
    at Object.next (/home/leedavidcs/projects/app_root/node_modules/node-iex-cloud/lib/request.js:13:53)
    at fulfilled (/home/leedavidcs/projects/app_root/node_modules/node-iex-cloud/lib/request.js:4:58)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)

This seems to only happen when the 3rd call is made from the same IEXCloudClient instance. So, I can work around this by creating a new IEXCloudClient instance every batch request.

Batch.shortInterest is invalid

Hi.

It appears that when I request batch data with shortInterest with a single symbol nothing is returned.

iex.symbol("googl").batch().shortInterest()...

And when I request batch data with shortInterest with multiple symbols via batchSymbol, I get an error: Error: "types" required with a valid value.

iex.batchSymbols("googl", "aapl").batch().shortInterest()...

I don't see this request within IEX-Cloud docs. Maybe it should be omitted from Batch?

process.env error for publishable?

Hi there, first of thanks for this great project. I am getting an error when I use the API token in a process.env saying that the token is invalid. When I use that exact same token hard coded it works just fine. Do you have a idea why this is happening? I am running on node v14.5.0

const iex = new IEXCloudClient(fetch, {
	sandbox: true,
	publishable: `${process.env.IEX_API_TOKEN}`,
	version: 'stable',
});

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.