Skip to content

Commit 538db67

Browse files
authored
Create price_oracle.py
1 parent 4314727 commit 538db67

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

api/price_oracle.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# api/price_oracle.py
2+
3+
import requests
4+
5+
class PriceOracle:
6+
def __init__(self):
7+
self.api_url = "https://api.coingecko.com/api/v3/simple/price"
8+
9+
def get_price(self, coin_id):
10+
try:
11+
response = requests.get(f"{self.api_url}?ids={coin_id}&vs_currencies=usd")
12+
response.raise_for_status()
13+
data = response.json()
14+
return data[coin_id]['usd']
15+
except Exception as e:
16+
print(f"Error fetching price data: {e}")
17+
return None

0 commit comments

Comments
 (0)