Spaces:
No application file
No application file
Upload 2 files
Browse files- market_data.py +30 -0
- space_config.py +18 -0
market_data.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime, timedelta
|
4 |
+
|
5 |
+
class MarketData:
|
6 |
+
def __init__(self):
|
7 |
+
self.base_url = "YOUR_MARKET_DATA_API_ENDPOINT"
|
8 |
+
|
9 |
+
def fetch_ohlcv(self, symbol, timeframe='1d'):
|
10 |
+
"""
|
11 |
+
Fetch OHLCV data for given symbol
|
12 |
+
Returns: DataFrame with columns [timestamp, open, high, low, close, volume]
|
13 |
+
"""
|
14 |
+
endpoint = f"{self.base_url}/historical/{symbol}"
|
15 |
+
params = {
|
16 |
+
'timeframe': timeframe,
|
17 |
+
'limit': 365 # Last year of data
|
18 |
+
}
|
19 |
+
|
20 |
+
response = requests.get(endpoint, params=params)
|
21 |
+
data = response.json()
|
22 |
+
|
23 |
+
df = pd.DataFrame(data)
|
24 |
+
df['timestamp'] = pd.to_datetime(df['timestamp'])
|
25 |
+
return df
|
26 |
+
|
27 |
+
def get_latest_price(self, symbol):
|
28 |
+
endpoint = f"{self.base_url}/price/{symbol}"
|
29 |
+
response = requests.get(endpoint)
|
30 |
+
return response.json()['price']
|
space_config.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import HfApi
|
2 |
+
import os
|
3 |
+
|
4 |
+
def configure_space():
|
5 |
+
api = HfApi()
|
6 |
+
|
7 |
+
# Configure space settings
|
8 |
+
space_config = {
|
9 |
+
"sdk": "gradio",
|
10 |
+
"python_version": "3.10",
|
11 |
+
"app_file": "app.py",
|
12 |
+
"models": [
|
13 |
+
"tmmdev/chart-vision-analyzer",
|
14 |
+
"tmmdev/chart-generator"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
|
18 |
+
return space_config
|