How to get historical stock data between two dates? - node.js

Im trying to get historical data for Apple from google finance.
but the start and end time is always the same.
in google-finance module sending a get request with these params to http://www.google.com/finance/historical should result in historical data between the dates but it returns last year instead.
var params = { q: 'AAPL',
startdate: '2014-01-01',
enddate: '2014-12-31',
output: 'csv'
};
google-finance module example :
gFinance.historical({
symbol: 'NASDAQ:AAPL',
from: '2014-01-01',
to: '2014-12-31'
}, function (err, quotes) {
console.log(quotes);
});
result is always from today (8 oct 2017) to one year earlier(8 oct 2016):
...
{ date: 2017-02-22T20:30:00.000Z,
open: 137.38,
high: 137.48,
low: 136.3,
close: 136.53,
volume: 20788186,
symbol: 'NASDAQ:AAPL' },
{ date: 2017-02-23T20:30:00.000Z,
open: 135.91,
high: 136.66,
low: 135.28,
close: 136.66,
volume: 21776585,
symbol: 'NASDAQ:AAPL' },
{ date: 2017-02-26T20:30:00.000Z,
open: 137.14,
high: 137.44,
low: 136.28,
close: 136.93,
volume: 20257426,
symbol: 'NASDAQ:AAPL' },
{ date: 2017-02-27T20:30:00.000Z,
open: 137.08,
high: 137.44,
low: 136.7,
close: 136.99,
volume: 23482860,
symbol: 'NASDAQ:AAPL' },
{ date: 2017-02-28T20:30:00.000Z,
open: 137.89,
high: 140.15,
low: 137.6,
close: 139.79,
volume: 36414585,
symbol: 'NASDAQ:AAPL' },
{ date: 2017-03-01T20:30:00.000Z,
open: 140,
high: 140.28,
low: 138.76,
close: 138.96,
volume: 26210984,
symbol: 'NASDAQ:AAPL' },
{ date: 2017-03-02T20:30:00.000Z,
open: 138.78,
high: 139.83,
low: 138.59,
close: 139.78,
volume: 21571121,
symbol: 'NASDAQ:AAPL' },
... 151 more items ]
I dont know if they changed something or they closed it like yahoo did or Im doing something wrong.
I searched for a week and everything seems outdated.
how can I get historical data between custom times with http request?

Gogle finance works as expected :
http://finance.google.com/finance/historical?q=AAPL&startdate=2014-01-01&enddate=2014-12-31&output=csv
You didn't put any source code.

Related

Node.js - Get font properties description

Is it possible to access the Description part of a font properties, as shown when you right-click on the file?
Here, I'm interested in the Title attribute, for example.
I've used the get-file-properties package as described in Node JS - read file properties, but it doesn't seem to have access to it (it's using wmic behind the scenes, which doesn't return it either). For example, Title doesn't exist, and Description returns C:\\Windows\\Fonts\\Alegreya-Bold.ttf
Is there another way to access this information?
Thanks
As #RobinMackenzie mentionned, there's the ttfinfo package (https://github.com/trevordixon/ttfinfo), which will give you the info on a specific font in this form:
{
tables: {
name: {
'0': 'Copyright 2011 The Alegreya Project Authors (https://github.com/huertatipografica/Alegreya)',
'1': 'Alegreya',
'2': 'Bold',
'3': '2.003;HT ;Alegreya-Bold',
'4': 'Alegreya Bold',
'5': 'Version 2.003; ttfautohint (v1.6)',
'6': 'Alegreya-Bold',
'8': 'Huerta Tipografica',
'9': 'Juan Pablo del Peral',
'11': 'http://www.huertatipografica.com',
'12': 'http://www.huertatipografica.com',
'13': 'This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is available with a FAQ at: http://scripts.sil.org/OFL',
'14': 'http://scripts.sil.org/OFL',
'256': 'Roman numerals',
'257': 'Arrows, triangles and circles',
'258': 'Foundry icon',
'259': 'Dynamic arrows and triangles'
},
post: {
format: 2,
italicAngle: 0,
underlinePosition: 0,
underlineThickness: 0,
minMemType42: 16734720,
maxMemType42: 1509968640,
minMemType1: 1258291200,
maxMemType1: 0
},
'OS/2': { version: 4, weightClass: 700 }
}
}
A full list of the names (0, 1, 2,...) can be found here: https://learn.microsoft.com/en-us/typography/opentype/spec/name#name-ids
There's also node-system-fonts (https://github.com/jgilsaa/node-system-fonts), which requires a build step as it's a C++ module, but on the plus side, gives you a lot of the same info, for every installed font:
[
{
path: 'C:\\WINDOWS\\FONTS\\ARIAL.TTF',
postscriptName: 'ArialMT',
family: 'Arial',
style: 'Regular',
weight: 400,
width: 5,
italic: false,
monospace: false
},
{
path: 'C:\\WINDOWS\\FONTS\\ARIALN.TTF',
postscriptName: 'ArialNarrow',
family: 'Arial Narrow',
style: 'Regular',
weight: 400,
width: 3,
italic: false,
monospace: false
},
{
path: 'C:\\WINDOWS\\FONTS\\ARIALI.TTF',
postscriptName: 'Arial-ItalicMT',
family: 'Arial',
style: 'Italic',
weight: 400,
width: 5,
italic: true,
monospace: false
},
...
]

