XMRigAPI
A class to interact with the XMRig miner API.
Attributes:
Name | Type | Description |
---|---|---|
_miner_name |
str
|
Unique name for the miner. |
_ip |
str
|
IP address of the XMRig API. |
_port |
str
|
Port of the XMRig API. |
_access_token |
Optional[str]
|
Access token for authorization. |
_base_url |
str
|
Base URL for the XMRig API. |
_json_rpc_url |
str
|
URL for the JSON RPC. |
_summary_url |
str
|
URL for the summary endpoint. |
_backends_url |
str
|
URL for the backends endpoint. |
_config_url |
str
|
URL for the config endpoint. |
_headers |
Dict[str, str]
|
Headers for all API/RPC requests. |
_json_rpc_payload |
Dict[str, Union[str, int]]
|
Default payload to send with RPC request. |
data |
XMRigProperties
|
Instance of XMRigProperties for accessing cached data. |
Source code in xmrig/api.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
__init__(miner_name, ip, port, access_token=None, tls_enabled=False, db_url=None)
Initializes the XMRig instance with the provided IP, port, and access token.
The ip
can be either an IP address or domain name with its TLD (e.g. example.com
). The schema is not
required and the appropriate one will be chosen based on the tls_enabled
value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
miner_name
|
str
|
A unique name for the miner. |
required |
ip
|
str
|
IP address or domain of the XMRig API. |
required |
port
|
str
|
Port of the XMRig API. |
required |
access_token
|
Optional[str]
|
Access token for authorization. Defaults to None. |
None
|
tls_enabled
|
bool
|
TLS status of the miner/API. Defaults to False. |
False
|
db_url
|
Optional[str]
|
Database URL for storing miner data. Defaults to None. |
None
|
Source code in xmrig/api.py
get_all_responses()
Retrieves all responses from the API.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if successful, or False if an error occurred. |
Raises:
Type | Description |
---|---|
XMRigAuthorizationError
|
If an authorization error occurs. |
XMRigConnectionError
|
If a connection error occurs. |
XMRigAPIError
|
If a general API error occurs. |
Source code in xmrig/api.py
get_endpoint(endpoint)
Updates the cached data from the specified XMRig API endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
str
|
The endpoint to fetch data from. Should be one of 'summary', 'backends', or 'config'. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the cached data is successfully updated or False if an error occurred. |
Raises:
Type | Description |
---|---|
XMRigAuthorizationError
|
If an authorization error occurs. |
XMRigConnectionError
|
If a connection error occurs. |
XMRigAPIError
|
If a general API error occurs. |
Source code in xmrig/api.py
perform_action(action)
Controls the miner by performing the specified action.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action
|
str
|
The action to perform. Valid actions are 'pause', 'resume', 'stop', 'start'. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the action was successfully performed, or False if an error occurred. |
Raises:
Type | Description |
---|---|
XMRigConnectionError
|
If a connection error occurs. |
XMRigAPIError
|
If a general API error occurs. |
Source code in xmrig/api.py
post_config(config)
Updates the miners config data via the XMRig API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration data to update. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the config was changed successfully, or False if an error occurred. |
Raises:
Type | Description |
---|---|
XMRigAuthorizationError
|
If an authorization error occurs. |
XMRigConnectionError
|
If a connection error occurs. |
XMRigAPIError
|
If a general API error occurs. |
Source code in xmrig/api.py
set_auth_header()
Update the Authorization header for the HTTP requests.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the Authorization header was changed, or False if an error occurred. |
Raises:
Type | Description |
---|---|
XMRigAuthorizationError
|
An error occurred setting the Authorization Header. |