-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmc_live_prices_v2.py
executable file
·58 lines (44 loc) · 2.14 KB
/
cmc_live_prices_v2.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
#!/usr/bin/env python36
import requests, graphitesend, redis
import json, time
def SendData():
response = requests.get(URL)
if response.status_code == 200:
AllData = response.json()
new_dict = {}
sitename = "cmc"
for i in AllData:
if i['id'] in cryptos:
new_key_1 = sitename + '-' + i['symbol'].lower() + '-last'
new_val_1 = i['price_inr']
new_dict.update({new_key_1:new_val_1})
new_key_2 = sitename + '-' + i['symbol'].lower() + '-usd'
new_val_2 = i['price_inr']
new_dict.update({new_key_2:new_val_2})
new_key_3 = sitename + '-' + i['symbol'].lower() + '-24h-pct-change'
new_val_3 = i['percent_change_24h']
new_dict.update({new_key_3:new_val_3})
new_key_4 = sitename + '-' + i['symbol'].lower() + '-24h-volume-usd'
new_val_4 = i['24h_volume_usd']
new_dict.update({new_key_4:new_val_4})
new_key_5 = sitename + '-' + i['symbol'].lower() + '-24h-volume-inr'
new_val_5 = i['24h_volume_inr']
new_dict.update({new_key_5:new_val_5})
new_key_6 = sitename + '-' + i['symbol'].lower() + '-rank'
new_val_6 = i['rank']
new_dict.update({new_key_6:new_val_6})
g.send_dict(new_dict)
r.hmset("Cmc", new_dict)
else:
pass
if __name__=="__main__":
cryptos = ["bitcoin", "ethereum", "ripple", "bitcoin-cash", "litecoin", "cardano", "neo", "stellar", "eos", "monero", "dash", "iota", "nem", "tron", "ethereum-classic", "vechain", "lisk", "nano", "omisego", "qtum", "bitcoin-gold", "zcash", "verge", "dogecoin", "siacoin", "ontology", "aeternity", "0x", "electroneum", "digibyte", "golem-network-tokens", "gas", "basic-attention-token", "zcoin", "deepbrain-chain", "red-pulse", "request-network", "zilla", "zilliqa", "nucleus-vision", "aion" ]
URL = "https://api.coinmarketcap.com/v1/ticker/?convert=INR&limit=1000"
SERVER = '127.0.0.1'
CARBON_PORT = 2003
REDIS_PORT = 6379
r = redis.Redis(host=SERVER, port=REDIS_PORT, db=0)
g = graphitesend.init(graphite_server=SERVER, graphite_port=CARBON_PORT, prefix='ohio-analyzer-1.metrics-cmc', system_name='')
while True:
time.sleep(6)
SendData()