Bulk Server Onboarding and Dynamic Pricing Configuration
Objective: This example demonstrates how to automate the onboarding of multiple servers to the Clore Marketplace and set dynamic pricing for each server based on profitability. This method is beneficial for server farm operators who want to efficiently add multiple servers and ensure optimal pricing for each.
Step 1: Generate Onboarding Data for Each Server
To add multiple servers to Clore Marketplace, we first need to generate onboarding data, including setting the server's unique identifier and initial configuration.
import requests
# Define API and Authentication
auth_token = 'YOUR_API_KEY'
url = 'https://api.clore.ai/v1/mass_onboard'
headers = {
'Authorization': f'Bearer {auth_token}',
'Content-Type': 'application/json'
}
# Define server configuration for mass onboarding
servers_data = [
{
"name": "Server-1",
"os": "HiveOS",
"pricing_model": "profitability_based",
"base_price_usd": 10,
"multiplier": 2
},
{
"name": "Server-2",
"os": "Ubuntu",
"pricing_model": "static",
"static_price_btc": 0.0005
}
# Add more server configurations here as needed
]
# Send onboarding request for each server
for server in servers_data:
response = requests.post(url, headers=headers, json=server)
if response.status_code == 200:
print(f"{server['name']} successfully onboarded.")
else:
print(f"Error onboarding {server['name']}: {response.text}")
Step 2: Set Dynamic Pricing Based on Mining Profitability
With servers onboarded, the next step is to configure dynamic pricing based on profitability. This example monitors mining earnings and adjusts the marketplace price accordingly.
import random # For simulation of profitability; in practice, replace with profitability data source
# Function to simulate fetching server profitability (replace with real data source)
def get_mining_profitability(server_id):
return random.uniform(2, 10) # Simulate daily profitability in USD
# Adjust price based on profitability
pricing_url = 'https://api.clore.ai/v1/set_server_settings'
for server in servers_data:
# Get current profitability (replace this function in production)
profitability = get_mining_profitability(server['name'])
adjusted_price_usd = profitability * server.get('multiplier', 1)
# Convert adjusted USD price to BTC (using placeholder conversion rate for demonstration)
usd_to_btc_rate = 0.000023 # Replace with real-time rate
adjusted_price_btc = adjusted_price_usd * usd_to_btc_rate
# Configure price settings
pricing_data = {
"name": server['name'],
"availability": True,
"mrl": 150, # Maximum rental duration in hours
"on_demand": adjusted_price_btc,
"spot": adjusted_price_btc * 0.8 # Spot price at 80% of on-demand price
}
# Update server pricing
response = requests.post(pricing_url, headers=headers, json=pricing_data)
if response.status_code == 200:
print(f"{server['name']} price set to {adjusted_price_btc:.6f} BTC on-demand.")
else:
print(f"Failed to update pricing for {server['name']}: {response.text}")
Step 3: Automate Regular Profitability Checks and Price Adjustments
To keep prices updated, schedule regular profitability checks and price adjustments to align with the latest profitability data.
import time
# Set interval for price updates (e.g., every 6 hours)
update_interval = 6 * 60 * 60
while True:
for server in servers_data:
profitability = get_mining_profitability(server['name'])
adjusted_price_usd = profitability * server.get('multiplier', 1)
adjusted_price_btc = adjusted_price_usd * usd_to_btc_rate
pricing_data = {
"name": server['name'],
"availability": True,
"mrl": 150,
"on_demand": adjusted_price_btc,
"spot": adjusted_price_btc * 0.8
}
response = requests.post(pricing_url, headers=headers, json=pricing_data)
if response.status_code == 200:
print(f"{server['name']} price updated to {adjusted_price_btc:.6f} BTC.")
else:
print(f"Failed to update pricing for {server['name']}: {response.text}")
# Wait before the next update
time.sleep(update_interval)
Summary
In this example, we have:
Automated server onboarding with custom configurations.
Implemented a dynamic pricing model that adjusts based on profitability.
Set up a regular loop to update server prices, ensuring alignment with changing profitability.
This code is suitable for operators managing multiple servers who want to keep their servers competitively priced and optimize revenue based on mining profitability.