Time tools¶
dccd.time_tools.TS_to_date (TS[, form, local]) |
Convert timestamp to date in specified format. |
dccd.time_tools.date_to_TS (date[, form]) |
Use your local time-zone to convert date in specific format to timestamp. |
dccd.time_tools.str_to_span (string) |
Return the equivalent interval time in seconds. |
dccd.time_tools.span_to_str (span) |
Return the time periodicity. |
dccd.time_tools.binance_interval (interval) |
Return the time interval in the specific format allowed by Binance. |
Tools to manage some time functions with respect to specific API exchanges.
-
dccd.time_tools.
TS_to_date
(TS, form='%Y-%m-%d %H:%M:%S', local=True)¶ Convert timestamp to date in specified format.
Parameters: - TS : int
A timestamp to convert.
- form : str (default ‘%Y-%m-%d %H:%M:%S’)
Time format.
- local : bool (default is True)
Local time is used if true else return UTC time.
Returns: - date : str
Date as specified format.
Examples
>>> TS_to_date(1548432099, form='%y-%m-%d %H:%M:%S', local=False) '19-01-25 16:01:39'
-
dccd.time_tools.
date_to_TS
(date, form='%Y-%m-%d %H:%M:%S')¶ Use your local time-zone to convert date in specific format to timestamp.
Parameters: - date : str
A date to convert.
- form : str (default ‘%Y-%m-%d %H:%M:%S’)
Time format.
Returns: - TS : int
Timestamp of specified date.
Examples
# >>> date_to_TS(‘19-01-25 16:01:39’, form=’%y-%m-%d %H:%M:%S’) # 1548428499
-
dccd.time_tools.
str_to_span
(string)¶ Return the equivalent interval time in seconds.
Parameters: - string : str
Time periodicity
Returns: - span : int
Number of seconds in time interval.
Examples
>>> str_to_span('minutely') 60
-
dccd.time_tools.
span_to_str
(span)¶ Return the time periodicity.
Parameters: - span : int
Time interval in second.
Returns: - date : str
Time periodicity.
Examples
>>> span_to_str(3600) 'Hourly'
-
dccd.time_tools.
binance_interval
(interval)¶ Return the time interval in the specific format allowed by Binance.
Parameters: - interval : int
Must be in seconds as 60, 180, 300, 900, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 259200, 604800, 2592000.
Returns: - form : str
Specific format allowed by Binance.
Examples
>>> binance_interval(7200) '2h'