-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarketSession.h
More file actions
31 lines (26 loc) · 1.35 KB
/
Copy pathmarketSession.h
File metadata and controls
31 lines (26 loc) · 1.35 KB
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
#ifndef MARKET_SESSION_H
#define MARKET_SESSION_H
// ---------------------------------------------------------------------------
// Trading-session timing math, split out of ClockLogic's getMarketStatus.
//
// All times are minutes from local midnight (0..1439). A session whose close
// is numerically before its open (endMin < startMin) spans midnight, e.g. an
// overnight future from 20:00 (1200) to 04:00 (240). This midnight-wrap logic
// is exactly where an off-by-one hides, so it lives here dependency-free and
// is unit-tested on the host (test/test_marketsession).
// ---------------------------------------------------------------------------
namespace market
{
// Is nowMin within [startMin, endMin), accounting for a midnight-spanning
// window?
bool inSession(int nowMin, int startMin, int endMin);
// Minutes until the window closes, assuming nowMin is inside it (inSession
// true). Handles being in the pre-midnight half of a spanning session.
int minutesUntilClose(int nowMin, int startMin, int endMin);
// Minutes until the window next opens from nowMin. Returns a negative value
// for a normal same-day window whose open is already past (the caller then
// looks to a later day) - a midnight-spanning window instead wraps to its
// next open.
int minutesUntilOpen(int nowMin, int startMin, int endMin);
} // namespace market
#endif // MARKET_SESSION_H