-
Notifications
You must be signed in to change notification settings - Fork 0
/
tickerhelp.py
executable file
·50 lines (42 loc) · 1.25 KB
/
tickerhelp.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
#!/usr/bin/python3
# tickerhelper: Give it a string of symbols and it returns the coingeck IDs
# This is to address the issue that some of the coingecko IDs are not intuitive
#
# tickerhelp.py -s "xmr, dot, AVAX"
# will give
# Symbol= xmr ID= monero
# Symbol= dot ID= polkadot
# Symbol= AVAX ID= avalanche-2
import requests
import sys, getopt
def symboltoid(code,melist):
lowercode=code.lower()
for i in range (len(melist)):
target=melist[i]['symbol']
idstring="I cannot find it, please don't hate me"
if target==lowercode or target==code:
theindex=i
idstring=melist[i]['id']
if "peg" not in idstring:
print("Symbol= ",code,"ID= ",idstring)
return idstring
def main():
try:
options, remainder = getopt.getopt(sys.argv[1:], 's:', ['symbol='])
#
except getopt.GetoptError:
print ('tickerhelp.py -s <symbollist>')
sys.exit(2)
for opt, arg in options:
if opt == '-h':
print ('tickerhelp.py -s <symbollist>')
sys.exit()
elif opt in ("-s", "--symbol"):
symbollist = arg.split(",")
coinlisturl="https://api.coingecko.com/api/v3/coins/list"
melist=requests.get(coinlisturl).json()
for i in range(len(symbollist)):
symbol=symbollist[i].strip()
symboltoid(symbol,melist)
if __name__ == '__main__':
main()