Spaces:
No application file
No application file
File size: 979 Bytes
64e2fc5 |
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 |
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']
|