-
Notifications
You must be signed in to change notification settings - Fork 26
/
start
executable file
·104 lines (96 loc) · 4.19 KB
/
start
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
#!/usr/bin/env python3
import decimal
import argparse
from operator import itemgetter
import pymarketcap
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-m', '--minimum_vol', type=float, help='Minimum Percent volume per exchange to have to count', default=1)
parser.add_argument('-p', '--pairs', nargs='*', default=[], help='Pairs the coins can be arbitraged with - default=all')
parser.add_argument('-l', '--coin_list', nargs='*', default=[], help='Replaces the number of top coins with a custom list of currencies')
parser.add_argument('-c', '--coins_shown', type=int, default=10, help='Number of coins to show')
parser.add_argument('-e', '--exchanges', nargs='*', help='Acceptable Exchanges - default=all', default=[])
parser.add_argument('-s', '--simple', help='Toggle off errors and settings', default=False, action="store_true")
parser.add_argument('-t', '--top', type=int, help='Set the number of coins to run with', default=100)
args = parser.parse_args()
cmc = pymarketcap.Pymarketcap()
info = []
count = 1
lowercase_exchanges = [x.lower() for x in args.exchanges]
coin_format = '{: <25} {: >6}% {: >10} {: <15} {: <10} {: >7}% {: <10} {: <15} {: <10} {: >8}%'
if not args.simple:
mode = 'TOP'
if args.coin_list:
mode = 'COIN_LIST'
print('CURRENT SETTINGS\n',
'‣ MINIMUM_PERCENT_VOL: {}'.format(args.minimum_vol),
'‣ TRADING_PAIRS: {}'.format(args.pairs),
'‣ COINS_SHOWN: {}'.format(args.coins_shown),
'‣ EXCHANGES: {}'.format(lowercase_exchanges),
'‣ ALL_PAIRS: {}'.format(not args.pairs),
'‣ ALL_EXCHANGES: {}'.format(not args.exchanges),
'‣ {}: {}'.format(mode, args.coin_list or args.top),
sep='\n')
if args.coin_list:
coin_data = {coin: cmc.ticker(coin)['data'] for coin in args.coin_list}
elif args.top > 100:
count = args.top
size = 100
coin_data = {}
while count > 0:
if count - size < 0:
size = count
coin_data.update(cmc.ticker(limit=size, start=args.top-count)['data'])
count -= size
else:
coin_data = cmc.ticker(limit=args.top)['data']
for id_, coin in coin_data.items():
try:
markets = cmc.markets(coin["id"])
except Exception as e:
markets = cmc.markets(coin["symbol"])
best_price = 0
best_exchange = ''
best_pair = ''
worst_price = 999999
worst_exchange = ''
worst_pair = ''
has_markets = False
for market in markets["markets"]:
trades_into = market["pair"].replace(coin["symbol"],"").replace("-","").replace("/","")
if (market['percent_volume'] >= args.minimum_vol and
market['updated'] and
(trades_into in args.pairs or not args.pairs) and
(market['source'].lower() in lowercase_exchanges or not args.exchanges)
):
has_markets = True
if market['price'] >= best_price:
best_price = market['price']
best_exchange = market['source']
best_pair = trades_into
best_volume = market['percent_volume']
if market['price'] <= worst_price:
worst_price = market['price']
worst_exchange = market['source']
worst_pair = trades_into
worst_volume = market['percent_volume']
if has_markets:
info.append([coin['name'],
round((best_price/worst_price-1)*100,2),
worst_price,
worst_exchange,
worst_pair,
round(worst_volume, 2),
best_price,
best_exchange,
best_pair,
round(best_volume, 2)
])
elif not args.simple:
print(coin['name'],'had no markets that fit the criteria.')
print('[{}/{}]'.format(count, args.top),end='\r')
count += 1
# show data
info = sorted(info, key=itemgetter(1), reverse=True)
print(coin_format.format("COIN","CHANGE","BUY PRICE","BUY AT","BUY WITH","BUY VOL","SELL PRICE","SELL AT","SELL WITH","SELL VOL"))
for coin in info[:args.coins_shown]:
print(coin_format.format(*coin))