-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagicapi.py
More file actions
172 lines (147 loc) · 5.09 KB
/
magicapi.py
File metadata and controls
172 lines (147 loc) · 5.09 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import flask
import requests
import json
from flask import jsonify
while True :
app = flask.Flask(__name__)
app.config["DEBUG"] = True
# Gets data for defined coins from CREX24 (address have to be changed to add new coins)
crexapi = "https://api.crex24.com/CryptoExchangeService/BotPublic/ReturnTicker?request=[NamePairs=BTC_ALPS,BTC_CRS]"
crexresp = requests.get(crexapi)
crexdata = crexresp.text
crexparsed = json.loads(crexdata)
# Gets Coinstock.me coin data
csapi = "https://coinstock.me//api/v2/tickers.json"
csresp = requests.get(csapi)
csdata = csresp.text
csparsed = json.loads(csdata)
tlrfloat = float(csparsed["tlrbtc"]["ticker"]["last"])
rpwnfloat = float(csparsed["rpwnbtc"]["ticker"]["last"])
# Gets Graviex coin data
grvapi = "https://graviex.net//api/v2/tickers.json"
grvresp = requests.get(grvapi)
grvdata = grvresp.text
grvparsed = json.loads(grvdata)
vtlfloat = float(grvparsed["vtlbtc"]["ticker"]["last"])
# Gets Cryptobridge API data
cbapi = "https://api.crypto-bridge.org/api/v1/ticker"
cbresp = requests.get(cbapi)
cbdata = cbresp.text
cbparsed = json.loads(cbdata)
# Parses Gincoin price data
for i in cbparsed:
if i['id'] == 'GIN_BTC':
cbginprice = (i)['last']
cbginfloat = float(cbginprice)
break
# Parses Manocoin price data
for i in cbparsed:
if i['id'] == 'MANO_BTC':
cbmanoprice = (i)['last']
cbmanofloat = float(cbmanoprice)
break
#Parses MCT+ price data
for i in cbparsed:
if i['id'] == 'MCT_BTC':
cbmctprice = (i)['last']
cbmctfloat = float(cbmctprice)
break
# Scrapes CREX24 data
for i in crexparsed['Tickers']:
if i['PairName'] == "BTC_ALPS":
alpsprice = (i)['Last']
alpsvolumetext = (i)['BaseVolume']
alpsvolume = float(alpsvolumetext)
alpsfloat = float(alpsprice)
break
for i in crexparsed['Tickers']:
if i['PairName'] == "BTC_CRS":
crsprice = (i)['Last']
crsvolumetext = (i)['BaseVolume']
crsvolume = float(crsvolumetext)
crsfloat = float(crsprice)
break
# Gets nethash for the listed coins
ginnethashresp = requests.get( "https://explorer.gincoin.io/api/getnetworkhashps" )
if ginnethashresp.status_code == 200:
ginnethash = float(ginnethashresp.text)
else:
ginnethash = 0
manonethashresp = requests.get( "http://explorer.manocoin.org/api/getnetworkhashps" )
if manonethashresp.status_code == 200:
manonethash = float(manonethashresp.text)
else:
manonethash = 0
alpsnethashresp = requests.get("http://explorer.alpenschilling.cash/api/getnetworkhashps")
if alpsnethashresp.status_code == 200:
alpsnethash = float(alpsnethashresp.text)
else:
alpsnethash = 0
crsnethashresp = requests.get("https://criptoreal.info/api/getnetworkhashps")
if crsnethashresp.status_code == 200:
crsnethash = float(crsnethashresp.text)
else:
crsnethash = 0
mctnethashresp = requests.get("https://explorer.mct.plus/api/getnetworkhashps")
if mctnethashresp.status_code == 200:
mctnethash = float(mctnethashresp.text)
else:
mctnethash = 0
tlrnethashresp = requests.get("https://explorer.mct.plus/api/getnetworkhashps")
if tlrnethashresp.status_code == 200:
tlrnethash = float(tlrnethashresp.text)
else:
tlrnethash = 0
vtlnethashresp = requests.get("https://explorer.vertical.ovh/api/getnetworkhashps")
if vtlnethashresp.status_code == 200:
vtlnethash = float(vtlnethashresp.text)
else:
vtlnethash = 0
rpwnnethashresp = requests.get("http://explorer.respawn.rocks:3001/api/getnetworkhashps")
if rpwnnethashresp.status_code == 200:
rpwnnethash = float(rpwnnethashresp.text)
else:
rpwnnethash = 0
# Creates list data
nethashps = [
{'id': 0,
'coin': "GIN",
'nethash': ginnethash,
'last': cbginfloat},
{'id': 1,
'coin': "MANO",
'nethash': manonethash,
'last': cbmanofloat},
{'id': 2,
'coin': "ALPS",
'nethash': alpsnethash,
'last': alpsfloat},
{'id': 3,
'coin': "CRS",
'nethash': crsnethash,
'last': crsfloat},
{'id': 4,
'coin': "MCT",
'nethash': mctnethash,
'last': cbmctfloat},
{'id': 5,
'coin': "TLR",
'nethash': tlrnethash,
'last': tlrfloat},
{'id': 6,
'coin': "VTL",
'nethash': vtlnethash,
'last': vtlfloat},
{'id': 7,
'coin': "RPWN",
'nethash': rpwnnethash,
'last': rpwnfloat},
]
@app.route('/', methods=['GET'])
def home():
return "Welcome to Trollmann's API server! Stay gentle and don't overload me!"
@app.route('/nethash', methods=['GET', 'POST'])
def nethash():
return jsonify(nethashps)
app.run()
time.sleep(300)