dev.clore.ai
  • Getting Started
  • Introduction to Clore API
    • API Key Management
    • Transaction Processing with Clore Coin
    • RESTful Protocols in Clore
  • Marketplace Automation and Resource Optimization
    • Automated Spot Price Adjustment for Cost Optimization
    • Automated Server Retrieval and Analysis
    • Spot Price Optimization
    • Predictive Market Analytics
  • Server Management and Configuration
    • Bulk Server Onboarding and Dynamic Pricing Configuration
  • Dynamic Pricing and Profit Maximization
    • Dynamic Pricing Adjustments Based on Server Profitability
    • Automated Price Adjustment Based on Market Demand
    • Automated Spot Rental Based on Price Thresholds
  • Rental Strategies and Arbitrage
  • Monitoring and Notifications
    • Automated Monitoring and Notification of Rental Status
    • Automated Alert System for Low Server Utilization
    • Automated Retrieval and Analysis of Available Servers on the Marketplace
  • Security and Compliance
  • UI Automation and Visualization
  • API Performance Optimization
  • Community Extensions and Integrations
  • Advanced Data Processing and Analysis
  • Scalability and Infrastructure Management
  • Machine Learning and AI Integrations
    • Integrating ML Models into Server Operations
  • Developer Tools and SDKs
    • Setting Up the Clore Developer Toolkit
    • Using Clore SDK for Rapid Prototyping
  • Billing, Accounting, and Financial Reporting
  • Workflow Automation and Scripting
  • Multi-Cloud and Hybrid Cloud Integrations
  • Security Monitoring and Incident Management
  • Blockchain Interactions and Smart Contracts
  • Resource Optimization and Cost-Saving Techniques
Powered by GitBook
On this page
  1. Dynamic Pricing and Profit Maximization

Automated Price Adjustment Based on Market Demand

This example demonstrates a script that automatically adjusts the rental price of your servers on the Clore marketplace based on current demand. The goal is to set a higher price when demand is high and reduce it when demand drops, helping maximize revenue while keeping the server competitive on the market.

Objective

To dynamically adjust rental prices according to market demand, ensuring optimal pricing that attracts renters while maximizing revenue.

Prerequisites

  • Authorization token for Clore API.

  • At least one server listed on the Clore marketplace.

Implementation

import requests
import time

# Clore API credentials
AUTH_TOKEN = 'your_auth_token_here'
SERVERS_URL = 'https://api.clore.ai/v1/my_servers'
SET_PRICE_URL = 'https://api.clore.ai/v1/set_server_settings'

# Configuration for price adjustment
BASE_PRICE = 0.0001  # Base price in BTC or equivalent for reference
HIGH_DEMAND_MULTIPLIER = 1.5  # Multiplier to apply when demand is high
LOW_DEMAND_MULTIPLIER = 0.8  # Multiplier to apply when demand is low

# Demand threshold settings (example values)
HIGH_DEMAND_THRESHOLD = 80  # If above 80% servers are rented, consider it high demand
LOW_DEMAND_THRESHOLD = 20   # If below 20% servers are rented, consider it low demand

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 calculate_demand(servers):
    total_servers = len(servers)
    rented_servers = sum(1 for server in servers if server['rental_status'] > 0)
    demand_percentage = (rented_servers / total_servers) * 100 if total_servers > 0 else 0
    return demand_percentage

def adjust_price(server_id, new_price):
    headers = {
        'auth': AUTH_TOKEN,
        'Content-type': 'application/json'
    }
    data = {
        "name": f"server_{server_id}",
        "availability": True,
        "mrl": 72,  # maximum rental length in hours (can be customized)
        "on_demand": new_price,
        "spot": new_price * 0.8  # Example of spot price being 80% of on-demand price
    }
    response = requests.post(SET_PRICE_URL, headers=headers, json=data)
    if response.status_code == 200:
        print(f"Price adjusted for server {server_id}: New Price = {new_price}")
    else:
        print(f"Failed to adjust price for server {server_id}: ", response.text)

def adjust_prices_based_on_demand():
    servers = get_servers()
    demand_percentage = calculate_demand(servers)
    print(f"Current demand: {demand_percentage}%")

    for server in servers:
        if demand_percentage >= HIGH_DEMAND_THRESHOLD:
            new_price = BASE_PRICE * HIGH_DEMAND_MULTIPLIER
        elif demand_percentage <= LOW_DEMAND_THRESHOLD:
            new_price = BASE_PRICE * LOW_DEMAND_MULTIPLIER
        else:
            new_price = BASE_PRICE  # Keep the base price during normal demand

        adjust_price(server['id'], new_price)

def main():
    while True:
        adjust_prices_based_on_demand()
        time.sleep(1800)  # Adjust prices every 30 minutes

if __name__ == "__main__":
    main()

Explanation

  1. get_servers: Retrieves the list of servers and their rental statuses.

  2. calculate_demand: Calculates the demand percentage based on how many servers are currently rented.

  3. adjust_price: Sets a new price for a specific server based on the calculated demand.

  4. adjust_prices_based_on_demand: Checks the current demand and adjusts prices for each server accordingly.

  5. main loop: Runs the demand-based price adjustment every 30 minutes.

Summary

This code monitors market demand and dynamically adjusts server prices to ensure optimal pricing, maximizing revenue during high demand and staying competitive during low demand. This automation helps server owners optimize their rental strategy without manual intervention.

PreviousDynamic Pricing Adjustments Based on Server ProfitabilityNextAutomated Spot Rental Based on Price Thresholds

Last updated 6 months ago