### Fetch Energy Denominated Revenue (Go) Source: https://docs.luxor.tech/hashrateindex/api/get-asic-energy-denominated-revenue Example using Go to retrieve energy-denominated revenue data. This code shows how to set up an HTTP client, make the GET request with necessary headers, and parse the JSON response. ```go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "time" ) func main() { apiKey := "" span := "3M" url := fmt.Sprintf("https://api.hashrateindex.com/v1/hashrateindex/asic/energy-denominated-revenue?span=%s", span) client := &http.Client{ Timeout: time.Second * 10, } req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Add("X-Hi-Api-Key", apiKey) res, err := client.Do(req) if err != nil { fmt.Printf("Error making request: %s\n", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } var result map[string]interface{}/ err = json.Unmarshal(body, &result) if err != nil { fmt.Printf("Error unmarshalling JSON: %s\n", err) return } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Install and Verify Luxos Source: https://docs.luxor.tech/firmware/tools_and_integrations/luxos/intro Instructions to install, upgrade, and verify the installation of the luxos Python package using pip. ```bash pip install luxos pip install --upgrade luxos python -c "import luxos; print(luxos.__version__, luxos.__hash__)" ``` -------------------------------- ### Retrieve ASIC Release History (Go) Source: https://docs.luxor.tech/hashrateindex/api/get-asic-release-history Example using Go to retrieve historical ASIC release information. This code snippet shows how to set up an HTTP GET request with query parameters and headers, and how to handle the JSON response. ```Go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "net/url" ) func main() { token := "" manufacturerSlug := "bitmain" modelSlug := "bitmain-antminer-s19j-90th" releaseDate := "2021-01-01" params := url.Values{} params.Add("manufacturerSlug", manufacturerSlug) params.Add("modelSlug", modelSlug) params.Add("releaseDate", releaseDate) url := "https://api.hashrateindex.com/v1/hashrateindex/asic/release-history?" + params.Encode() client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("X-Hi-Api-Key", token) res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } var result map[string]interface{}/ err = json.Unmarshal(body, &result) if err != nil { fmt.Println("Error unmarshalling JSON:", err) return } fmt.Println(result) } ``` -------------------------------- ### Get Global Hashrate Heatmaps (Go) Source: https://docs.luxor.tech/hashrateindex/api/network/get-network-global-hashrate-heatmaps A Go language example for fetching global Bitcoin mining distribution and hashrate concentration data. This code demonstrates setting up the HTTP request, including the API key in the headers, and handling the JSON response. ```Go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "net/url" "strings" ) func main() { apiKey := "" quarters := []string{"Q1", "Q2"} year := "2025" query := url.Values{} query.Add("quarter", strings.Join(quarters, ",")) query.Add("year", year) url := fmt.Sprintf("https://api.hashrateindex.com/v1/hashrateindex/network/global-hashrate-heatmaps?%s", query.Encode()) client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("X-Hi-Api-Key", apiKey) res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) // Optionally, unmarshal JSON response // var result map[string]interface{} // if err := json.Unmarshal(body, &result); err != nil { // fmt.Println("Error unmarshalling JSON:", err) // } // fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Fetch ASIC Price History (Go) Source: https://docs.luxor.tech/hashrateindex/api/asic/get-asic-price-history Example using Go to make a GET request to the ASIC price history endpoint. This code snippet demonstrates how to retrieve historical price data for a given ASIC model and time bucket, utilizing an API key for authentication. ```go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "strings" ) func getAsicPriceHistory(modelSlug string, bucket string, token string) (map[string]interface{}, error) { url := fmt.Sprintf("https://api.hashrateindex.com/v1/hashrateindex/asic/price-history?modelSlug=%s&bucket=%s", modelSlug, bucket) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } req.Header.Set("X-Hi-Api-Key", token) client := &http.Client{} res, err := client.Do(req) if err != nil { return nil, fmt.Errorf("failed to execute request: %w", err) } defer res.Body.Close() if res.StatusCode != http.StatusOK { return nil, fmt.Errorf("API request failed with status: %s", res.Status) } body, err := ioutil.ReadAll(res.Body) if err != nil { return nil, fmt.Errorf("failed to read response body: %w", err) } var data map[string]interface{} if err := json.Unmarshal(body, &data); err != nil { return nil, fmt.Errorf("failed to unmarshal JSON: %w", err) } return data, nil } // Example usage: // func main() { // token := "" // data, err := getAsicPriceHistory("bitmain-antminer-s19j-90th", "1M", token) // if err != nil { // fmt.Println("Error:", err) // return // } // fmt.Printf("%+v\n", data) // } ``` -------------------------------- ### Get ASIC Hashrate Costs - Go Source: https://docs.luxor.tech/hashrateindex/api/asic/get-asic-hashrate-costs Example of how to retrieve ASIC hashrate costs using Go. This code demonstrates making an HTTP GET request and handling the JSON response. ```Go package main import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" ) func main() { apiKey := "" url := "https://api.hashrateindex.com/v1/hashrateindex/asic/hashrate-costs" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { log.Fatalf("Error creating request: %v", err) } req.Header.Add("X-Hi-Api-Key", apiKey) resp, err := client.Do(req) if err != nil { log.Fatalf("Error making request: %v", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("Error reading response body: %v", err) } fmt.Println("Response Status:", resp.Status) var result map[string]interface{} if err := json.Unmarshal(body, &result); err != nil { log.Fatalf("Error unmarshalling JSON: %v", err) } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Set ATM Configuration - All Parameters Source: https://docs.luxor.tech/firmware/api/luxminer/atmset This example demonstrates setting all available ATM parameters simultaneously. It includes enabling ATM, setting startup and post-ramp minutes, defining temperature windows, and specifying efficiency and performance profiles as min and max profiles, respectively. ```bash $ echo '{"command": "atmset", "parameter":"tjqw4aNI,enabled=true,startup_minutes=99,post_ramp_minutes=1440,temp_window=7,chip_temp_window=9,min_profile=efficiency,max_profile=performance"}' | nc $MINER_IP 4028 | jq ``` -------------------------------- ### Get Hashrate History (JavaScript) Source: https://docs.luxor.tech/mining/api/reporting/get-hashrate-history Fetches hashrate history data using JavaScript. This example demonstrates making a GET request to the API endpoint with necessary query parameters and headers for authentication. ```JavaScript async function getHashrateHistory(token, currencyType, subaccountNames, siteId, startDate, endDate, tickSize, pageNumber = 1, pageSize = 10) { const url = `https://app.luxor.tech/api/v2/pool/hashrate-efficiency/${currencyType}`; const params = new URLSearchParams({ subaccount_names: subaccountNames.join(','), site_id: siteId, start_date: startDate, end_date: endDate, tick_size: tickSize, page_number: pageNumber, page_size: pageSize }); try { const response = await fetch(`${url}?${params}`, { method: 'GET', headers: { 'authorization': token } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } catch (error) { console.error('Error fetching hashrate history:', error); return null; } } ``` -------------------------------- ### Installation Source: https://docs.luxor.tech/firmware/tools_and_integrations/luxos/intro Instructions for installing and upgrading the Luxos Python package. ```APIDOC ## Installation Detailed instruction on how to install it are provided 👉 here, to install the latest released code: ```bash # to install it $> pip install luxos # to upgrade it $> pip install --upgrade luxos # to verify the current version $> python -c "import luxos; print(luxos.__version__, luxos.__hash__)" ``` **Output Example:** ``` 0.0.7 27e53c7b37ac1bbb88112f3c931b9cd8f1a74a3a ``` ``` -------------------------------- ### Get Top Performing Stocks (Python) Source: https://docs.luxor.tech/hashrateindex/api/get-stocks-top-performers Python script to retrieve top stock performer data. This example utilizes the `requests` library to send a GET request with the necessary API key. ```python import requests def get_top_performing_stocks(api_key): url = "https://api.hashrateindex.com/v1/hashrateindex/stocks/top-performers" headers = { "X-Hi-Api-Key": api_key } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching top performing stocks: {e}") return None # Example usage: # api_token = "" # stocks_data = get_top_performing_stocks(api_token) # if stocks_data: # print(stocks_data) ``` -------------------------------- ### Fetch Electricity Generation Data (Python) Source: https://docs.luxor.tech/hashrateindex/api/get-energy-electricity-generation-by-region Example using Python to get electricity generation data by region. This code illustrates how to send a GET request with the required API key and query parameters. ```Python import requests url = "https://api.hashrateindex.com/v1/hashrateindex/energy/electricity-generation-by-region" headers = { "X-Hi-Api-Key": "" } params = { "span": "1Y", "region": "CAL" } response = requests.get(url, headers=headers, params=params) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### `luxos` Command Line Tool Source: https://docs.luxor.tech/firmware/tools_and_integrations/luxos/intro Usage examples for the `luxos` command-line tool to issue single commands to miners. ```APIDOC ## `luxos` Command Line Tool The luxos python package comes with a command line script called `luxos`: it can issue a command (with parameters) to a list of miners' ips in a csv file. ### Example: Get Version This will launch the version command on a miner, returning the json output: ```bash luxos --range 127.0.0.1 --quiet --json --cmd version ``` ### `--range` Flag Options The `--range` flag can take: * a single ip address, eg: `--range 127.0.0.1` * a range like: `--range 127.0.0.1-127.0.0.5` * or addresses from a file: `--range @miners.csv`. ### Other Examples ```bash # set/unset ATM luxos --range 127.0.0.1 --quiet --json --cmd atmset --params "enabled=true" # add a new profile luxos --range 127.0.0.1 --quiet --json --cmd profilenew --params "myprofile,700,14.8" ``` ### Notes > 1. `--ipfile` is an alternative way to load miners from a csv file, it's the same as `--range` flag: it can take addresses like `127.0.0.1`, ranges as `127.0.0.1-127.0.0.5` or filenames as `@miners.csv`. > 2. you can use the `--json` to save the results in json format (to stdout). > ``` -------------------------------- ### Get ASIC Manufacturers (Python) Source: https://docs.luxor.tech/hashrateindex/api/asic/get-asic-manufacturers This snippet provides a Python example for fetching ASIC mining hardware manufacturer details. It uses the 'requests' library to make a GET request with an API key in the header. ```Python import requests url = "https://api.hashrateindex.com/v1/hashrateindex/asic/manufacturers" api_key = "" headers = { "X-Hi-Api-Key": api_key } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") print(response.text) ``` -------------------------------- ### `luxos-run` Command Line Tool Source: https://docs.luxor.tech/firmware/tools_and_integrations/luxos/intro Usage examples for the `luxos-run` command-line tool to execute Python scriptlets on miners in parallel. ```APIDOC ## `luxos-run` Command Line Tool The `luxos-run` is an alternative to `luxos` command line script, allowing to run as **scriptlet** (a small python script) targeting miners: a scriptlet usually can contain some logic and or longer commands sequences. ### Example Scriptlet (`hello-world.py`) ```python from luxos import asyncops async def main(host: str, port: int): # async sending to the miner the version command res = await asyncops.rexec(host, port, "version") # validate will check the message is correct and return the result version = asyncops.validate(res, "VERSION", 1, 1) return {"address": f"{host}:{port}", "miner": version["LUXminer"]} ``` ### Running `luxos-run` Running the `luxos-run` will execute the scriptlet aggregating the results in a dictionary with key set to the miner address: ```bash luxos-run --range @miners.csv --quiet --json hello-world.py ``` ### Response Example ```json { "127.0.0.1:4028": { "address": "127.0.0.1:4028", "version": "2021.1.12.202305-nnnn" } } ``` ``` -------------------------------- ### Get ASIC Hashrate Costs - Python Source: https://docs.luxor.tech/hashrateindex/api/asic/get-asic-hashrate-costs Example of how to retrieve ASIC hashrate costs using Python. This code snippet shows how to send a GET request with an API key and parse the JSON response. ```Python import requests def get_asic_hashrate_costs(api_key): url = "https://api.hashrateindex.com/v1/hashrateindex/asic/hashrate-costs" headers = { "X-Hi-Api-Key": api_key } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching ASIC hashrate costs: {e}") return None # Example usage: # api_token = "" # data = get_asic_hashrate_costs(api_token) # if data: # print(data) ``` -------------------------------- ### Fetch ASIC Price Index (Go) Source: https://docs.luxor.tech/hashrateindex/api/get-asic-price-index Example of how to fetch the ASIC Price Index using Go. This code snippet shows how to construct the request, include headers, and handle the JSON response. ```go package main import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" "strings" ) func main() { apiKey := "" url := "https://api.hashrateindex.com/v1/hashrateindex/asic/price-index?span=3M¤cy=USD" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { log.Fatalf("Error creating request: %s", err) } req.Header.Add("X-Hi-Api-Key", apiKey) resp, err := client.Do(req) if err != nil { log.Fatalf("Error making request: %s", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("Error reading response body: %s", err) } if resp.StatusCode != http.StatusOK { log.Fatalf("API request failed with status code: %d, body: %s", resp.StatusCode, string(body)) } var result map[string]interface{} if err := json.Unmarshal(body, &result); err != nil { log.Fatalf("Error unmarshalling JSON: %s", err) } fmt.Println(result) } ``` -------------------------------- ### Get ASIC Hashrate Costs - JavaScript Source: https://docs.luxor.tech/hashrateindex/api/asic/get-asic-hashrate-costs Example of how to retrieve ASIC hashrate costs using JavaScript. This code snippet demonstrates making a GET request to the API endpoint with the necessary authorization header. ```JavaScript async function getAsciiHashrateCosts(token) { const url = "https://api.hashrateindex.com/v1/hashrateindex/asic/hashrate-costs"; const headers = { "X-Hi-Api-Key": token }; try { const response = await fetch(url, { method: "GET", headers: headers }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error("Error fetching ASIC hashrate costs:", error); return null; } } ``` -------------------------------- ### Get Global Hashrate Heatmap Years - Python Source: https://docs.luxor.tech/hashrateindex/api/network/get-network-global-hashrate-heatmap-years Example of how to retrieve global hashrate heatmap data for multiple years using Python. This request requires an API key for authorization and demonstrates making a GET request to the specified endpoint. ```Python import requests def get_global_hashrate_heatmap_years(api_key): url = "https://api.hashrateindex.com/v1/hashrateindex/network/global-hashrate-heatmap-years" headers = { "X-Hi-Api-Key": api_key } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching global hashrate heatmap years: {e}") return None # Example usage: # api_key = "" # data = get_global_hashrate_heatmap_years(api_key) # if data: # print(data) ``` -------------------------------- ### Fetch Electricity Overview Data (Go) Source: https://docs.luxor.tech/hashrateindex/api/get-energy-electricity-overview This Go program demonstrates how to retrieve electricity overview data from the API. It utilizes the 'net/http' package to make a GET request, including the 'X-Hi-Api-Key' header for authentication and the 'span' query parameter for specifying the time range. ```go package main import ( "fmt" "io/ioutil" "net/http" "time" ) func getElectricityOverview(token, span string) (string, error) { url := fmt.Sprintf("https://api.hashrateindex.com/v1/hashrateindex/energy/electricity-overview?span=%s", span) client := &http.Client{Timeout: 10 * time.Second} req, err := http.NewRequest("GET", url, nil) if err != nil { return "", fmt.Errorf("failed to create request: %w", err) } req.Header.Set("X-Hi-Api-Key", token) resp, err := client.Do(req) if err != nil { return "", fmt.Errorf("failed to execute request: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return "", fmt.Errorf("unexpected status code: %d", resp.StatusCode) } body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("failed to read response body: %w", err) } return string(body), nil } ``` -------------------------------- ### Get Global Hashrate Heatmap Years - Go Source: https://docs.luxor.tech/hashrateindex/api/network/get-network-global-hashrate-heatmap-years Example of how to retrieve global hashrate heatmap data for multiple years using Go. This request requires an API key for authorization and demonstrates making a GET request to the specified endpoint. ```Go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "strings" ) func getGlobalHashrateHeatmapYears(apiKey string) (map[string]interface{}, error) { url := "https://api.hashrateindex.com/v1/hashrateindex/network/global-hashrate-heatmap-years" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } req.Header.Add("X-Hi-Api-Key", apiKey) resp, err := client.Do(req) if err != nil { return nil, fmt.Errorf("failed to execute request: %w", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read response body: %w", err) } if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("API request failed with status code: %d, body: %s", resp.StatusCode, string(body)) } var result map[string]interface{} if err := json.Unmarshal(body, &result); err != nil { return nil, fmt.Errorf("failed to unmarshal response: %w", err) } return result, nil } // Example usage: // func main() { // apiKey := "" // data, err := getGlobalHashrateHeatmapYears(apiKey) // if err != nil { // fmt.Println("Error:", err) // return // } // fmt.Printf("%+v\n", data) // } ``` -------------------------------- ### Python API: `launch` Function Source: https://docs.luxor.tech/firmware/tools_and_integrations/luxos/intro Details on how to use the `launch` function from the Luxos Python API for executing tasks across multiple miners. ```APIDOC #### launch The `luxos.utils.lauch` allows to rexec commands to a list of miners stored in a csv file. This all-in-one function, allows batched operations on a set of miners, taking care of all details. ```python import asyncio from luxos import utils # load miners addresses from miners.csv addresses = utils.load_ips_from_csv("miners.csv") # define a task with (host, port) signature, acting on a miner async def task(host: str, port: int): return await utils.rexec(host, port, "version") # execute task across all miners, batch will limit execution rate to 4 asyncio.run(utils.launch(addresses, task, batch=4)) ``` ``` -------------------------------- ### Get Global Hashrate Heatmap Years - JavaScript Source: https://docs.luxor.tech/hashrateindex/api/network/get-network-global-hashrate-heatmap-years Example of how to retrieve global hashrate heatmap data for multiple years using JavaScript. This request requires an API key for authorization and demonstrates making a GET request to the specified endpoint. ```JavaScript async function getGlobalHashrateHeatmapYears(apiKey) { const url = "https://api.hashrateindex.com/v1/hashrateindex/network/global-hashrate-heatmap-years"; const headers = { "X-Hi-Api-Key": apiKey }; try { const response = await fetch(url, { method: "GET", headers: headers }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error("Error fetching global hashrate heatmap years:", error); return null; } } // Example usage: // const apiKey = ""; // getGlobalHashrateHeatmapYears(apiKey).then(data => { // if (data) { // console.log(data); // } // }); ``` -------------------------------- ### Set Fan Speed using Legacy Format Source: https://docs.luxor.tech/firmware/api/luxminer/fanset Demonstrates the legacy command format using sequential positional parameters for speed and minimum fan count. ```bash echo '{"command": "fanset", "parameter":"yJN2nlj1,-1,1"}' | nc $MINER_IP 4028 | jq ``` -------------------------------- ### Get Sites List - Go Source: https://docs.luxor.tech/mining/api/workspaces/get-sites This Go program demonstrates how to retrieve a list of all sites using an HTTP GET request. It sets the required 'authorization' header and handles the JSON response. Error handling for the request and response is included. ```go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "strings" ) func main() { url := "https://app.luxor.tech/api/v2/workspace/sites" token := "" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Add("authorization", token) res, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get Subaccounts List - JavaScript Source: https://docs.luxor.tech/mining/api/subaccounts/get-subaccounts This JavaScript example shows how to make a GET request to the subaccounts endpoint using the fetch API. It includes setting the authorization header and passing query parameters for site ID, page number, and page size. ```JavaScript async function getSubaccounts(siteId, pageNumber = 1, pageSize = 10, token) { const response = await fetch(`https://app.luxor.tech/api/v2/pool/subaccounts?site_id=${siteId}&page_number=${pageNumber}&page_size=${pageSize}`, { method: 'GET', headers: { 'authorization': token } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } // Example usage: // const token = ''; // getSubaccounts('b0a5fad8-0e09-4f10-ac20-ccd80fb2d138', 1, 10, token) // .then(data => console.log(data)) // .catch(error => console.error('Error fetching subaccounts:', error)); ``` -------------------------------- ### Get Global Hashrate Heatmaps (JavaScript) Source: https://docs.luxor.tech/hashrateindex/api/network/get-network-global-hashrate-heatmaps Provides a JavaScript example for retrieving global Bitcoin mining distribution and hashrate concentration data. This snippet shows how to make a GET request to the API, including necessary headers for authentication and query parameters for filtering. ```JavaScript async function getGlobalHashrateHeatmaps(token, quarters, year) { const url = `https://api.hashrateindex.com/v1/hashrateindex/network/global-hashrate-heatmaps?quarter=${encodeURIComponent(quarters.join(','))}&year=${year}`; const headers = { 'X-Hi-Api-Key': token }; try { const response = await fetch(url, { method: 'GET', headers: headers }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error('Error fetching global hashrate heatmaps:', error); return null; } } // Example usage: // const apiKey = ''; // const selectedQuarters = ['Q1', 'Q2']; // const selectedYear = 2025; // getGlobalHashrateHeatmaps(apiKey, selectedQuarters, selectedYear).then(data => { // if (data) { // console.log(data); // } // }); ``` -------------------------------- ### Fetch Daily Stock Returns (Go) Source: https://docs.luxor.tech/hashrateindex/api/get-stocks-change This Go program illustrates how to retrieve daily stock returns from the /stocks/change API. It demonstrates making an HTTP GET request with the necessary authorization header and parsing the JSON response. ```Go package main import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" ) func main() { apiKey := "" url := "https://api.hashrateindex.com/v1/hashrateindex/stocks/change" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { log.Fatalf("Failed to create request: %v", err) } req.Header.Add("X-Hi-Api-Key", apiKey) resp, err := client.Do(req) if err != nil { log.Fatalf("Failed to execute request: %v", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { log.Fatalf("API request failed with status code: %d", resp.StatusCode) } body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("Failed to read response body: %v", err) } var result map[string]interface{}/ err = json.Unmarshal(body, &result) if err != nil { log.Fatalf("Failed to unmarshal JSON response: %v", err) } fmt.Println(result) } ``` -------------------------------- ### Get ASIC Hashrate Costs - cURL Source: https://docs.luxor.tech/hashrateindex/api/asic/get-asic-hashrate-costs Example of how to retrieve ASIC hashrate costs using a cURL command. Requires an API key for authorization. ```cURL curl -X GET "https://api.hashrateindex.com/v1/hashrateindex/asic/hashrate-costs" \ -H "X-Hi-Api-Key: " ``` -------------------------------- ### Configure PSU bypass settings Source: https://docs.luxor.tech/firmware/api/luxminer/psuset Example of enabling PSU bypass mode and setting the bypass voltage to 13.5. ```bash echo '{"command": "psuset", "parameter":"jKk8ljbU,bypass_enabled=true,bypass_voltage=13.5"}' | nc $MINER_IP 4028 | jq ``` -------------------------------- ### POST /api/v1/energy/sites/{site_id}/report-energy Source: https://docs.luxor.tech/energy/api/sites/report_site_energy Report energy data for an existing site in batches. Reference the getting started documentation for more information on how you should report load. ```APIDOC ## POST /api/v1/energy/sites/{site_id}/report-energy ### Description Report energy for an existing site in batches. Reference the getting started documentation here for more information on how you should report load. ### Method POST ### Endpoint /api/v1/energy/sites/{site_id}/report-energy ### Parameters #### Path Parameters - **site_id** (uuid) - Required - The UUID of the site to report energy for #### Headers - **Authorization** (string) - Required - Bearer - **Content-Type** (string) - Required - application/json #### Request Body - **reports** (array) - Required - Reports - **load_kw** (string) - Required - The load in kilowatts. - **load_type** (string) - Required - The type of load (e.g., "actual", "estimate"). - **timestamp** (string) - Required - The timestamp of the energy reading in ISO 8601 format. ### Request Example ```json { "reports": [ { "load_kw": "50.5", "load_type": "actual", "timestamp": "2025-04-09T12:00:00Z" }, { "load_kw": "60.2", "load_type": "estimate", "timestamp": "2025-04-09T13:00:00Z" } ] } ``` ### Response #### Success Response (200) - **results** (array) - Description of the results. - **summary** (object) - Summary of the report. - **url** (string) - URL related to the report. #### Response Example ```json { "results": [ {} ], "summary": {}, "url": "string" } ``` ``` -------------------------------- ### Get Subaccounts List - Go Source: https://docs.luxor.tech/mining/api/subaccounts/get-subaccounts This Go program demonstrates how to fetch subaccounts using the net/http package. It constructs the URL with query parameters and sets the necessary authorization header. Error handling for the HTTP request and response is included. ```Go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "net/url" ) func main() { baseURL := "https://app.luxor.tech/api/v2/pool/subaccounts" siteID := "b0a5fad8-0e09-4f10-ac20-ccd80fb2d138" pageNumber := "1" pageSize := "10" token := "" params := url.Values{} params.Add("site_id", siteID) params.Add("page_number", pageNumber) params.Add("page_size", pageSize) requestURL := fmt.Sprintf("%s?%s", baseURL, params.Encode()) client := &http.Client{} req, err := http.NewRequest("GET", requestURL, nil) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Add("authorization", token) res, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } if res.StatusCode != http.StatusOK { fmt.Printf("Error: Received status code %d. Response body: %s\n", res.StatusCode, string(body)) return } // Process the JSON response var result map[string]interface{} if err := json.Unmarshal(body, &result); err != nil { fmt.Printf("Error unmarshalling JSON: %s\n", err) return } fmt.Printf("Subaccounts: %+v\n", result["subaccounts"]) } ``` -------------------------------- ### Get Stock Volatility Data (cURL) Source: https://docs.luxor.tech/hashrateindex/api/get-stocks-volatility Example using cURL to fetch the 30-day annualized volatility of stock prices. Requires an API key in the header. ```cURL curl -X GET "https://api.hashrateindex.com/v1/hashrateindex/stocks/volatility" \ -H "X-Hi-Api-Key: " ``` -------------------------------- ### Fetch Electricity Overview Data (Python) Source: https://docs.luxor.tech/hashrateindex/api/get-energy-electricity-overview This Python script illustrates how to fetch electricity overview data using the 'requests' library. It shows how to set the 'X-Hi-Api-Key' header for authentication and how to specify the desired time span using the 'span' query parameter. ```python import requests def get_electricity_overview(token, span='1Y'): url = f"https://api.hashrateindex.com/v1/hashrateindex/energy/electricity-overview?span={span}" headers = { 'X-Hi-Api-Key': token } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching electricity overview: {e}") return None ``` -------------------------------- ### Get Network Transaction Count (cURL) Source: https://docs.luxor.tech/hashrateindex/api/get-network-transaction-count Example cURL command to fetch the network transaction count for a specific time span. Requires an API key for authorization. ```cURL curl -X GET "https://api.hashrateindex.com/v1/hashrateindex/network/transaction-count?span=1D" \ -H "X-Hi-Api-Key: " ``` -------------------------------- ### Get ASIC Price Per Model (cURL) Source: https://docs.luxor.tech/hashrateindex/api/get-asic-price-per-model Example cURL command to fetch ASIC prices per model, including the manufacturer slug and API key. ```bash curl -X GET "https://api.hashrateindex.com/v1/hashrateindex/asic/price-per-model?manufacturerSlug=bitmain" \ -H "X-Hi-Api-Key: " ``` -------------------------------- ### Get Hashprice Data (Go) Source: https://docs.luxor.tech/hashrateindex/api/hashprice/get-hashprice This Go program demonstrates how to make a GET request to the Hashprice API. It constructs the URL with query parameters and includes the authorization header. The response is then parsed into a struct representing the hashprice data. ```go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "net/url" ) type HashPriceData struct { Data []struct { Price float64 `json:"price"` Timestamp string `json:"timestamp"` } `json:"data"` } func main() { apiKey := "" baseURL := "https://api.hashrateindex.com/v1/hashrateindex/hashprice" params := url.Values{} params.Add("span", "1D") params.Add("bucket", "1H") params.Add("currency", "USD") params.Add("hashunit", "PHS") fullURL := baseURL + "?" + params.Encode() client := &http.Client{} req, err := http.NewRequest("GET", fullURL, nil) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Add("X-Hi-Api-Key", apiKey) res, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } if res.StatusCode != http.StatusOK { fmt.Printf("API returned status code %d: %s\n", res.StatusCode, string(body)) return } var hashPriceData HashPriceData err = json.Unmarshal(body, &hashPriceData) if err != nil { fmt.Printf("Error unmarshalling JSON: %s\n", err) return } fmt.Printf("%+v\n", hashPriceData) } ``` -------------------------------- ### Retrieve Top Performing Stocks (Go) Source: https://docs.luxor.tech/hashrateindex/api/get-stocks-top-performers This Go program illustrates how to query the API for top-performing stocks. It includes setting up the request with the required API key header. ```go package main import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" "strings" ) func main() { apiKey := "" url := "https://api.hashrateindex.com/v1/hashrateindex/stocks/top-performers" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { log.Fatalf("Error creating request: %v", err) } req.Header.Add("X-Hi-Api-Key", apiKey) resp, err := client.Do(req) if err != nil { log.Fatalf("Error sending request: %v", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("Error reading response body: %v", err) } if resp.StatusCode != http.StatusOK { log.Fatalf("API request failed with status code: %d, body: %s", resp.StatusCode, string(body)) } // Assuming the response is JSON, you might want to unmarshal it var result map[string]interface{} if err := json.Unmarshal(body, &result); err != nil { log.Fatalf("Error unmarshalling JSON: %v", err) } fmt.Printf("Response: %s\n", string(body)) } ``` -------------------------------- ### Get Stocks Top Constituents (cURL) Source: https://docs.luxor.tech/hashrateindex/api/get-stocks-top-constituents Example of how to fetch the top constituents of a stock index using cURL. Requires an API key in the headers. This endpoint is subject to rate limitations. ```cURL curl -X GET "https://api.hashrateindex.com/v1/hashrateindex/stocks/top-constituents" \ -H "X-Hi-Api-Key: " ``` -------------------------------- ### Fetch Workspace Actions (cURL, JavaScript, Go, Python) Source: https://docs.luxor.tech/mining/api/workspaces/get-actions Demonstrates how to retrieve a list of actions from the workspace using the Luxor Tech API. Supports filtering by date range and status, and includes pagination options. Requires an authorization token. ```curl curl -X GET "https://app.luxor.tech/api/v2/workspace/actions?start_date=2025-01-01&end_date=2025-01-31&status=PENDING&page_number=1&page_size=10" \ -H "authorization: " ``` ```javascript async function getActions() { const token = ''; const startDate = '2025-01-01'; const endDate = '2025-01-31'; const status = 'PENDING'; const pageNumber = 1; const pageSize = 10; const url = `https://app.luxor.tech/api/v2/workspace/actions?start_date=${startDate}&end_date=${endDate}&status=${status}&page_number=${pageNumber}&page_size=${pageSize}`; try { const response = await fetch(url, { method: 'GET', headers: { 'authorization': token } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching actions:', error); } } getActions(); ``` ```go package main import ( "fmt" "io/ioutil" "net/http" "time" ) func main() { token := "" startDate := "2025-01-01" endDate := "2025-01-31" status := "PENDING" pageNumber := 1 pageSize := 10 url := fmt.Sprintf("https://app.luxor.tech/api/v2/workspace/actions?start_date=%s&end_date=%s&status=%s&page_number=%d&page_size=%d", startDate, endDate, status, pageNumber, pageSize) client := &http.Client{ Timeout: 30 * time.Second, } req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Set("authorization", token) resp, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { fmt.Printf("HTTP error! status: %s\n", resp.Status) return } body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Println(string(body)) } ``` ```python import requests def get_actions(): token = '' start_date = '2025-01-01' end_date = '2025-01-31' status = 'PENDING' page_number = 1 page_size = 10 url = f"https://app.luxor.tech/api/v2/workspace/actions?start_date={start_date}&end_date={end_date}&status={status}&page_number={page_number}&page_size={page_size}" headers = { 'authorization': token } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes data = response.json() print(data) except requests.exceptions.RequestException as e: print(f"Error fetching actions: {e}") get_actions() ``` -------------------------------- ### Retrieve Hashprice using JavaScript Source: https://docs.luxor.tech/hashrateindex/api/get-hashprice Example of how to retrieve hashprice data using JavaScript. This code snippet shows how to make a GET request to the /hashprice endpoint with specified parameters and authorization. ```javascript async function getHashprice(token) { const url = `https://api.hashrateindex.com/v1/hashrateindex/hashprice?span=1D&bucket=1H¤cy=USD&hashunit=PHS`; const headers = { 'X-Hi-Api-Key': token }; try { const response = await fetch(url, { method: 'GET', headers: headers }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); return data; } catch (error) { console.error('Error fetching hashprice:', error); } } // Example usage: // const apiKey = ''; // getHashprice(apiKey); ``` -------------------------------- ### Execute Commands via Luxos CLI Source: https://docs.luxor.tech/firmware/tools_and_integrations/luxos/intro Examples of using the luxos command-line tool to send commands to miners specified by IP range or CSV file. ```bash luxos --range 127.0.0.1 --quiet --json --cmd version luxos --range 127.0.0.1 --quiet --json --cmd atmset --params "enabled=true" luxos --range 127.0.0.1 --quiet --json --cmd profilenew --params "myprofile,700,14.8" ```