chore(plugins/stock): move to community

This commit is contained in:
lowlighter
2022-01-16 19:32:31 -05:00
parent b65a033d34
commit c361d93972
4 changed files with 4 additions and 2 deletions

View File

@@ -0,0 +1,129 @@
<!--header-->
<table>
<tr><th colspan="2"><h3>💹 Stock prices</h3></th></tr>
<tr><td colspan="2" align="center"><p>This plugin displays the stock market price of a given company.</p>
</td></tr>
<tr><th>Authors</th><td><a href="https://github.com/lowlighter">@lowlighter</a></td></tr>
<tr>
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
<td><a href="/source/templates/classic"><code>📗 Classic template</code></a> <a href="/source/templates/repository"><code>📘 Repository template</code></a></td>
</tr>
<tr>
<td><code>👤 Users</code> <code>👥 Organizations</code> <code>📓 Repositories</code></td>
</tr>
<tr>
<td><code>🗝️ plugin_stock_token</code></td>
</tr>
<tr>
<td colspan="2" align="center">
<img src="https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.stock.svg" alt=""></img>
<img width="900" height="1" alt="">
</td>
</tr>
</table>
<!--/header-->
## ➡️ Available options
<!--options-->
<table>
<tr>
<td align="center" nowrap="nowrap">Type</i></td><td align="center" nowrap="nowrap">Description</td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_stock</code></td>
<td rowspan="2"><p>Enable stock plugin</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
<br>
<b>default:</b> no<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_stock_token</code></td>
<td rowspan="2"><p>Yahoo Finance token</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">🔐 Token<br>
<b>type:</b> <code>token</code>
<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_stock_symbol</code></td>
<td rowspan="2"><p>Company stock symbol</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>string</code>
<br></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_stock_duration</code></td>
<td rowspan="2"><p>Time range (relative to current date)</p>
<ul>
<li><code>1d</code>: Today</li>
<li><code>5d</code>: 5 days</li>
<li><code>1mo</code>: 1 month</li>
<li><code>3mo</code>: 3 months</li>
<li><code>6mo</code>: 6 months</li>
<li><code>1y</code>: 1 year</li>
<li><code>2y</code>: 2 years</li>
<li><code>5y</code>: 5 years</li>
<li><code>10y</code>: 10 years</li>
<li><code>ytd</code>: Year to date</li>
<li><code>max</code>: All time</li>
</ul>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>string</code>
<br>
<b>default:</b> 1d<br>
<b>allowed values:</b><ul><li>1d</li><li>5d</li><li>1mo</li><li>3mo</li><li>6mo</li><li>1y</li><li>2y</li><li>5y</li><li>10y</li><li>ytd</li><li>max</li></ul></td>
</tr>
<tr>
<td nowrap="nowrap"><code>plugin_stock_interval</code></td>
<td rowspan="2"><p>Time interval between points</p>
<ul>
<li><code>1m</code>: 1 minute</li>
<li><code>2m</code>: 2 minutes</li>
<li><code>5m</code>: 5 minutes</li>
<li><code>15m</code>: 15 minutes</li>
<li><code>60m</code>: 60 minutes</li>
<li><code>1d</code>: 1 day</li>
</ul>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap"><b>type:</b> <code>string</code>
<br>
<b>default:</b> 5m<br>
<b>allowed values:</b><ul><li>1m</li><li>2m</li><li>5m</li><li>15m</li><li>60m</li><li>1d</li></ul></td>
</tr>
</table>
<!--/options-->
## 🗝️ Obtaining a RapidAPI Yahoo Finance token
Create a [RapidAPI account](https://rapidapi.com) and subscribe to [Yahoo Finance API](https://rapidapi.com/apidojo/api/yahoo-finance1) to get a token.
![RapidAPI token](/.github/readme/imgs/plugin_stock_token.png)
## Examples workflows
<!--examples-->
```yaml
name: Stock prices from Tesla
uses: lowlighter/metrics@latest
with:
filename: metrics.plugin.stock.svg
token: NOT_NEEDED
base: ""
plugin_stock: yes
plugin_stock_token: ${{ secrets.STOCK_TOKEN }}
plugin_stock_symbol: TSLA
```
<!--/examples-->

View File

@@ -0,0 +1,9 @@
- name: Stock prices from Tesla
uses: lowlighter/metrics@latest
with:
filename: metrics.plugin.stock.svg
token: NOT_NEEDED
base: ""
plugin_stock: yes
plugin_stock_token: ${{ secrets.STOCK_TOKEN }}
plugin_stock_symbol: TSLA

View File

@@ -0,0 +1,60 @@
//Setup
export default async function({login, q, imports, data, account}, {enabled = false, token} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled) || (!q.stock))
return null
//Load inputs
let {symbol, interval, duration} = imports.metadata.plugins.stock.inputs({data, account, q})
if (!token)
throw {error:{message:"A token is required"}}
if (!symbol)
throw {error:{message:"A company stock symbol is required"}}
symbol = symbol.toLocaleUpperCase()
//Query API for company informations
console.debug(`metrics/compute/${login}/plugins > stock > querying api for company`)
const {data:{quoteType:{shortName:company}}} = await imports.axios.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-profile", {
params:{symbol, region:"US"},
headers:{"x-rapidapi-key":token},
})
//Query API for sotck charts
console.debug(`metrics/compute/${login}/plugins > stock > querying api for stock`)
const {data:{chart:{result:[{meta, timestamp, indicators:{quote:[{close}]}}]}}} = await imports.axios.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-chart", {
params:{interval, symbol, range:duration, region:"US"},
headers:{"x-rapidapi-key":token},
})
const {currency, regularMarketPrice:price, previousClose:previous} = meta
//Generating chart
console.debug(`metrics/compute/${login}/plugins > stock > generating chart`)
const chart = await imports.chartist("line", {
width:480 * (1 + data.large),
height:160,
showPoint:false,
axisX:{showGrid:false, labelInterpolationFnc:(value, index) => index % Math.floor(close.length / 4) === 0 ? value : null},
axisY:{scaleMinSpace:20},
showArea:true,
}, {
labels:timestamp.map(timestamp => new Intl.DateTimeFormat("en-GB", {month:"2-digit", day:"2-digit", hour:"2-digit", minute:"2-digit"}).format(new Date(timestamp * 1000))),
series:[close],
})
//Results
return {chart, currency, price, previous, delta:price - previous, symbol, company, interval, duration}
}
//Handle errors
catch (error) {
let message = "An error occured"
if (error.isAxiosError) {
const status = error.response?.status
const description = error.response?.data?.message ?? null
message = `API returned ${status}${description ? ` (${description})` : ""}`
error = error.response?.data ?? null
}
throw {error:{message, instance:error}}
}
}

