Is the Stock Market Open Today? #API
@calpa
code:
data:privatelast updated:3 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
nodejs
auth
to use OAuth tokens and API keys in code via theauths object
params
AUTH TOKEN
 
string ·params.AUTH_TOKEN
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
}
37
const axios = require('axios');
const moment = require('moment');
const { get } = require('lodash');

axios.defaults.baseURL = 'https://sandbox.tradier.com/v1/';
axios.defaults.headers.common['Authorization'] = `Bearer ${params.AUTH_TOKEN}`;

const arrayToObject = (array, keyField) =>
   array.reduce((obj, item) => {
     obj[item[keyField]] = item
     return obj
   }, {})

try {
  const { data } = await axios.get('markets/calendar', {
    params: {
      month: moment().month() +1,
      year: moment().year()
    }
  });
  // const dates = arrayToObject(get(data, 'calendar.days.day'), 'date');
  // console.log(dates);
  // $checkpoint = dates;
  
  const today = data.calendar.days.day.find(item => item.date === moment().format('YYYY-MM-DD'));

  $respond({
    status: 200,
    body: today.status === 'open',
  });

  return today;
} catch (err) {
  console.error(err);
}