![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
A CalendarCache in a private folder: one file per name. POSIX only; not provided on Windows. More...
#include <algotradelib/src/network/calendar_cache.hpp>
Public Member Functions | |
| FileCalendarCache (std::string folder) | |
| Constructs a cache; nothing is created or opened until the first call. | |
| Result< std::optional< TradingCalendar > > | load (const std::string &name) override |
| Reads the name's calendar file. | |
| std::optional< BrokerError > | publish (const std::string &name, const TradingCalendar &calendar) override |
| Replaces the name's calendar file. | |
Friends | |
| struct | FileCalendarCacheTestAccess |
A CalendarCache in a private folder: one file per name. POSIX only; not provided on Windows.
The folder is created (mode 0700) if it does not exist; its parent must. For name N the cache keeps N.calendar: JSON with the format (1), the country, received_at_ns (nanoseconds since the epoch), unreadable_days and the days as [YYYYMMDD, open] pairs in their order. Session hours (TradingDay::regular_, extended_) are not stored: a calendar read back has none. The folder and the file must be owned by the user running the program and give no permission to group or others; a cache that finds otherwise returns its error and leaves them as they were. A symbolic link at the file's name is refused, and so is one at the folder's own name when the folder is given without a trailing separator. A link earlier in the folder's path, or one reached through a trailing separator, is followed: avoiding both is the caller's part, and the folder and file opened must still be the user's alone. Descriptors are closed on exec. A file over 256 KiB, or one that is not well formed, reads as no calendar. publish refuses a calendar received outside what signed 64-bit nanoseconds since the epoch hold, less a day at each end (about the years 1677 to 2262). A count of unreadable days larger than a signed 64-bit integer holds is stored but reads as no calendar.
Writers take no lock: each writes a temporary file of its own, N.calendar.<process>-<count>.tmp, flushes it and renames it over N.calendar, so a reader sees a whole file and the last writer's calendar stays. A writer stopped before its rename can leave its temporary file; it is never read and may be removed.
Definition at line 96 of file calendar_cache.hpp.
|
inlineexplicit |
Constructs a cache; nothing is created or opened until the first call.
| folder | The folder. |
Definition at line 102 of file calendar_cache.hpp.
|
inlineoverridevirtual |
Reads the name's calendar file.
| name | The name. |
Implements algotradelib::network::CalendarCache.
Definition at line 109 of file calendar_cache.hpp.
|
inlineoverridevirtual |
Replaces the name's calendar file.
| name | The name. |
| calendar | The calendar. |
Implements algotradelib::network::CalendarCache.
Definition at line 144 of file calendar_cache.hpp.
|
friend |
Definition at line 166 of file calendar_cache.hpp.