Sequelize, how to use Op.contains to find models that have certain values

I'm working on some project about renting houses and appartments and I've reached the point when i need to implement filtering houses based on features they have(wifi, security and other staff). In the beginning I decided to try Sequelize ORM for the first time. Stuff like adding, creating, editing is working fine, but the filtering part is where I have some problems.
I'm working with nodejs,express and postgresql.
I need to find all houses that have features listed in the array of features IDs. Here is what I've tried. In this example I'm trying to get houses which have features with ids 1, 2 and 4.
db.House.findAll({
include: [{
model: db.HouseFeature,
as: 'HouseFeatures',
where: {
featureId: {
[Op.contains]: [1, 2, 4] //<- array of featuresIds
}
}
}]
})
Fetching houses by single feature id works fine because i don't use Op.contains there.
Here are some relations related to this case:
House.hasMany(models.HouseFeature, { onDelete: 'CASCADE' });
HouseFeature.belongsTo(models.House);
HouseFeature contains featureId field.
Here is the error I get:
error: оператор не существует: integer #> unknown
at Connection.parseE (C:\***\server\node_modules\pg\lib\connection.js:601:11)
at Connection.parseMessage (C:\***\server\node_modules\pg\lib\connection.js:398:19)
at Socket.<anonymous> (C:\***\server\node_modules\pg\lib\connection.js:120:22)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 397,
severity: 'ОШИБКА',
code: '42883',
detail: undefined,
hint:
'Оператор с данными именем и типами аргументов не найден. Возможно, вам следует добавить явные приведения типов.',
position: '851',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file:
'd:\\pginstaller.auto\\postgres.windows-x64\\src\\backend\\parser\\parse_oper.c',
line: '731',
routine: 'op_error',
sql:
'SELECT "House"."id", "House"."title", "House"."description", "House"."price", "House"."address", "House"."lat", "House"."lon", "House"."kitchen", "House"."bathrooms", "House"."floor", "House"."totalFloors", "House"."people", "House"."area", "House"."bedrooms", "House"."trusted", "House"."createdAt", "House"."updatedAt", "House"."CityId", "House"."ComplexId", "House"."OwnerProfileId", "House"."HouseTypeId", "House"."RentTypeId", "HouseFeatures"."id" AS "HouseFeatures.id", "HouseFeatures"."featureId" AS "HouseFeatures.featureId", "HouseFeatures"."createdAt" AS "HouseFeatures.createdAt", "HouseFeatures"."updatedAt" AS "HouseFeatures.updatedAt", "HouseFeatures"."HouseId" AS "HouseFeatures.HouseId" FROM "Houses" AS "House" INNER JOIN "HouseFeatures" AS "HouseFeatures" ON "House"."id" = "HouseFeatures"."HouseId" AND "HouseFeatures"."featureId" #> \'1,2\';'
Sorry for some russian there.
UPDATE:
I've managed to do what i needed by changing each House relating only to one HouseFeature, and by changing that HouseFeature model to store array of featureIds. Op.contains works fine.
db.House.findAll({
include: [{
model: db.HouseFeature,
as: 'HouseFeature',
where: {
features: {
[Op.contains]: req.body.features
}
},
}]
})
// Associations
HouseFeature.belongsTo(models.House);
House.hasOne(models.HouseFeature, { onDelete: 'CASCADE' });
const HouseFeature = sequelize.define('HouseFeature', {
features: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
}
}, {});
Now i have one little issue. Can I somehow link HouseFeature model with Feature model to fetch feature icon images and name later on? With Feature ids being stored inside HouseFeature array.
Please check the difference between Op.in and Op.contains:
[Op.in]: [1, 2], // IN [1, 2]
[Op.contains]: [1, 2] // #> [1, 2] (PG array contains operator)
It looks like HouseFeatures.featureId is a PK with type integer, not a postgres array.
Please try:
db.House.findAll({
include: [{
model: db.HouseFeature,
as: 'HouseFeatures',
where: {
featureId: {
[Op.in]: [1, 2, 3]
}
}
}]
})
or even
db.House.findAll({
include: [{
model: db.HouseFeature,
as: 'HouseFeatures',
where: {
featureId: [1, 2, 3]
}
}]
})
instead

