Skip to content

Commit

Permalink
feat(chart): { return: "array" } (default) + test fix (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadicc committed Nov 22, 2021
1 parent de22ffc commit 1ac66c3
Show file tree
Hide file tree
Showing 5 changed files with 1,007 additions and 32 deletions.
47 changes: 46 additions & 1 deletion docs/modules/chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,50 @@ const result = await yahooFinance._chart(query, queryOptions);
'ytd', 'max'
]
},
quotes: [
{
date: new Date("2020-05-08T13:30:00.000Z"),
high: 77.5875015258789,
volume: 133838400,
open: 76.41000366210938,
low: 76.07250213623047,
close: 77.53250122070312,
adjclose: 76.78629302978516 // if requested
},
// ...
]
events: {
dividends: [
{ amount: 0.205, date: new Date("2020-05-08T13:30:00.000Z") },
// ...
],
splits: [
{
date: new Date("2020-08-31T13:30:00.000Z"),
numerator: 4,
denominator: 1,
splitRatio: '4:1'
},
// ...
]
}
}
```

The above includes a number of transforms from the original object format
received from Yahoo, which makes the data a bit easier to work with. It uses
the query default of `{ return: "array" }`. However, certain charting
libraries might actually prefer the original format, which you can get with
`{ return: "object" }`, as follows:

```js

const query = 'AAPL';
const queryOptions = { period1: '2021-05-08', return: "object", /* ... */ };
const result = await yahooFinance._chart(query, queryOptions);

{
meta: { /* same format as previous example */ },
timestamp: [
// These are the object keys used below.
1598880600,
Expand Down Expand Up @@ -120,7 +164,8 @@ Yahoo Symbol, e.g. "AAPL", "TSLA", etc.
| `interval` | string | "1d" | Interval period (see below)
| `includePrePost` | boolean | true |
| `events` | string | "div\|split\|earn" | Event types to return, "\|"-separated
| `lang` | string | "en-US"
| `lang` | string | "en-US" |
| **`return`** | string | "array" | "array" or "object", see examples above. Not sent to Yahoo.


Dates* can be:
Expand Down
215 changes: 206 additions & 9 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
},
"additionalProperties": false
},
"ChartResult": {
"ChartResultObject": {
"type": "object",
"properties": {
"meta": {
Expand All @@ -167,10 +167,10 @@
}
},
"events": {
"$ref": "#/definitions/ChartEvents"
"$ref": "#/definitions/ChartEventsObject"
},
"indicators": {
"$ref": "#/definitions/ChartIndicators"
"$ref": "#/definitions/ChartIndicatorsObject"
}
},
"required": [
Expand Down Expand Up @@ -296,7 +296,7 @@
],
"additionalProperties": false
},
"ChartEvents": {
"ChartEventsObject": {
"type": "object",
"properties": {
"dividends": {
Expand All @@ -306,10 +306,6 @@
"$ref": "#/definitions/ChartEventSplits"
}
},
"required": [
"dividends",
"splits"
],
"additionalProperties": false
},
"ChartEventDividends": {
Expand Down Expand Up @@ -364,7 +360,7 @@
],
"additionalProperties": false
},
"ChartIndicators": {
"ChartIndicatorsObject": {
"type": "object",
"properties": {
"quote": {
Expand Down Expand Up @@ -444,6 +440,81 @@
],
"additionalProperties": false
},
"ChartResultArray": {
"type": "object",
"properties": {
"meta": {
"$ref": "#/definitions/ChartMeta"
},
"events": {
"$ref": "#/definitions/ChartEventsArray"
},
"quotes": {
"type": "array",
"items": {
"$ref": "#/definitions/ChartResultArrayQuote"
}
}
},
"required": [
"meta",
"quotes"
],
"additionalProperties": false
},
"ChartEventsArray": {
"type": "object",
"properties": {
"dividends": {
"type": "array",
"items": {
"$ref": "#/definitions/ChartEventDividend"
}
},
"splits": {
"type": "array",
"items": {
"$ref": "#/definitions/ChartEventSplit"
}
}
},
"additionalProperties": false
},
"ChartResultArrayQuote": {
"type": "object",
"properties": {
"date": {
"yahooFinanceType": "date"
},
"high": {
"yahooFinanceType": "number"
},
"low": {
"yahooFinanceType": "number"
},
"open": {
"yahooFinanceType": "number"
},
"close": {
"yahooFinanceType": "number"
},
"volume": {
"yahooFinanceType": "number"
},
"adjclose": {
"yahooFinanceType": "number"
}
},
"required": [
"date",
"high",
"low",
"open",
"close",
"volume"
],
"additionalProperties": false
},
"ChartOptions": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -492,13 +563,139 @@
},
"lang": {
"type": "string"
},
"return": {
"type": "string",
"enum": [
"array",
"object"
]
}
},
"required": [
"period1"
],
"additionalProperties": false
},
"ChartOptionsWithReturnArray": {
"type": "object",
"properties": {
"period1": {
"anyOf": [
{
"yahooFinanceType": "date"
},
{
"type": "string"
},
{
"yahooFinanceType": "number"
}
]
},
"period2": {
"anyOf": [
{
"yahooFinanceType": "date"
},
{
"type": "string"
},
{
"yahooFinanceType": "number"
}
]
},
"useYfid": {
"type": "boolean"
},
"interval": {
"type": "string",
"enum": [
"1d",
"1wk",
"1mo"
]
},
"includePrePost": {
"type": "boolean"
},
"events": {
"type": "string"
},
"lang": {
"type": "string"
},
"return": {
"type": "string",
"const": "array"
}
},
"additionalProperties": false,
"required": [
"period1"
]
},
"ChartOptionsWithReturnObject": {
"type": "object",
"properties": {
"period1": {
"anyOf": [
{
"yahooFinanceType": "date"
},
{
"type": "string"
},
{
"yahooFinanceType": "number"
}
]
},
"period2": {
"anyOf": [
{
"yahooFinanceType": "date"
},
{
"type": "string"
},
{
"yahooFinanceType": "number"
}
]
},
"useYfid": {
"type": "boolean"
},
"interval": {
"type": "string",
"enum": [
"1d",
"1wk",
"1mo"
]
},
"includePrePost": {
"type": "boolean"
},
"events": {
"type": "string"
},
"lang": {
"type": "string"
},
"return": {
"type": "string",
"const": "object"
}
},
"required": [
"period1",
"return"
],
"additionalProperties": false
},
"HistoricalResult": {
"type": "array",
"items": {
Expand Down
Loading

0 comments on commit 1ac66c3

Please sign in to comment.