破解密码:使用ChatGPT实时分析Bitcoin价格

ChatGPT中文站
Cracking the Code: Analyzing Bitcoin Prices in Real Time with ChatGPT

介绍

大家好,开发者同伴们!在本教程中,我将指导您构建一款应用程序,利用ChatGPT的强大功能分析过去一周的实时比特币价格。通过本教程,您将更好地理解如何利用ChatGPT构建强大的应用程序来分析实时数据。让我们开始吧!

要求

要构建此应用程序,您需要以下工具、软件和 API:

  • Python 3.x:我们将使用Python作为此项目的主要编程语言。
  • 一个文本编辑器或IDE(如Visual Studio Code、PyCharm)
  • 比特币价格数据的API:我们需要一个提供历史比特币价格数据的API。在本教程中,我们将使用Coinranking API,它提供免费计划。
  • OpenAI APIs:我们需要访问OpenAI的GPT-3.5-turbo模型。
  • OpenAI API密钥:您可以从这里获取自己的API密钥。
  • RapidAPI 账户 (从这里免费注册)

在开始之前,通过运行以下命令来安装所需的软件包:

pip install openai
pip install requests
pip install streamlit

您可以从此代码库获取完整代码。

获取过去7天的比特币价格

为了检索过去一周的比特币价格,我们将使用RapidAPI的Coinranking API,如下所示的函数。

def GetBitCoinPrices():
# Define the API endpoint and query parameters
url = "https://coinranking1.p.rapidapi.com/coin/Qwsogvtv82FCd/history"
querystring = {
"referenceCurrencyUuid": "yhjMzLPhuIDl",
"timePeriod": "7d"
}
# Define the request headers with API key and host
headers = {
"X-RapidAPI-Key": "a617d6467dmshac84323ce581a72p11caa9jsn1adf8bbcbd47",
"X-RapidAPI-Host": "coinranking1.p.rapidapi.com"
}
# Send a GET request to the API endpoint with query parameters and headers
response = requests.request(
"GET", url, headers=headers, params=querystring)
# Parse the response data as a JSON object
JSONResult = json.loads(response.text)
# Extract the "history" field from the JSON response
history = JSONResult["data"]["history"]
# Extract the "price" field from each element in the "history" array and add to a list
prices = []
for change in history:
prices.append(change["price"])
# Join the list of prices into a comma-separated string
pricesList = ','.join(prices)
# Return the comma-separated string of prices
return pricesLis

在这个函数中,我们初始化RapidAPI连接,获取过去7天的比特币价格,并返回结果。

使用ChatGPT分析数据

首先,我们需要为ChatGPT创建一个自定义提示,我们需要制定一个清晰简洁的问题,指出我们想在比特币数据上执行的分析。例如,我们将使用以下提示:

chatGPTPrompt = f"""You are an expert crypto trader with more than 10 years of experience,
I will provide you with a list of bitcoin prices for the last 7 days
can you provide me with a technical analysis
of Bitcoin based on these prices. here is what I want:
Price Overview,
Moving Averages,
Relative Strength Index (RSI),
Moving Average Convergence Divergence (MACD),
Advice and Suggestion,
Do I buy or sell?
Please be as detailed as much as you can, and explain in a way any beginner can understand. and make sure to use headings
Here is the price list: {bitcoinPrices}"""

在这个提示中,我们强制ChatGPT扮演专家交易员的角色,然后告诉ChatGPT我们将提供要分析的价格(这些价格是从先前的函数获得的)。

现在,让我们创建一个用于使用高级提示查询ChatGPT的函数。

def BasicGeneration(userPrompt):
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": userPrompt}]
)
return completion.choices[0].message.content

这将返回过去一周的比特币价格数据分析,包括趋势、波动性和值得注意的事件。

结论

在本教程中,我们演示了如何构建一个应用程序,使用ChatGPT分析过去一周的比特币实时价格。通过利用ChatGPT的强大功能,您可以创建强大的应用程序,分析实时数据并提供有价值的见解。希望您能从本教程中受益,我迫不及待地想看到您将使用ChatGPT创建的惊人应用程序!

?在 Instagram 上关注我?

2023-10-20 16:56:46 AI中文站翻译自原文