diff --git a/qubipy/config.py b/qubipy/config.py index d84a2a2..b4626b3 100644 --- a/qubipy/config.py +++ b/qubipy/config.py @@ -7,6 +7,8 @@ CORE_URL = 'https://api.qubic.org/v1' +MONERO_URL = 'https://xmr-stats.qubic.org' # This URL is only used to obtain monero mining stats. + TIMEOUT = 5 HEADERS = { diff --git a/qubipy/core/core_client.py b/qubipy/core/core_client.py index 3895c6c..b979247 100644 --- a/qubipy/core/core_client.py +++ b/qubipy/core/core_client.py @@ -541,4 +541,32 @@ def get_qx_fees(self) -> Dict[str, Any]: return data except requests.RequestException as E: raise QubiPy_Exceptions(f"Error when getting QX fees: {str(E)}") from None + + def get_monero_mining_stats(self) -> Dict[str, Any]: + + """ + Retrieves current Monero mining statistics from the external Monero system. + + This function makes an API call to fetch real-time or recent data related + to Monero network mining. + + Returns: + Dict[str, Any]: A dictionary containing various statistics related to Monero mining, + such as pool and network hashrates, network difficulty, block height, + and other relevant pool/miner data. The exact structure and content + depend on the Monero API response. + + Raises: + QubiPy_Exceptions: If there is an issue during the API request execution (e.g., + a network connection error, a non-2xx HTTP status code from the + API server, a timeout during the request, or if the API + response cannot be parsed as valid JSON). + """ + try: + response = requests.get(f'{MONERO_URL}{MONERO_MINING_STATS}', headers=HEADERS, timeout=self.timeout) + response.raise_for_status() # Raise an exception for bad HTTP status codes + data = response.json() + return data + except requests.RequestException as E: + raise QubiPy_Exceptions(f"Error when getting the monero mining stats: {str(E)}") from None diff --git a/qubipy/endpoints_core.py b/qubipy/endpoints_core.py index 9808b2f..2fbe7b3 100644 --- a/qubipy/endpoints_core.py +++ b/qubipy/endpoints_core.py @@ -42,4 +42,8 @@ QX_ENTITY_BID_ORDERS = '/qx/getEntityBidOrders' -QX_FEES = '/qx/getFees' \ No newline at end of file +QX_FEES = '/qx/getFees' + +# MONERO MINING STATS + +MONERO_MINING_STATS = '/stats' \ No newline at end of file diff --git a/qubipy/endpoints_rpc.py b/qubipy/endpoints_rpc.py index 58a5626..565bd0d 100644 --- a/qubipy/endpoints_rpc.py +++ b/qubipy/endpoints_rpc.py @@ -48,7 +48,7 @@ RICH_LIST = '/rich-list' -# Testing +# ASSETS ASSETS_ISSUANCE = '/assets/issuances'