Time and date tools (dccd.tools.date_time)¶
Tools to manage some time functions with respect to specific API exchanges.
- TS_to_date(TS, form='%Y-%m-%d %H:%M:%S', tz='local')[source]¶
Convert timestamp to date in specified format.
- Parameters:
- TSint
A timestamp to convert.
- formstr, optional
strftime format string. Default
'%Y-%m-%d %H:%M:%S'.- tzstr, optional
Timezone to use.
'local'(default) uses the system timezone,'UTC'uses UTC, any other value is interpreted as an IANA timezone name (e.g.'Europe/Paris').
- Returns:
- str
Date formatted according to form.
Examples
>>> TS_to_date(1548432099, form='%y-%m-%d %H:%M:%S', tz='UTC') '19-01-25 16:01:39'
- binance_interval(interval)[source]¶
Return the time interval in the specific format allowed by Binance.
- Parameters:
- intervalint
Must be in seconds as 60, 180, 300, 900, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 259200, 604800, 2592000.
- Returns:
- formstr
Specific format allowed by Binance.
Examples
>>> binance_interval(7200) '2h'
- date_to_TS(date, form='%Y-%m-%d %H:%M:%S', tz='local')[source]¶
Convert a date string to a Unix timestamp.
- Parameters:
- datestr
Date string to convert.
- formstr, optional
strftime format string. Default
'%Y-%m-%d %H:%M:%S'.- tzstr, optional
Timezone used to interpret date.
'local'(default) uses the system timezone,'UTC'treats the string as UTC, any other value is an IANA timezone name (e.g.'Europe/Paris').
- Returns:
- int
Unix timestamp.
Examples
>>> date_to_TS('2019-01-25 16:01:39', tz='UTC') 1548432099
- span_label(span)[source]¶
Return a short directory-safe label for span seconds.
- Parameters:
- spanint
Candle interval in seconds.
- Returns:
- str
Short label (e.g.
'1m','1h','1d'). Falls back to'{span}s'for unknown spans.
Examples
>>> span_label(3600) '1h' >>> span_label(86400) '1d' >>> span_label(7777) '7777s'
- span_to_str(span)[source]¶
Return the time periodicity label for the given span in seconds.
- Parameters:
- spanint
Time interval in seconds. Supported values: 60, 180, 300, 900, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 259200, 604800, 1296000, 2592000.
- Returns:
- datestr
Time periodicity label used for directory naming.
Examples
>>> span_to_str(3600) 'Hourly'
- str_to_span(string)[source]¶
Return the equivalent interval time in seconds.
- Parameters:
- stringstr
Time periodicity. Accepted values (case-insensitive):
'monthly','1M','15d','weekly','3d','daily','12h','8h','6h','4h','bi-hourly','hourly','half-hourly','quarter-hourly','5min','3m','minutely', and common aliases.
- Returns:
- spanint
Number of seconds in time interval.
Examples
>>> str_to_span('minutely') 60