Time

Time is represented by the standard DateTime from Base.Dates and ZonedDateTime from TimeZones.jl for more precise timing.

Note
  • A standard DateTime will 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_timeFunction
current_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.

source
Trading.market_open_closeFunction
market_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"))
source
Trading.in_dayFunction
in_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"))
true
source
Trading.previous_trading_dayFunction
previous_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:00
source
Trading.is_market_openFunction
is_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"))
false
source
Trading.is_market_closeFunction
is_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"))
false
source

Clock