Code Monkey home page Code Monkey logo

stocks.js's People

Contributors

cvarisco avatar wagenaartje 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

stocks.js's Issues

Error hashtable

Should we use an error hashtable to throw errors? Or is there any other cleaner way we could handle errors? At this moment, the _checkOptions function is very ugly and unreadable. We need to find a way to fix this.

Something I thought of was:

Stocks.prototype.ERRORS = {
  0: 'Some error message'
  1: 'Some other error message'
  2: ...
} 

So you could easily call errors like:

throw new Error(this.ERRORS[0])

But I think there is a better solution out there...

Stocks is not a constructor

var Stocks = require("stocks.js");
const stocks = new Stocks("J4AUAHBUZ1DQDSA0");

export default function Form() {
  const [stock, setStock] = useState("");
  const callApi = async () => {
    var result = await stocks.timeSeries(options);
    var options = {
      symbol: "AAPL",
      interval: "daily",
      start: new Date("2020-07-01"),
      end: new Date("2020-09-09"),
    };
    console.log(result);
  }

timeSeries does not work

"use strict";
exports.__esModule = true;
var stocks = require("stocks.js");
stocks.API_KEY = 'XXXX';
stocks.timeSeries({
    symbol: 'TSLA',
    interval: '1min',
    amount: 10
}, function (err, res) {
    console.log(res);
});

Debugged a little bit and the URL created is messed up, the interval is rewritten

Processing Key:function = TIME_SERIES_intraday 
Processing Key:symbol = TSLA 
Processing Key:outputsize = full 
Processing Key:1min = undefined1min 
This is the URL: [https://www.alphavantage.co/query?apikey=Q7U8TQA8Q5ZBYYTY&function=TIME_SERIES_intraday&symbol=TSLA&outputsize=full&1min=undefined1min&]

Stacktrace if useful:

Error: An error occured. Please create an issue at https://github.com/wagenaartje/stocks/issues with your code, and provide the following message: Invalid API call, please visit doc
umentation (https://www.alphavantage.co/documentation/) for function: TIME_SERIES_INTRADAY                                                                                           
    at exports.XMLHttpRequest.request.onload (/app/node_modules/stocks.js/src/stocks.js:56:21)
    at exports.XMLHttpRequest.dispatchEvent (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
    at setState (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:614:14)                            
    at IncomingMessage.<anonymous> (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
    at emitNone (events.js:110:20)                                                                
    at IncomingMessage.emit (events.js:207:7)                                                                        
    at endReadableNT (_stream_readable.js:1047:12)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)           
    at process._tickCallback (internal/process/next_tick.js:161:9) 

Use URL.searchParams

Once URL.searchParams has compability with more browsers, we can use this to simplify the _createURL function. At this moment, the function is supported by:

  • Chrome ^51.0
  • Firefox ^52.0
  • Node ^7.5.0

The usage is pretty simple, example:

var url = new URL('https://www.alphavantage.co/query?');
var params = {
  function: 'TIME_SERIES_INTRADAY',
  symbol: 'MSFT',
  interval: '1min',
  apikey: 'demo'  
};

Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))

For Node, all you need to do is add:

var URL = require('url').URL;

Please generate ES5 code in dist

To avoid errors like: Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode.

I'm using a very tight project setup for a minimal project, therefore I don't want to bloat up the project with a transpilation just for this library.

TypeError: this._throw is not a function

Any time I enter an incorrect stock symbol, I get this error:

TypeError: this._throw is not a function

Yet it still works when I give a correct stock symbol. Do you know how I can resolve this issue?

Alphavantage removed intraday data for interval like 1min, 5min, hourly etc

{
    "Error Message": "The intraday time series encountered an internal or external error - we apologize for the inconvenience. If you would like to obtain the realtime stock quote for the current trading day, please refer to the latest data point of our DAILY and DAILY ADJUSTED functions (e.g., https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo | https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo)."
}

More intervals

Is there a way to include more intervals for day trading, for example 2h/4h?

ReferenceError: Stocks is not defined

I am confused. I use stocks.js like

var Stocks = require("stocks.js");
var stocks = new Stocks('XXXX');       
                                                       

stocks.timeSeries({                                                 
    symbol: 'TSLA',                                                 
    interval: '1min',                                               
    amount: 10                                                      
}, function (err, res) {                                            
    console.log(res);                                               
}); 

Also, I installed stocks.js with npm.
However, I got an error "ReferenceError: Stocks is not defined"

Is there any suggestion?
Thanks in advance.

proposals

Hi @wagenaartje !

I like your idea ๐Ÿ™‚ , and I started a little refactoring on my fork with your code style.
But I propose a contribution guide to help other people to contribute.
And it would be great if everything is written in ES6.

What do you think about it ?
Have a nice day ๐ŸŒฎ

Get current stock price?

Checked through the code and did some tests but want to make sure im not totally missing something. Can I get the current price with any of the calls, or can Alpha Vantage return that at all? I only want to pull the current price like once an hour so it doesn't have to be down to the second or anything.

nodejs broken

I guess the commit of the global variable broke nodejs [https://github.com/wagenaartje/stocks.js/commit/8548d96010f2f48dbf7bc649bf27883dd07fbc01].

program:

var stocks = require("stocks.js");                                  
stocks.API_KEY = 'XXXX';                                            
stocks.timeSeries({                                                 
    symbol: 'TSLA',                                                 
    interval: '1min',                                               
    amount: 10                                                      
}, function (err, res) {                                            
    console.log(res);                                               
}); 

result:

stocks.timeSeries({
       ^

TypeError: stocks.timeSeries is not a function
    at Object.<anonymous> (/app/app3.js:3:8)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

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.