Last active
December 27, 2025 15:17
-
-
Save davidhq/9dcc1d713654fac0d2048d3f9c4933d6 to your computer and use it in GitHub Desktop.
brent crude price changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import path from 'path'; | |
| import { homedir } from 'os'; | |
| import axios from 'axios'; | |
| import { log, executeAt } from 'dmt/common'; | |
| import { push } from 'dmt/notify'; | |
| const OILPRICE_API_TOKEN = '...'; | |
| import sendNotification from '../lib/sendNotification.js'; | |
| import send from '../lib/send.js'; | |
| import reportError from '../lib/reportError.js'; | |
| import { oilPricesStore } from '../lib/stores.js'; | |
| const THRESHOLD_OIL = 5; // % | |
| function getIcon(diff, threshold) { | |
| if (diff >= 0) { | |
| return '🛢️'; | |
| } | |
| return '🛢️🔻'; | |
| } | |
| function oilPrice() { | |
| return new Promise((success, reject) => { | |
| axios | |
| .get('https://api.oilpriceapi.com/v1/prices/latest', { | |
| headers: { | |
| Authorization: `Token ${OILPRICE_API_TOKEN}` | |
| } | |
| }) | |
| .then(response => { | |
| success(response.data?.data?.price); | |
| }) | |
| .catch(reject); | |
| }); | |
| } | |
| function getPrices() { | |
| return new Promise((success, reject) => { | |
| oilPrice() | |
| .then(oilPrice => { | |
| // brentCrudePrice | |
| success({ oilPrice }); | |
| }) | |
| .catch(reject); | |
| }); | |
| } | |
| export default function init(program) { | |
| const brentCrudeSlot = oilPricesStore.slot('brentCrude'); | |
| const brentCrudeReadingsSlot = oilPricesStore.slot('brentCrudeReadings').makeArray(); | |
| executeAt('17:00', () => { | |
| getPrices() | |
| .then(({ oilPrice }) => { | |
| sendNotification({ | |
| ticker: 'CRUDE OIL', | |
| price: oilPrice, | |
| slot: brentCrudeSlot, | |
| readingsSlot: brentCrudeReadingsSlot, | |
| timestamp: Date.now(), | |
| threshold: THRESHOLD_OIL, | |
| roundDecimals: 1, | |
| currencySymbol: '$', | |
| getIcon, | |
| send | |
| }); | |
| }) | |
| .catch(reportError('OilPriceAPI')); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment