Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/agent/market_hours.rs: Add market hours format implementation #93

Merged
merged 4 commits into from
Nov 23, 2023

Conversation

drozdziak1
Copy link
Contributor

@drozdziak1 drozdziak1 commented Nov 21, 2023

Motivation

This is the first in a series of changes realizing the market hours feature for conditional publishing according to dedicated market hours metadata. This change introduces a market hours format that lets us define a weekly schedule for a market, along with its local timezone. The format works as follows:

MarketHours ::= TimeZoneSpec,MHKind,MHKind,MHKind,MHKind,MHKind,MHKind,MHKind
TimeZoneSpec ::= Continent/Country  # e.g. Europe/Paris
MHKind::= O | C | HHMMTime-HHMMTime # e.g. 09:00-17:00, O means Open all day, C means Closed all day
HHMMTime ::= [0-23]:[0-59] # e.g. 15:21

Examples

  • 9 - 5 Mon - Fri in Hong Kong Asia/Hong_Kong,9:00-17:00,9:00-17:00,9:00-17:00,9:00-17:00,9:00-17:00,C,C
  • 24/7 (e.g. many crypto assets) Europe/Lisbon,O,O,O,O,O,O,O - This will probably be the default for symbols with no market hours metadata

Summary of changes

  • src/agent/metrics.rs - rustfmt really wanted me to add this
  • src/agent/market_hours.rs - The core of the change
  • Cargo.toml, Cargo.lock - Bump chrono version, add chrono_tz

Review highlights

  • src/agent/market_hours.rs - I think it would make sense to have more non-trivial timezone handling tests, including DST chanes etc.,ideas welcome

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. I think there's one issue here with day wrapping (see inline) but good aside from that.

match self {
Self::Open => true,
Self::Closed => false,
Self::TimeRange(start, end) => start <= &when_market_local && &when_market_local <= end,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to support 24:00 in the format so that you can have intervals like:

17:00-24:00,00:00-17:00 (for 5pm on the first day through 5pm on the second day).

I think this current check will stop publishing between 11:59 pm and midnight every day if you're not careful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can you add a test case for this day wraparound behavior?

Copy link
Contributor Author

@drozdziak1 drozdziak1 Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a very good observation. I added support for explicit 24:00 to mean 23:59:59.999(...) down to a nanosecond and tested how it works.

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@drozdziak1 drozdziak1 merged commit 75497df into main Nov 23, 2023
2 checks passed
@drozdziak1 drozdziak1 deleted the drozdziak1/market-hours-format branch November 23, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants