Time
Time is represented by the standard DateTime from Base.Dates and ZonedDateTime from TimeZones.jl for more precise timing.
- A standard
DateTimewill be assumed to be in central Europe / Zurich time - Trading.jl is at present not aware of holidays or other market altering behavior, i.e. trading days are assumed to always be Monday-Friday; 9:30am - 4pm.
Utility Functions
These can be pulled into the main namespace by using Trading.Time.
Trading.current_time — Functioncurrent_time()
current_time(broker)
current_time(trader)Returns the current time either globally, or of an broker or Trader which is essentially the same as the trader's broker.
Trading.market_open_close — Functionmarket_open_close(time, timezone=tz"EST")Returns the open and closing time of the market located in timezone, and converts it to the local timezone, i.e. central european time. It assumes opening at 9:30am and closing at 4pm.
Example
julia> Trading.market_open_close(DateTime("2023-04-05"))
(DateTime("2023-04-05T15:30:00"), DateTime("2023-04-05T22:00:00"))Trading.in_day — Functionin_day(time, args...)Returns true if the time is within the trading hours on a weekday. The args are passed to market_open_close.
Example
julia> Trading.in_day(DateTime("2023-02-02T00:00:00"))
false
julia> Trading.in_day(DateTime("2023-02-02T15:00:00"))
trueTrading.previous_trading_day — Functionprevious_trading_day(time)Returns the previous trading day, i.e. skipping saturdays and sundays.
Example
julia> Trading.previous_trading_day(DateTime("2023-04-06"))
2023-04-05T00:00:00
julia> Trading.previous_trading_day(DateTime("2023-04-03"))
2023-03-30T00:00:00Trading.is_market_open — Functionis_market_open(time, interval=Minute(1))Tests whether a given time is within interval before market open.
Example
julia> Trading.is_market_open(DateTime("2023-04-04T15:31:00"))
false
julia> Trading.is_market_open(DateTime("2023-04-04T15:30:00"))
true
julia> Trading.is_market_open(DateTime("2023-04-04T15:29:00"))
true
julia> Trading.is_market_open(DateTime("2023-04-04T15:28:00"))
falseTrading.is_market_close — Functionis_market_close(time, interval=Minute(1))Tests whether a given time is within interval before market close.
Example
julia> Trading.is_market_close(DateTime("2023-04-04T22:01:00"))
false
julia> Trading.is_market_close(DateTime("2023-04-04T22:00:00"))
true
julia> Trading.is_market_close(DateTime("2023-04-04T21:59:00"))
true
julia> Trading.is_market_close(DateTime("2023-04-04T21:58:00"))
falseTrading.only_trading — Functiononly_trading(ta::TimeArray)Filters for data in ta during trading sessions. Uses in_day.
Clock
Trading.Clock — TypeClockRepresents the internal time of a Trader or AbstractBroker. Its time is updated by Timer and returned by current_time if it is called on the Trader or AbstractBroker. It also stores dt, the timestamp interval when the Clock is updated manually, for example when being used with a HistoricalBroker.