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 Spot Rental Based on Price Thresholds

In this example, we'll set up an automated script to monitor the spot marketplace and automatically rent servers when prices meet predefined thresholds. This script will help users capture GPU rental opportunities at optimal rates, ensuring cost efficiency without manual intervention.

Objective

Automatically rent available servers from the spot marketplace when their prices are below specified thresholds. This use case is beneficial for users who want to take advantage of variable pricing but do not want to monitor the marketplace manually.

Prerequisites

  • Authorization token for Clore API access.

  • Predefined price thresholds for each server type.

Implementation

import requests
import time

# Authorization token
AUTH_TOKEN = 'your_auth_token_here'

# Set price thresholds per GPU model
price_thresholds = {
    'GeForce GTX 1080 Ti': 0.00005,  # BTC per day
    'GeForce RTX 3070': 0.00008,
    'Tesla V100': 0.0002
}

# Clore API endpoints
MARKETPLACE_URL = 'https://api.clore.ai/v1/spot_marketplace'
RENTAL_URL = 'https://api.clore.ai/v1/create_order'

def get_available_servers():
    headers = {'auth': AUTH_TOKEN}
    response = requests.get(MARKETPLACE_URL, headers=headers)
    
    if response.status_code == 200:
        data = response.json()
        if data.get("code") == 0:
            return data['market']['offers']
    else:
        print("Error fetching marketplace data:", response.status_code, response.text)
    return []

def rent_server(offer_id, server_id, price):
    headers = {
        'auth': AUTH_TOKEN,
        'Content-type': 'application/json'
    }
    rental_data = {
        'renting_server': server_id,
        'type': 'spot',
        'spotprice': price
    }
    response = requests.post(RENTAL_URL, headers=headers, json=rental_data)
    if response.status_code == 200:
        print(f"Server with ID {server_id} rented successfully.")
    else:
        print("Error renting server:", response.status_code, response.text)

def main():
    while True:
        servers = get_available_servers()
        
        for server in servers:
            model = server['specs']['gpu']
            price = server['spot']['bitcoin']
            server_id = server['id']
            offer_id = server['offer_id']
            
            # Check if the price meets threshold
            if model in price_thresholds and price <= price_thresholds[model]:
                print(f"Renting server {server_id} with {model} at {price} BTC (Threshold: {price_thresholds[model]} BTC)")
                rent_server(offer_id, server_id, price)
        
        # Sleep before re-checking marketplace
        time.sleep(300)  # Adjust based on desired check frequency

if __name__ == "__main__":
    main()

Explanation

  1. get_available_servers: Fetches the current available servers from the spot marketplace.

  2. rent_server: Initiates a rental request for a server if it meets the predefined price conditions.

  3. main loop: Repeatedly checks for servers at optimal prices and rents them when conditions are met.

Summary

This script helps you dynamically rent servers at optimal prices by continuously monitoring and acting on the spot marketplace without manual intervention.

PreviousAutomated Price Adjustment Based on Market DemandNextRental Strategies and Arbitrage

Last updated 6 months ago