Automated Spot Price Adjustment for Cost Optimization
Objective: This example demonstrates how to automate the adjustment of a server's spot price to stay competitive on the marketplace. By continuously monitoring other offers and adjusting the spot price within specified boundaries, users can maximize rental opportunities and revenue.
Step 1: Retrieve Spot Marketplace Data for a Specific Server
The first step is to get the current offers in the spot marketplace for a specific server ID, allowing us to assess the price competition.
import requests
# Parameters
server_id = 6 # Replace with the target server's ID
auth_token = 'YOUR_API_KEY'
url = f'https://api.clore.ai/v1/spot_marketplace?market={server_id}'
headers = {
'Authorization': f'Bearer {auth_token}'
}
# Retrieve spot marketplace data
response = requests.get(url, headers=headers)
if response.status_code == 200:
spot_data = response.json()
offers = spot_data.get('market', {}).get('offers', [])
else:
print(f"Error {response.status_code}: {response.text}")
offers = []Step 2: Analyze Competing Offers and Set Target Price
Here, we will analyze the current spot offers, then define a strategy to set our target price below the lowest existing bid, ensuring it remains competitive.
Step 3: Adjust the Server's Spot Price Based on Target
Using the set_spot_price endpoint, the code will attempt to adjust the spot price to the target value if it's different from the current spot price.
Step 4: Automate Price Monitoring and Adjustment Loop
To keep the server’s price competitive, this loop will repeat the price adjustment process periodically, adjusting only when a price change is detected.
Summary
This example shows how to:
Retrieve and analyze current marketplace offers for competitive pricing.
Set target prices based on competition to increase rental chances.
Implement an automated loop that monitors and updates the spot price as needed to remain competitive.
This process is ideal for server owners aiming to maximize server usage on the spot marketplace by dynamically adjusting their prices based on real-time market data.
Last updated