Spaces:
No application file
No application file
| import requests | |
| import pandas as pd | |
| from datetime import datetime, timedelta | |
| class MarketData: | |
| def __init__(self): | |
| self.base_url = "YOUR_MARKET_DATA_API_ENDPOINT" | |
| def fetch_ohlcv(self, symbol, timeframe='1d'): | |
| """ | |
| Fetch OHLCV data for given symbol | |
| Returns: DataFrame with columns [timestamp, open, high, low, close, volume] | |
| """ | |
| endpoint = f"{self.base_url}/historical/{symbol}" | |
| params = { | |
| 'timeframe': timeframe, | |
| 'limit': 365 # Last year of data | |
| } | |
| response = requests.get(endpoint, params=params) | |
| data = response.json() | |
| df = pd.DataFrame(data) | |
| df['timestamp'] = pd.to_datetime(df['timestamp']) | |
| return df | |
| def get_latest_price(self, symbol): | |
| endpoint = f"{self.base_url}/price/{symbol}" | |
| response = requests.get(endpoint) | |
| return response.json()['price'] | |