diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a6f073f..52e49d3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,13 +2,13 @@ default_language_version: python: python3 repos: - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 24.3.0 hooks: - id: black exclude: ^(dev/) args: [--skip-string-normalization] - repo: https://github.com/myint/autoflake - rev: v2.0.0 + rev: v2.3.1 hooks: - id: autoflake exclude: ^(dev/) @@ -18,7 +18,7 @@ repos: - --remove-all-unused-imports - --remove-duplicate-keys - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-toml - id: check-yaml @@ -27,7 +27,7 @@ repos: - id: trailing-whitespace exclude: ^(dev/) - repo: https://github.com/PyCQA/flake8 - rev: "6.0.0" + rev: "7.0.0" hooks: - id: flake8 name: flake8 except __init__.py @@ -40,20 +40,20 @@ repos: args: [--config, dev/.flake8, "--extend-ignore=F401"] # ignore unused imports in __init__.py files: /__init__\.py$ - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort args: ["--profile", "black"] name: isort except __init__.py exclude: (^(dev/)|/__init__\.py$) - repo: https://github.com/myint/docformatter - rev: v1.4 + rev: v1.7.5 hooks: - id: docformatter exclude: ^(dev/) args: ["--in-place", "--wrap-summaries=88"] - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.15.1 hooks: - id: pyupgrade exclude: ^(dev/) diff --git a/pymempool/api.py b/pymempool/api.py index cbfa4db..a37e902 100644 --- a/pymempool/api.py +++ b/pymempool/api.py @@ -130,6 +130,29 @@ def __send(self, url, data): raise + def get_price(self): + """Returns bitcoin latest price denominated in main currencies.""" + api_url = 'v1/prices' + return self._request(api_url) + + def get_historical_price(self, currency=None, timestamp=None): + """Returns bitcoin historical price denominated in main currencies. + + Available query parameters: currency, timestamp. + If no parameter is provided, the full price history + for all currencies is returned. + """ + api_url = 'v1/historical-price' + connector = "?" + if currency is not None: + currency = str(currency).upper() + api_url += f'{connector}currency={currency}' + connector = "&" + if timestamp is not None: + timestamp = int(timestamp) + api_url += f'{connector}timestamp={timestamp}' + return self._request(api_url) + def get_difficulty_adjustment(self): """Returns details about difficulty adjustment.""" api_url = 'v1/difficulty-adjustment' @@ -230,9 +253,7 @@ def get_block_transactions(self, hash_value, start_index=None): hash_value = hash_value.replace(' ', '') if start_index is not None: start_index = int(start_index) - api_url = '{}block/{}/txs/{}'.format( - self.get_api_base_url(), hash_value, start_index - ) + api_url = f'block/{hash_value}/txs/{start_index}' else: api_url = f'block/{hash_value}/txs' return self._request(api_url) @@ -322,8 +343,8 @@ def get_block_fees(self, time_period): """Returns average total fees for blocks in the specified :timePeriod, ordered oldest to newest. - :timePeriod can be any of the following: - 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y. + :timePeriod can be any of the following: 24h, 3d, 1w, 1m, 3m, + 6m, 1y, 2y, 3y. """ api_url = f'v1/mining/blocks/fees/{time_period}' return self._request(api_url) @@ -332,8 +353,8 @@ def get_block_rewards(self, time_period): """Returns average block rewards for blocks in the specified :timePeriod, ordered oldest to newest. - :timePeriod can be any of the following: - 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y. + :timePeriod can be any of the following: 24h, 3d, 1w, 1m, 3m, + 6m, 1y, 2y, 3y. """ api_url = f'v1/mining/blocks/rewards/{time_period}' return self._request(api_url) @@ -351,8 +372,8 @@ def get_block_sizes_and_weights(self, time_period): """Returns average size (bytes) and average weight (weight units) for blocks in the specified :timePeriod, ordered oldest to newest. - :timePeriod can be any of the following: - 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y. + :timePeriod can be any of the following: 24h, 3d, 1w, 1m, 3m, + 6m, 1y, 2y, 3y. """ api_url = f'v1/mining/blocks/sizes-weights/{time_period}' return self._request(api_url)