typesdigital commited on
Commit
a3a35e0
·
1 Parent(s): 977c169

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import openai
3
+
4
+ # Set up the CoinMarketCap API endpoint and parameters
5
+ url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
6
+ parameters = {
7
+ 'start': '1',
8
+ 'limit': '10',
9
+ 'convert': 'USD'
10
+ }
11
+
12
+ # Set up the OpenAI API credentials
13
+ openai.api_key = '<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>'
14
+
15
+ # Fetch the latest cryptocurrency prices from the CoinMarketCap API
16
+ response = requests.get(url, headers={'X-CMC_PRO_API_KEY': '<03365e9f-2220-4083-90a7-151a70bb40ae>'}, params=parameters)
17
+ data = response.json()['data']
18
+
19
+ # Extract the relevant data from the API response
20
+ bitcoin_price = data[0]['quote']['USD']['price']
21
+ ethereum_price = data[1]['quote']['USD']['price']
22
+ bitcoin_margin = data[0]['quote']['USD']['percent_change_24h']
23
+ ethereum_margin = data[1]['quote']['USD']['percent_change_24h']
24
+
25
+ # Use the OpenAI API to generate a prediction for the margin
26
+ prompt = f"Based on the latest cryptocurrency prices, what will be the margin for Bitcoin and Ethereum in the next 24 hours?"
27
+ model = "text-davinci-002"
28
+ response = openai.Completion.create(
29
+ engine=model,
30
+ prompt=prompt,
31
+ temperature=0.5,
32
+ max_tokens=50,
33
+ n=1,
34
+ stop=None,
35
+ timeout=20,
36
+ )
37
+
38
+ # Extract the predicted margin from the OpenAI API response
39
+ predicted_margin = response.choices[0].text.strip()
40
+
41
+ # Print the results
42
+ print("Latest cryptocurrency prices:")
43
+ print(f"Bitcoin: ${bitcoin_price:.2f}")
44
+ print(f"Ethereum: ${ethereum_price:.2f}")
45
+ print("24-hour margin:")
46
+ print(f"Bitcoin: {bitcoin_margin:.2f}%")
47
+ print(f"Ethereum: {ethereum_margin:.2f}%")
48
+ print("Predicted margin for the next 24 hours:")
49
+ print(predicted_margin)