MCPcopy Create free account
hub / github.com/ccxt/ccxt / assert_timestamp

Function assert_timestamp

python/ccxt/test/exchange/base/test_shared_methods.py:114–136  ·  view source on GitHub ↗
(exchange, skipped_properties, method, entry, now_to_check=None, key_name_or_index='timestamp', allow_null=True)

Source from the content-addressed store, hash-verified

112
113
114def assert_timestamp(exchange, skipped_properties, method, entry, now_to_check=None, key_name_or_index='timestamp', allow_null=True):
115 log_text = log_template(exchange, method, entry)
116 skip_value = exchange.safe_value(skipped_properties, key_name_or_index)
117 if skip_value is not None:
118 return # skipped
119 is_date_time_object = isinstance(key_name_or_index, str)
120 if is_date_time_object:
121 assert (key_name_or_index in entry), 'timestamp key "' + key_name_or_index + '" is missing from structure' + log_text
122 else:
123 # if index was provided (mostly from fetchOHLCV) then we check if it exists, as mandatory
124 assert not (entry[key_name_or_index] is None), 'timestamp index ' + string_value(key_name_or_index) + ' is undefined' + log_text
125 ts = entry[key_name_or_index]
126 assert ts is not None or allow_null, 'timestamp is null' + log_text
127 if ts is not None:
128 assert isinstance(ts, numbers.Real), 'timestamp is not numeric' + log_text
129 assert isinstance(ts, int), 'timestamp should be an integer' + log_text
130 min_ts = 1230940800000 # 03 Jan 2009 - first block
131 max_ts = 2147483648000 # 19 Jan 2038 - max int
132 assert ts > min_ts, 'timestamp is impossible to be before ' + str(min_ts) + ' (03.01.2009)' + log_text # 03 Jan 2009 - first block
133 assert ts < max_ts, 'timestamp more than ' + str(max_ts) + ' (19.01.2038)' + log_text # 19 Jan 2038 - int32 overflows # 7258118400000 -> Jan 1 2200
134 if now_to_check is not None:
135 max_ms_offset = 60000 # 1 min
136 assert ts < now_to_check + max_ms_offset, 'returned item timestamp (' + exchange.iso8601(ts) + ') is ahead of the current time (' + exchange.iso8601(now_to_check) + ')' + log_text
137
138
139def assert_timestamp_and_datetime(exchange, skipped_properties, method, entry, now_to_check=None, key_name_or_index='timestamp', allow_null=True):

Callers 1

Calls 4

log_templateFunction · 0.85
string_valueFunction · 0.85
safe_valueMethod · 0.80
iso8601Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…