forked from SaxonWarrior/TradeBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_crypto_pairs.py
146 lines (105 loc) · 5.87 KB
/
get_crypto_pairs.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
139
140
141
142
143
144
145
146
#!/usr/bin/env python
from pprint import pprint
import requests
import argparse
#----------------------------------
'''
Usage:-
- Run main program:
time python3
Notes:-
-
ToDo:-
-
XYZ:-
https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing?start=1&limit=3&sortBy=market_cap&sortType=desc&convert=USD,btc,eth&cryptoType=all&tagType=all&aux=ath,atl,high24h,low24h,num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply,volume_7d,volume_30d
https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing?start=1&limit=3&sortBy=market_cap&sortType=desc&convert=USD&cryptoType=all&tagType=all&aux=high24h,low24h,num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply,volume_7d,volume_30d
'''
#----------------------------------
parser = argparse.ArgumentParser()
parser.add_argument("--max", help='Max number pairs to return', type=int, default=30)
parser.add_argument("--csv", help='CSV output format', action='store_true', default=None)
parser.add_argument("--debug", help='debug', action='store_true', default=None)
args = parser.parse_args()
start = 1
limit = 30
max_limit = args.max
#----------------------------------
def getCryptoCurrencyList(start, limit):
#url = f"https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing?start={start}&limit={limit}&sortBy=market_cap&sortType=desc&convert=USD,btc,eth&cryptoType=all&tagType=all&aux=ath,atl,high24h,low24h,num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply,volume_7d,volume_30d"
url = f"https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing?start={start}&limit={limit}&sortBy=market_cap&sortType=desc&convert=USD&cryptoType=all&tagType=all&aux=high24h,low24h,num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply,volume_7d,volume_30d"
headers = {}
response = requests.request(
method="GET",
url=url,
headers=headers)
return response.json()['data']['cryptoCurrencyList']
def getFullCryptoCurrencyList(start, limit, max_limit):
fullCryptoCurrencyList = []
while (True):
CryptoCurrencyList = getCryptoCurrencyList(start, limit)
if len(CryptoCurrencyList) <= 0 or start >= max_limit:
break
for cryptoCurrency in CryptoCurrencyList:
usd_price = 0.0
usd_fullyDilluttedMarketCap = 0.0
usd_marketCap = 0.0
usd_percentChange1h = 0.0
usd_percentChange24h = 0.0
usd_percentChange7d = 0.0
usd_percentChange30d = 0.0
usd_percentChange90d = 0.0
usd_volume24h = 0.0
usd_ytdPriceChangePercentage = 0.0
for quote in cryptoCurrency['quotes']:
if quote['name'] == 'USD':
usd_price = quote['price']
usd_fullyDilluttedMarketCap = quote['fullyDilluttedMarketCap']
usd_marketCap = quote['marketCap']
usd_percentChange1h = quote['percentChange1h']
usd_percentChange24h = quote['percentChange24h']
usd_percentChange7d = quote['percentChange7d']
usd_percentChange30d = quote['percentChange30d']
usd_percentChange90d = quote['percentChange90d']
usd_volume24h = quote['volume24h']
usd_ytdPriceChangePercentage = quote['ytdPriceChangePercentage']
coin = { 'symbol': cryptoCurrency['symbol']
,'name': cryptoCurrency['name']
,'totalSupply': cryptoCurrency['totalSupply']
,'circulatingSupply': cryptoCurrency['circulatingSupply']
,'low24h': cryptoCurrency['low24h']
,'high24h': cryptoCurrency['high24h']
,'dateAdded': cryptoCurrency['dateAdded']
,'usd_price': usd_price
,'usd_fullyDilluttedMarketCap': usd_fullyDilluttedMarketCap
,'usd_marketCap': usd_marketCap
,'usd_percentChange1h': usd_percentChange1h
,'usd_percentChange24h': usd_percentChange24h
,'usd_percentChange7d': usd_percentChange7d
,'usd_percentChange30d': usd_percentChange30d
,'usd_percentChange90d': usd_percentChange90d
,'usd_volume24h': usd_volume24h
,'usd_ytdPriceChangePercentage': usd_ytdPriceChangePercentage
,'cmcRank': cryptoCurrency['cmcRank']
}
fullCryptoCurrencyList.append(coin)
start = start + limit
return fullCryptoCurrencyList[:max_limit]
def showFullCryptoCurrencyList(start, limit, max_limit):
txt = ""
fullCryptoCurrencyList = getFullCryptoCurrencyList(start, limit, max_limit)
if args.csv:
txt += f"Symbol,Rank,Price,24h Change,7d Change,Market Cap,24h Volume,Circulating Supply,Name\n"
else:
txt += f"{'Sym':4} {'Rank':4} {'Price':10} {'24h%':5} {'7d%':6} {'Market Cap':18} {'Volume (24h)':16} {'Circulating Supply (Name)'}\n"
for ac in fullCryptoCurrencyList:
if args.csv:
txt += f"{ac['symbol']},{ac['cmcRank']},{ac['usd_price']},{ac['usd_percentChange24h']},{ac['usd_percentChange7d']},{ac['usd_marketCap']},{ac['usd_volume24h']},{ac['circulatingSupply']},{ac['name']}\n"
else:
txt += f"{ac['symbol']:5} {ac['cmcRank']:3} ${ac['usd_price']:9,.2f} {ac['usd_percentChange24h']:>4.1f}% {ac['usd_percentChange7d']:>5.1f}% ${ac['usd_marketCap']:17,.0f} ${ac['usd_volume24h']:15,.0f} {ac['circulatingSupply']:,.0f} ({ac['name']})\n"
return txt[:-1]
#----------------------------------
#----------------------------------
#----------------------------------
print(showFullCryptoCurrencyList(start, limit, max_limit))
#----------------------------------