npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trading-calendar

v1.1.1

Published

a Node.js library that allows you to check if an exchange is open or closed at a specific date (or in real-time).

Downloads

27

Readme

Trading Calendar

Build npm licence

A NodeJS library that allows you to check if an exchange is open or closed. You can check if the market is trading today and if the trading session is live right now. You can also check historical and futures dates with the condition that the year is supported. Create multiple exchange objects to check status of multiple exchanges easily.

Feel free to contribute with adding more exchanges and years.

List of features

  • Check if trading today
  • Check if trading right now
  • Check if trading at specific date (with or without time)

Supported exchanges

  • new-york
  • stockholm
  • oslo
  • paris (2022)

Supported years

  • 2021
  • 2022

Installation

$ npm i trading-calendar

Code Example

const { exchange } = require('trading-calendar');

const stockholm = exchange('stockholm');
if(stockholm.isTradingNow()){
  // Stockholm is open right now
} else {
  // Stockholm is closed right now
}

Documentation

Get all supported exchanges

const { supportedExchanges } = require('trading-calendar');

console.log(supportedExchanges); // => [ 'stockholm' ]

Create an Exchange object (Check supported exchanges for valid input)

const { exchange } = require('trading-calendar');

const stockholm = exchange('stockholm');

Example of an Exchange object:

Exchange {
  name: 'stockholm',
  timezone: 'Europe/Stockholm',
  openTime: { hour: 9, minute: 0 },
  closeTime: { hour: 17, minute: 30 },
  calendar: {
    '2021': {
      January: [Array],
      April: [Array],
      May: [Array],
      June: [Array],
      December: [Array]
    }
  }
}

Explanation:

  • name - name of exchange
  • timezone - timezone of exchange
  • openTime - local opening time of exchange
  • closeTime - local closeing time of exchange
  • calendar - calendar strucutre of the days that the exchange is closed

Functions of an Exchange object:

  • isTradingToday(): boolean
  • isTradingNow(): boolean
  • isTradingDay(date: string | Date | DateTime): boolean
  • isTradingTime(date: string | Date | DateTime): boolean

isTradingToday(): boolean - Check if the exchange will be open today

const { exchange } = require('trading-calendar');

const stockholm = exchange('stockholm');
if(stockholm.isTradingToday()){
  // Stockholm is open today
} else {
  // Stockholm is closed today
}

isTradingNow(): boolean - Check if the exchange is open right now

const { exchange } = require('trading-calendar');

const stockholm = exchange('stockholm');
if(stockholm.isTradingNow()){
  // Stockholm is open right now
} else {
  // Stockholm is closed right now
}

isTradingDay(date: string | Date | DateTime): boolean - Check if the exchange was / will be open at a specific date. The function can take three different inputs. String should be in the format yyyy-mm-dd. Date is the standard Javascript object. DateTime is an object created by the package Luxon.

const { DateTime } = require('luxon');
const { exchange } = require('trading-calendar');

// Example of all three
const stringDate = '2021-08-11';
// const date = new Date('2021-08-11');
// const time = DateTime.fromFormat('2021-08-11', 'yyyy-MM-dd');

const stockholm = exchange('stockholm');
if(stockholm.isTradingDay(stringDate)){
  // Stockholm is open at the date 2021-08-11
} else {
  // Stockholm is closed at the date 2021-08-11
}

isTradingTime(date: string | Date | DateTime): boolean - Check if the exchange was / will be open at a specific date including time. The function can take three different inputs. String should be in the format yyyy-mm-dd-HH24:MI. Date is the standard Javascript object. DateTime is an object created by the package Luxon.

const { DateTime } = require('luxon');
const { exchange } = require('trading-calendar');

// Example of all three
const stringTime = '2021-08-11-14:30';
// const date = new Date('2021-08-11');
// date.setHours(14);
// date.setMinutes(30);
// time = DateTime.fromFormat('2021-08-11-14:30', 'yyyy-MM-dd-HH:mm');

const stockholm = exchange('stockholm');
if(stockholm.isTradingTime(stringTime)){
  // Stockholm is open at the date + time 2021-08-11-14:30
} else {
  // Stockholm is closed at the date + time 2021-08-11-14:30
}

Tests

Unit testing with Jest. Run with:

$ npm test

Contributing

Feel free to add more features or fix bugs

Adding support for more exchanges and years is also appreciated.

Author

  • David Söderberg

License

This project is licensed under the MIT License