Replace time.time with arrow.utcnow().timestamp

arrow is imported already
This commit is contained in:
Matthias 2018-08-15 13:18:52 +02:00
parent 76914c2c07
commit baeffee80d
2 changed files with 8 additions and 8 deletions

View File

@ -6,7 +6,6 @@ from random import randint
from typing import List, Dict, Tuple, Any, Optional
from datetime import datetime
from math import floor, ceil
import time
import asyncio
import ccxt
@ -379,7 +378,7 @@ class Exchange(object):
logger.debug("one_call: %s", one_call)
input_coroutines = [self._async_get_candle_history(
pair, tick_interval, since) for since in
range(since_ms, int(time.time() * 1000), one_call)]
range(since_ms, arrow.utcnow().timestamp * 1000, one_call)]
tickers = await asyncio.gather(*input_coroutines, return_exceptions=True)
# Combine tickers
@ -412,7 +411,7 @@ class Exchange(object):
# so we fetch it from local cache
if (not since_ms and
self._pairs_last_refresh_time.get(pair, 0) + interval_in_sec >=
int(time.time())):
arrow.utcnow().timestamp):
data = self._cached_klines[pair]
logger.debug("Using cached klines data for %s ...", pair)
else:

View File

@ -3,9 +3,9 @@
import logging
from datetime import datetime
from random import randint
import time
from unittest.mock import Mock, MagicMock, PropertyMock
import arrow
import ccxt
import pytest
@ -575,7 +575,7 @@ def test_get_history(default_conf, mocker, caplog):
exchange = get_patched_exchange(mocker, default_conf)
tick = [
[
int(time.time() * 1000), # unix timestamp ms
arrow.utcnow().timestamp * 1000, # unix timestamp ms
1, # open
2, # high
3, # low
@ -592,7 +592,7 @@ def test_get_history(default_conf, mocker, caplog):
# one_call calculation * 1.8 should do 2 calls
since = 5 * 60 * 500 * 1.8
print(f"since = {since}")
ret = exchange.get_history(pair, "5m", int((time.time() - since) * 1000))
ret = exchange.get_history(pair, "5m", int((arrow.utcnow().timestamp - since) * 1000))
assert exchange._async_get_candle_history.call_count == 2
# Returns twice the above tick
@ -603,7 +603,7 @@ def test_get_history(default_conf, mocker, caplog):
async def test__async_get_candle_history(default_conf, mocker, caplog):
tick = [
[
int(time.time() * 1000), # unix timestamp ms
arrow.utcnow().timestamp * 1000, # unix timestamp ms
1, # open
2, # high
3, # low
@ -642,7 +642,8 @@ async def test__async_get_candle_history(default_conf, mocker, caplog):
with pytest.raises(OperationalException, match=r'Could not fetch ticker data*'):
api_mock.fetch_ohlcv = MagicMock(side_effect=ccxt.BaseError)
exchange = get_patched_exchange(mocker, default_conf, api_mock)
await exchange._async_get_candle_history(pair, "5m", int((time.time() - 2000) * 1000))
await exchange._async_get_candle_history(pair, "5m",
(arrow.utcnow().timestamp - 2000) * 1000)
@pytest.mark.asyncio