This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_information.py
138 lines (109 loc) · 4.71 KB
/
get_information.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
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
from bs4 import BeautifulSoup
from requests import get
from time import sleep
import pandas as pd
from ignore_list import ignore_list
def getTop1000(): # Top 1000
try:
tables = []
# We first start by getting overall list of coins from coingecko?
url = "https://www.coingecko.com/en?page="
# In theory we could extract all 8000 coins by extending page to 81 update this accordingly works
last_page = 11 # Update this accordingly
for page in range(1, last_page + 1): # Gets top 1000 coins
response = get(
url + str(page)
) # Query coingecko for table. Note that each page stores 100 symbols
html_page = response.content
table = BeautifulSoup(html_page, "html.parser").find_all("table")
df = pd.read_html(str(table))[0]
tables.append(df)
sleep(0.5)
print("[Top 1000] Extracting page", page, "/", last_page)
all_coins = pd.concat(tables)
all_coins = all_coins.dropna(axis=1, how='all')
top_1000 = all_coins[0:1000]
coins = []
symbols = []
# Add symbol column and edit coin column
for index, row in top_1000.iterrows():
try:
split_word = row["Coin"].split()
symbol = split_word[-1] # Gets symbol
name = " ".join(
[word for word in split_word if word != symbol]
) # Removes symbol from name and joins string
if name == "":
name = symbol # For edge cases like XRP XRP XRP
coins.append(name)
symbols.append(symbol)
except Exception as e:
print("Error occured while adding symbols & coin:", e)
# Replaces coin column with cleaned name # We take top 2800 due to '#' not being labelled after
top_1000["Coin"] = coins
# Insert symbol column after coin
top_1000.insert(top_1000.columns.get_loc("Coin"), "Symbol", symbols)
top_1000 = top_1000.query("Symbol not in @ignore_list")
return top_1000
except Exception as e:
print("Error:", e)
print("Getting top 1000 symbols failed, retrying in 30s")
sleep(30) # Sleeps 20s, and re-attempt to get information
return getTop1000() # Re-attempt if fail
def getBinanceSymbols():
try:
url = "https://api.binance.com/api/v3/exchangeInfo" # Gets all exchange info from binance
response = get(url).json()
binance_symbols = []
def isLevToken(symbol):
if symbol[-2:] == "UP":
return True
elif len(symbol) >= 6 and symbol[-4:] == "DOWN":
return True
elif "BULL" in symbol or "BEAR" in symbol:
return True
else:
return False
# We filter for lev tokens
for i in range(0, len(response["symbols"])):
symbol = response["symbols"][i]["baseAsset"]
if (symbol not in binance_symbols) and (not isLevToken(symbol)):
binance_symbols.append(symbol)
print("Binance has a total of", len(binance_symbols), "unique crypto offerings")
return binance_symbols
except Exception as e:
print("Error", e)
print("Getting Binance Symbols failed, retrying in 30s")
sleep(30)
return getBinanceSymbols()
def getCoinbaseSymbols():
try:
# Hits CB REST API for all products)
url = "https://api.pro.coinbase.com/products"
response = get(url).json()
coinbase_symbols = []
for i in range(0, len(response)):
symbol = response[i]["base_currency"]
if symbol not in coinbase_symbols:
coinbase_symbols.append(symbol)
print("Coinbase has a total of", len(coinbase_symbols), "unique symbols")
return coinbase_symbols
except Exception as e:
print("Error", e)
print("Getting Coinbase Symbols failed, retrying in 30s")
sleep(30)
return getCoinbaseSymbols()
def getCoinbaseCustodySymbols():
try:
url = "https://api.custody.coinbase.com/api/marketing/currencies"
response = get(url).json()
response
print("No. of Coinbase Custody Symbols:", len(response))
symbols = []
for asset in response:
symbols.append(asset["symbol"].upper())
return symbols
except Exception as e:
print("Error", e)
print("Getting Coinbase Custody Symbols failed, retrying in 30s")
return getCoinbaseCustodySymbols()