-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgemini_api_call.py
55 lines (44 loc) · 1.63 KB
/
gemini_api_call.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
from dotenv import load_dotenv
import os
load_dotenv() # This loads the variables from .env into the environment
def make_api_call():
'''
# Trial 1
# Accessing the API key from an environment variable
api_key = os.getenv('GEMINI_KEY')
print(api_key)
if not api_key:
raise ValueError("API key not found. Please set the GEMINI_KEY environment variable.")
# The API endpoint you're trying to access; replace this with the actual endpoint
url = 'https://api.gemini.com/v1/symbols'
# Including the API key in the request's header
headers = {
'Authorization': f'Bearer {api_key}'
}
# Making the GET request
response = requests.get(url, headers=headers)
# Checking if the request was successful
if response.status_code == 200:
# Processing the response
print("working")
data = response.json()
print(data)
else:
print(f'Failed to retrieve data: {response.status_code}')
#Trial 2
symbols = ['btcusd', 'ethusd'] # Symbols for Bitcoin and Ethereum trading pairs
for symbol in symbols:
url = f'https://api.gemini.com/v1/pubticker/{symbol}'
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(f"Symbol: {symbol.upper()}")
print(f"Last trading price: {data['last']}")
print(f"Volume: {data['volume'][symbol[:3].upper()]}")
print("------")
else:
print(f'Failed to retrieve data for {symbol.upper()}: {response.status_code}')
'''
if __name__ == '__main__':
make_api_call()