Skip to content

Instantly share code, notes, and snippets.

@davidhq
Last active December 27, 2025 15:17
Show Gist options
  • Select an option

  • Save davidhq/9dcc1d713654fac0d2048d3f9c4933d6 to your computer and use it in GitHub Desktop.

Select an option

Save davidhq/9dcc1d713654fac0d2048d3f9c4933d6 to your computer and use it in GitHub Desktop.
brent crude price changes
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