-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto.py
68 lines (54 loc) · 2.28 KB
/
crypto.py
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
67
68
import datetime
import requests
def coin(symbol):
# Get Token Valid for 24 Hours
url = "https://bravenewcoin.p.rapidapi.com/oauth/token"
payload = "{\r\"audience\": \"https://api.bravenewcoin.com\",\r\"client_id\": \"oCdQoZoI96ERE9HY3sQ7JmbACfBf55RY\",\r\"grant_type\": \"client_credentials\"\r}"
headers = {
'content-type': "application/json",
'x-rapidapi-host': "bravenewcoin.p.rapidapi.com",
'x-rapidapi-key': "ca396c8c62mshf51f177a6611b4ap1cf15ajsnb909632c0ce7"
}
response = requests.request("POST", url, data=payload, headers=headers)
datas = response.json()
token = datas['access_token']
#Get Asset ID by Symbol
url = "https://bravenewcoin.p.rapidapi.com/asset"
querystring = {"symbol":f"{symbol.upper()}","status":"ACTIVE"}
headers = {
"X-RapidAPI-Key": "ca396c8c62mshf51f177a6611b4ap1cf15ajsnb909632c0ce7",
"X-RapidAPI-Host": "bravenewcoin.p.rapidapi.com"
}
response_id = requests.request("GET", url, headers=headers, params=querystring)
dic_id = response_id.json()
data_keys = dic_id['content']
data_id = str(data_keys[0]['id'])
data_name = data_keys[0]['name']
# Get the asset details
url = "https://bravenewcoin.p.rapidapi.com/market-cap"
querystring = {"assetId": f" {data_id}"}
headers = {
'authorization': f"Bearer {token}",
'x-rapidapi-host': "bravenewcoin.p.rapidapi.com",
'x-rapidapi-key': "ca396c8c62mshf51f177a6611b4ap1cf15ajsnb909632c0ce7"
}
response = requests.request("GET",
url,
headers=headers,
params=querystring)
dic = response.json()
#print(dic)
data = dic['content']
price = str(data[0]['price'])
marketcaprank = data[0]['marketCapRank']
total_market_cap = str(data[0]['totalMarketCap'])
totalsupply = data[0]['totalSupply']
timestamp = data[0]['timestamp']
mes1 = f"{data_name} Mkt Rank {marketcaprank}"
mes2 = f"Price = {price[0:9]}$ per/{symbol}"
mes3 = f"Mkt Cap = {total_market_cap[0:20]}$"
mes4 = f"Supply = {totalsupply}"
mes5 = f" "
mes6 = f"Timestamp: {timestamp[:19]} GMT"
#print(mes1, mes2, mes3, mes4, mes5, mes6)
return mes1, mes2, mes3, mes4, mes5, mes6