import requests import openai # Set up the CoinMarketCap API endpoint and parameters url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest' parameters = { 'start': '1', 'limit': '10', 'convert': 'USD' } # Set up the OpenAI API credentials openai.api_key = '' # Fetch the latest cryptocurrency prices from the CoinMarketCap API response = requests.get(url, headers={'X-CMC_PRO_API_KEY': '<03365e9f-2220-4083-90a7-151a70bb40ae>'}, params=parameters) # Check if the response is successful if response.status_code == 200: # Extract the data from the API response data = response.json() # Extract the relevant data from the API response bitcoin_price = data['data']['cryptocurrency_list'][0]['quote']['USD']['price'] ethereum_price = data['data']['cryptocurrency_list'][1]['quote']['USD']['price'] bitcoin_margin = data['data']['cryptocurrency_list'][0]['quote']['USD']['percent_change_24h'] ethereum_margin = data['data']['cryptocurrency_list'][1]['quote']['USD']['percent_change_24h'] # Use the OpenAI API to generate a prediction for the margin prompt = f"Based on the latest cryptocurrency prices, what will be the margin for Bitcoin and Ethereum in the next 24 hours?" model = "text-davinci-002" response = openai.Completion.create( engine=model, prompt=prompt, temperature=0.5, max_tokens=50, n=1, stop=None, timeout=20, ) # Extract the predicted margin from the OpenAI API response predicted_margin = response.choices[0].text.strip() # Print the results print("Latest cryptocurrency prices:") print(f"Bitcoin: ${bitcoin_price:.2f}") print(f"Ethereum: ${ethereum_price:.2f}") print("24-hour margin:") print(f"Bitcoin: {bitcoin_margin:.2f}%") print(f"Ethereum: {ethereum_margin:.2f}%") print("Predicted margin for the next 24 hours:") print(predicted_margin) else: print("Error: API request failed")