Dynamic Pricing Adjustments Based on Server Profitability
In this example, we’ll set up a script to dynamically adjust the spot pricing of listed servers on Clore’s marketplace based on their mining profitability. This use case is beneficial for server owners who want to maximize rental revenue by aligning their prices with current profitability trends.
Objective
Continuously monitor a server's mining profitability and adjust the spot price on Clore’s marketplace to reflect profitability. This approach ensures that prices remain competitive and profitable over time.
Prerequisites
Authorization token for Clore API.
Mining profitability data source, such as an external mining profitability API or local calculation tool.
Implementation
import requests
import time
# Authorization token
AUTH_TOKEN = 'your_auth_token_here'
# Set the initial price multiplier
PRICE_MULTIPLIER = 1.5 # Adjust this based on desired profitability margin
# Clore API endpoints
SERVERS_URL = 'https://api.clore.ai/v1/my_servers'
SET_PRICE_URL = 'https://api.clore.ai/v1/set_spot_price'
def get_profitability_data(server_specs):
"""
Placeholder function to simulate fetching profitability data from an external API.
In a real implementation, replace this with code to fetch data from a profitability API.
"""
gpu_model = server_specs['gpu']
# Example profitability in BTC for demonstration purposes
profitability_data = {
'GeForce GTX 1080 Ti': 0.00005,
'GeForce RTX 3070': 0.00008,
'Tesla V100': 0.0002
}
return profitability_data.get(gpu_model, 0.00005) # Default fallback profitability
def get_servers():
headers = {'auth': AUTH_TOKEN}
response = requests.get(SERVERS_URL, headers=headers)
if response.status_code == 200:
data = response.json()
if data.get("code") == 0:
return data['servers']
else:
print("Error fetching server data:", response.status_code, response.text)
return []
def update_server_price(server_id, offer_id, new_price):
headers = {
'auth': AUTH_TOKEN,
'Content-type': 'application/json'
}
price_data = {
'order_id': offer_id,
'desired_price': new_price
}
response = requests.post(SET_PRICE_URL, headers=headers, json=price_data)
if response.status_code == 200 and response.json().get("code") == 0:
print(f"Price updated for server {server_id}: {new_price} BTC")
else:
print("Error updating price:", response.status_code, response.text)
def main():
while True:
servers = get_servers()
for server in servers:
server_id = server['id']
offer_id = server['spot']['offer_id']
current_price = server['spot']['bitcoin']
# Fetch current mining profitability for this server
profitability = get_profitability_data(server['specs'])
# Calculate new price based on profitability and multiplier
new_price = profitability * PRICE_MULTIPLIER
# Update price if it differs significantly from current spot price
if abs(new_price - current_price) > 0.00001: # Adjust threshold as needed
print(f"Adjusting price for server {server_id} from {current_price} BTC to {new_price} BTC")
update_server_price(server_id, offer_id, new_price)
# Sleep before rechecking profitability and updating prices
time.sleep(1800) # Adjust based on desired update frequency (e.g., every 30 minutes)
if __name__ == "__main__":
main()
Explanation
get_profitability_data: Simulates fetching profitability data based on the server’s GPU model. Replace this with an actual call to a profitability API in a production environment.
get_servers: Fetches the user's listed servers on Clore’s marketplace.
update_server_price: Adjusts the server’s spot price based on the latest profitability data.
main loop: Periodically checks profitability and updates server pricing if the change exceeds a threshold.
Summary
This script enables server owners to adaptively adjust their rental prices in response to current market profitability, maximizing revenue while staying competitive.