-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_client.py
More file actions
54 lines (46 loc) · 1.45 KB
/
api_client.py
File metadata and controls
54 lines (46 loc) · 1.45 KB
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
import requests
from requests_toolbelt.utils import dump
###########################################################
######### Fetching Newest Market Data #####################
_baseurl = 'https://coincube.io/api/v1/'
auth_args = {'key': '', 'secret': ''}
def cube_details(cube_id):
url = _baseurl + 'cube_details'
data = {**auth_args, **{
'cube_id': cube_id
}}
# POST request
r = requests.post(url, data=data)
# Return JSON data
content = r.json()
if r.status_code == 200:
return content
else:
return "There was a problem: " + str(r.status_code)
def get_portfolios(algorithm_id=6):
url = _baseurl + 'get_portfolios'
data = {**auth_args, **{
'algorithm_id': algorithm_id
}}
# POST request
r = requests.post(url, data=data)
# Return JSON data
content = r.json()
if r.status_code == 200:
return content
else:
return "There was a problem: " + str(r.status_code)
def post_allocations(allocations, algorithm_id=6):
url = _baseurl + 'post_allocations'
data = {**auth_args, **{
'allocations': allocations,
'algorithm_id': algorithm_id
}}
# POST request
r = requests.post(url, json=data)
data = dump.dump_all(r)
# Return 'success' or status code
if r.status_code == 200:
return "success"
else:
return "There was a problem: " + str(r.status_code)