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 🙏

© 2026 – Pkg Stats / Ryan Hefner

market-open

v0.0.7

Published

A flexible TypeScript library for managing and predicting broker/exchange trading hours

Downloads

25

Readme

Market-Open

A flexible TypeScript library for managing and predicting broker/exchange trading hours

Fully customizable rules for defining trading schedules, holidays, and special trading sessions

Features

  • 🌍 Timezone-aware scheduling
  • 📅 Customizable weekly trading schedules
  • 🎯 Multiple trading session support (pre-market, regular hours, after-hours)
  • 🏖 Holiday calendar integration
  • 💪 Type-safe configurations
  • ⚡ Zero dependencies (except date-fns-tz)

Installation

npm install broker-schedule

Quick Start

import { Broker } from 'broker-schedule';

// Example usage with pre-configured Robinhood broker
import { Robinhood } from 'broker-schedule/brokers';

// Check if Robinhood is open
const now = new Date();
const isOpen = Robinhood.isOpen(now);

// Get detailed status (PRE_MARKET, OPEN, AFTER_HOURS)
const status = Robinhood.get(now);
console.log('Current trading session:', status);

Creating a Custom Broker

You can create configurations for any broker or exchange by implementing the BrokerConfig interface:

import { Broker, BrokerConfig } from 'broker-schedule';

// Define your status enum
enum CustomBrokerStatus {
    REGULAR = "REGULAR",
    SPECIAL = "SPECIAL",
}

// Define your holiday status enum
enum CustomHolidayStatus {
    CLOSED = "CLOSED",
    HALF_DAY = "HALF_DAY",
}

// Create broker configuration
const customConfig: BrokerConfig<typeof CustomBrokerStatus, typeof CustomHolidayStatus> = {
    name: "Custom Broker",
    timezone: "America/New_York",
    weeklySchedule: [
        {
            day: 1, // Monday
            type: CustomBrokerStatus.REGULAR,
            start: "09:30",
            end: "16:00"
        },
        {
            day: 1, // states can overlap in time
            type: CustomBrokerStatus.SPECIAL,
            start: "7:30",
            end: "20:00"
        }
        // Add more schedule entries...
    ],
    holidays: [
        // Add holiday checking functions
        (date: Date) => {
            // Return holiday status or null
            return null;
        }
    ],
    holidayToStatus: (holiday, dateTime) => {
        // map a holiday status to a opening status
        // this is useful for half-day for example, where half days are defined by the holiday
        // functions, but the hours and status depend on the current time
        if (holiday === CustomHolidayStatus.HALF_DAY) {
            const hours = dateTime.getHours();
            if (hours > 9 && hours < 13) {
                return CustomBrokerStatus.REGULAR;
            }
        }
        return null;
    }
};

// Create broker instance
const customBroker = new Broker(customConfig);

Configuration Options

BrokerConfig

| Property | Type | Description | |----------|------|-------------| | name | string | Broker/exchange name | | timezone | string | Timezone identifier (e.g., "America/New_York") | | weeklySchedule | WeekdaySchedule[] | Array of trading sessions | | holidays | ((date: Date) => HolidayStatus | null)[] | Array of holiday checker functions | | holidayToStatus | (holiday: HolidayStatus, dateTime: Date) => BrokerStatus | null | Holiday status converter |

WeekdaySchedule

| Property | Type | Description | |----------|------|-------------| | day | number | Day of week (0-6, 0 = Sunday) | | type | EnumValue | Trading session type | | start | string | Session start time (HH:mm) | | end | string | Session end time (HH:mm) |

Methods

isOpen(date: Date): boolean

Returns whether the broker is open at the given date/time.

getOpenStatus(date: Date): EnumValue[] | null

Returns the current trading session status(es) or null if closed.

Examples

Checking Multiple Trading Sessions

const broker = new Broker(RobinhoodConfig);
const now = new Date();
const status = broker.getOpenStatus(now);

if (status) {
    status.forEach(session => {
        console.log(`Currently in ${session} trading session`);
    });
} else {
    console.log('Market is closed');
}

Custom Holiday Implementation

const holidays = [
    (date: Date) => {
        // Check for Christmas
        if (date.getMonth() === 11 && date.getDate() === 25) {
            return CustomHolidayStatus.CLOSED;
        }
        return null;
    }
];

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Acknowledgments

This project uses date-fns-tz for timezone handling.