natexcvi
Adapt to API changes
e451088 unverified
raw
history blame
No virus
2.13 kB
from json import JSONDecodeError
import requests
class TradeAssistantAPI:
def __init__(self, token: str) -> None:
self.token = token
self.url = "https://natexcvi-trade-assistant.hf.space"
self.base_headers = {"Authorization": f"Bearer {self.token}"}
def get_recommendations(self):
url = f"{self.url}/recommend.json"
response = requests.get(url, headers=self.base_headers)
try:
body = response.json()
if "message" in body:
raise Exception(body["message"])
return body
except JSONDecodeError:
raise Exception(response.text)
def train_model(self):
url = f"{self.url}/train"
response = requests.post(url, headers=self.base_headers)
try:
body = response.json()
if "message" in body:
raise Exception(body["message"])
return body
except JSONDecodeError:
raise Exception(response.text)
def get_training_job_status(self, job_id: str):
url = f"{self.url}/train/{job_id}"
response = requests.get(url, headers=self.base_headers)
try:
body = response.json()
if "message" in body:
raise Exception(body["message"])
return body
except JSONDecodeError:
raise Exception(response.text)
def list_training_jobs(self):
url = f"{self.url}/train"
response = requests.get(url, headers=self.base_headers)
try:
body = response.json()
if "message" in body:
raise Exception(body["message"])
return body
except JSONDecodeError:
raise Exception(response.text)
def get_portfolio(self):
url = f"{self.url}/portfolio"
response = requests.get(url, headers=self.base_headers)
try:
body = response.json()
if "message" in body:
raise Exception(body["message"])
return body
except JSONDecodeError:
raise Exception(response.text)