File size: 2,126 Bytes
4c004a4
 
c70f265
 
 
 
 
 
 
 
 
 
dbe36d3
c70f265
4c004a4
 
 
 
 
 
 
c70f265
 
 
4907b42
4c004a4
 
 
 
 
 
 
87e4852
 
 
 
4c004a4
 
 
 
 
 
 
864f824
 
 
 
 
 
 
 
 
 
 
e451088
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)