I've been trying a few days now to get this code to work on MacOS but with no success. Can you please have a look at and see what I'm missing?
Running python 3.6 and I've uploaded the whole code. Thanks a lot
#!/usr/bin/env python3
from __future__ import print_function
try:
import pymarketcap
import decimal
from operator import itemgetter
import argparse
except Exception as e:
print('Make sure to install {0} (pip3 install {0}).'.format(str(e).split("'")[1]))
exit()
# arguments and setup
parser = argparse.ArgumentParser()
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('-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")
args = parser.parse_args()
cmc = pymarketcap.Pymarketcap()
info = []
count = 1
lowercase_exchanges = [x.lower() for x in args.exchanges]
all_exchanges = not bool(args.exchanges)
all_trading_pairs = not bool(args.pairs)
coin_format = '{: <25} {: >6}% {: >10} {: >15} {: <10} {: <10} {: <15} {: <5}'
if not args.simple:
print('CURRENT SETTINGS\n* MINIMUM_PERCENT_VOL:{}\n* TRADING_PAIRS:{}\n* COINS_SHOWN:{}\n* EXCHANGES:{}\n* ALL_TRADING_PAIRS:{}\n* ALL_EXCHANGES:{}\n'.format(args.minimum_vol,args.pairs,args.coins_shown,lowercase_exchanges,all_trading_pairs,all_exchanges))
# retrieve coin data
for coin in cmc.ticker():
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:
trades_into = market["pair"].replace (coin["symbol"]," ").replace("-"," ")
if market['percent_volume'] >= args.minimum_vol and market['updated'] and (trades_into in args.pairs or all_trading_pairs) and (market['exchange'].lower() in lowercase_exchanges or all_exchanges):
has_markets = True
if market['price_usd'] >= best_price:
best_price = market['price_usd']
best_exchange = market['exchange']
best_pair = trades_into
if market['price_usd'] <= worst_price:
worst_price = market['price_usd']
worst_exchange = market['exchange']
worst_pair = trades_into
if has_markets:
info.append([coin['name'],round((best_price/worst_price-1)*100,2),worst_price,worst_exchange,worst_pair,best_price,best_exchange,best_pair])
elif not args.simple:
print(coin['name'],'had no markets that fit the criteria.')
print('[{}/100]'.format(count),end='\r')
count += 1
# show data
info = sorted(info,key=itemgetter(1))[::-1]
print(coin_format.format("COIN","CHANGE","BUY PRICE","BUY AT","BUY WITH","SELL PRICE","SELL AT","SELL WITH"))
for coin in info[0:args.coins_shown]:
print(coin_format.format(*coin))#
also link - https://gist.github.com/anonymous/ec0643e0b27f33cf628fdafce29a698c
The error that I keep getting is this :
Traceback (most recent call last):
File "./run", line 45, in <module>
trades_into = market["pair"].replace(coin["symbol"],"").replace("-","")
TypeError: replace() argument 1 must be str, not int
Really appreciate your help with this.
The Python "TypeError: write () argument must be str, not int" occurs when we try to write an integer to a file using the write () method. To solve the error, use the str () class to convert the integer to a string before writing it to the file. Here is an example of how the error occurs.
Last Updated : 20 Aug, 2020 TypeError is one among the several standard Python exceptions. TypeError is raised whenever an operation is performed on an incorrect/unsupported object type. For example, using the + (addition) operator on a string and an integer value will raise TypeError.
The general causes for TypeError being raised are: 1. Unsupported operation between two types: In the following example, the variable ‘geek’ is a string and the variable ‘num’ is an integer. The + (addition) operator cannot be used between these two types and hence TypeError is raised.
For example, using the + (addition) operator on a string and an integer value will raise TypeError. The general causes for TypeError being raised are: 1. Unsupported operation between two types:
your error is telling you all you need to know coin["symbol"]
is an int, but replace
accepts only Strings. You can fix this by doing str(coin["symbol"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With