python html table is only getting first row

I'm trying to parse historical data for Bitcoin. Instead of getting 30 in 30 rows, I'm getting one days repeated 30 times.
import requests
import urllib.request
from bs4 import BeautifulSoup
url = "https://coinmarketcap.com/currencies/bitcoin/historical-data/"
r = requests.get(url)
html_content = r.text
soup = BeautifulSoup(html_content,"html.parser")
for tr in soup.find_all('tr')[6]:
tds = soup.find_all('td')
print ("date: %s, Open: %s, High:%s, Low: %s, Close: %s, Volume: %s, Marketcap: %s\n" % \
(tds[0].text,tds[1].text,tds[2].text,tds[3].text,tds[4].text, tds[5].text, tds[6].text))
Here's the output:
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
I should be getting data for the dates, Apr 30 - May 29
What am I missing?
You can apply a variable for all data like this:
soup = BeautifulSoup(html_content,"html.parser")
i=1
for trs in soup.find('table'):
# tds = soup.find_all('td')
i=i+1
print(trs.text)
print(i)

Mongoose: moment().format not working

Im having Mongoose schema as follows:
createdOn: {
type: String,
//default: Date.now,
default: moment(new Date(Date.now())).format('MMM Do YY') //npm install moment --save # npm
},
updatedOn: {
type: String,
//default: Date.now
default: moment(new Date(Date.now())).format('MMM Do YY')
}
UPDATE:
After changing the type to String,
I get :
Fri Jul 28 2017 14:43:40 GMT+0530 (IST)
How to remove the time and SMT.
I need to keep only Fri Jul 28 2017
I installed Moment package of node js (http://momentjs.com/)
Whats wrong in my schema above:
I get
MongooseError: Cast to date failed for value "Aug 7th 17" at path "updatedOn"
message: 'Cast to date failed for value "Aug 7th 17" at path "updatedOn"',
name: 'CastError',
stringValue: '"Aug 7th 17"',
kind: 'date',
value: 'Aug 7th 17',
path: 'updatedOn',
reason: undefined }
The double default assignment looks wrong.
default: default: moment(new Date(Date.now())).format('MMM Do YY')
As a better practice, you should consider just using UNIX timestamps rather than formatted date strings. Timestamps will allow you to easily track statistics on the database.
So you could just use the:
Date.now() // returns a UNIX timestamp
In moment.js a UNIX timestamp:
moment().unix()
If for some reason you need the timestamp in a string format you could always just do:
moment().unix() + ''

No UiSlider remove decimal?

How to remove decimals digit from linked output
I am using this code
$("#slider_01").noUiSlider({
start: [2000, 24000],
connect: true,
step: 0.01,
range: {
'min': 0,
'max': 28500
},
format: wNumb({
decimals: false,
thousand: ',',
prefix: '$ ',
})
});
$('#slider_01').Link('lower').to($('#value-lower_1'));
$('#slider_01').Link('upper').to($('#value-upper_1'));
I didn't have access to the wNumb library in the environment I was working with.
Had a look under the hood in the library and this also works:
$("#slider_01").noUiSlider({
...
format: {
to: (v) => parseFloat(v).toFixed(0),
from: (v) => parseFloat(v).toFixed(0)
}
});
Decimals decimals: false is invalid, use decimals: 0. Also, you are setting formatting for the .val() method. Use it like this:
$('#slider_01').Link('lower').to($('#value-lower_1'), null, wNumb({
decimals: 0,
thousand: ',',
prefix: '$ ',
}));
Change the step from 0.01 to 1.
I know it's a very old question, but I did not want to include another library Wnumb just to remove the decimal from one place. Here is my solution without using the wnumb.
var slider = document.getElementById('prcsldr');
noUiSlider.create(slider, {
start: [10000],
range: {
min: 1000,
max: 50000
},
step: 1000,
format:{
to: (v) => v | 0,
from: (v) => v | 0
}
});

Resources