View File

@@ -0,0 +1,77 @@
name: "💹 Stock prices"
category: community
description: This plugin displays the stock market price of a given company.
examples:
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.stock.svg
authors:
- lowlighter
supports:
- user
- organization
- repository
scopes: []
inputs:
plugin_stock:
description: Enable stock plugin
type: boolean
default: no
plugin_stock_token:
description: Yahoo Finance token
type: token
default: ""
plugin_stock_symbol:
description: Company stock symbol
type: string
default: ""
example: MSFT
plugin_stock_duration:
description: |
Time range (relative to current date)
- `1d`: Today
- `5d`: 5 days
- `1mo`: 1 month
- `3mo`: 3 months
- `6mo`: 6 months
- `1y`: 1 year
- `2y`: 2 years
- `5y`: 5 years
- `10y`: 10 years
- `ytd`: Year to date
- `max`: All time
type: string
default: 1d
values:
- 1d
- 5d
- 1mo
- 3mo
- 6mo
- 1y
- 2y
- 5y
- 10y
- ytd
- max
plugin_stock_interval:
description: |
Time interval between points
- `1m`: 1 minute
- `2m`: 2 minutes
- `5m`: 5 minutes
- `15m`: 15 minutes
- `60m`: 60 minutes
- `1d`: 1 day
type: string
default: 5m
values:
- 1m
- 2m
- 5m
- 15m
- 60m
- 1d