Skip to content

Commit

Permalink
Using f-strings now.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopetiz committed Aug 27, 2020
1 parent 2cd9538 commit d30a12c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
8 changes: 4 additions & 4 deletions cryptoalgotrading/aux.py
Expand Up @@ -9,7 +9,7 @@
import sys
import matplotlib as mpl
if os.environ.get('DISPLAY','') == '':
print('no display found. Using non-interactive Agg backend')
print(f'No display found. Using non-interactive Agg backend')
mpl.use('Agg')

import matplotlib.pylab as plt
Expand Down Expand Up @@ -522,8 +522,8 @@ def time_to_index(data, _datetime):

try:
d = data[(data.time > dtime[0]) & (data.time < dtime[1])]
except e as err:
print(err)
except Exception as e:
print(f'{e}')
return (0,0)

return d.index[0], d.index[-1]
Expand Down Expand Up @@ -639,7 +639,7 @@ def beep(duration=0.5):
system('play --no-show-progress --null --channels 1 synth %s sine %f' %
(duration, freq))
except Exception as e:
print(e, "Couldn't play beep.")
print(f"Couldn't play beep-> {e}")

return 0

Expand Down
56 changes: 25 additions & 31 deletions cryptoalgotrading/cryptoalgotrading.py
Expand Up @@ -44,7 +44,7 @@


def signal_handler(sig, frame):
print('You pressed Ctrl+C!')
print(f'You pressed Ctrl+C!')
sys.exit(0)

# Prevents FutureWarning from Pandas.
Expand Down Expand Up @@ -154,7 +154,7 @@ def tick_by_tick(market,
if not isinstance(entry_funcs, list): entry_funcs=[entry_funcs]
if not isinstance(exit_funcs, list): exit_funcs=[exit_funcs]

print('[Market analysis]: ' + market + '\n')
print(f'[Market analysis]: {market}')

if from_file:
try:
Expand Down Expand Up @@ -213,8 +213,8 @@ def tick_by_tick(market,
if exit_funcs:
aux_buy = True

print(str(data_init.time.iloc[i + 109 + date[0]]) + \
' [BUY] @ ' + str(data_init.Ask.iloc[i + 109 + date[0]]) + '\n')
print(f'''{data_init.time.iloc[i + 109 + date[0]]} \
[BUY] @ {data_init.Ask.iloc[i + 109 + date[0]]}''')

else:
# Used for trailing stop loss.
Expand All @@ -238,10 +238,10 @@ def tick_by_tick(market,
buy_price) /
buy_price)*100, 2)

print(str(data_init.time.iloc[i + 109 + date[0]]) + \
' [SELL]@ ' + str(data_init.Bid.iloc[i + 109 + date[0]]) + '\n')
print(f'''{data_init.time.iloc[i + 109 + date[0]]} \
[SELL]@ {data_init.Bid.iloc[i + 109 + date[0]]}''')

print('[P&L] > ' + str(total) + '%.' + '\n')
print(f'[P&L] > {total}%.')

#plt.plot(data.Last.iloc[i:i+50])
#plt.draw()
Expand Down Expand Up @@ -305,12 +305,12 @@ def realtime(exchanges,
if "bittrex" in exchanges:
if simulation:
bt = Bittrex('', '')
print("Starting Bot with Bittrex")
print(f"Starting Bot with Bittrex")
else:
try:
bt = RiskManagement(var.ky, var.sct)
except Exception as e:
print("[Error] Couldn't connect to Bittrex", e)
print(f"[Error] Couldn't connect to Bittrex: {e}")
nr_exchanges -=1

# Binance exchange
Expand All @@ -322,9 +322,9 @@ def realtime(exchanges,
bnb = Binance.set('', '')
print("Starting Bot with Binance")
except Exception as e:
print("[Error] Couldn't connect to Binance", e)
print(f"[Error] Couldn't connect to Binance: {e}")
else:
print("Can't use Binance exchange in real scenario, just simulation.")
print(f"Can't use Binance exchange in real scenario, just simulation.")
sys.exit(1)
#try:
# bnb = RiskManagement(var.ky, var.sct)
Expand Down Expand Up @@ -409,29 +409,25 @@ def realtime(exchanges,
# M U D A R
sold_at = sell_res

print('[SELL]@ ' + str(sold_at) +\
' > ' + market_name, 1, log_level)
print(f'[SELL]@ {sold_at} > {market_name}')

print('[P&L] ' + market_name + '> ' +\
str(round(((sold_at-\
portfolio[market_name]['bought_at'])/\
portfolio[market_name]['bought_at'])*100,2)) +\
'%.', 1, log_level)
res = ((sold_at - portfolio[market_name]['bought_at'])/\
portfolio[market_name]['bought_at'])*100

print(f'[P&L] {market_name}> {res:.2f}%.')


# implementar binance
else:
#SIMULATION
#print('> https://bittrex.com/Market/Index?MarketName=' + market_name)

print('[SELL]@ ' + str(data.Bid.iloc[-1]) +\
' > ' + market_name, 1, log_level)
print(f'[SELL]@ {data.Bid.iloc[-1]} > {market_name}')

res = ((data.Bid.iloc[-1] - portfolio[market_name]['bought_at'])/\
portfolio[market_name]['bought_at'])*100

print('[P&L] ' + market_name + '> ' +\
str(round(((data.Bid.iloc[-1]-\
portfolio[market_name]['bought_at'])/\
portfolio[market_name]['bought_at'])*100,2)) +\
'%.', 1, log_level)
print(f'[P&L] {market_name} > {res:.2f}%.')

locals()[market_name].to_csv('df_' + market_name + '.csv')
del locals()[market_name]
Expand All @@ -457,12 +453,11 @@ def realtime(exchanges,
portfolio[market_name]['quantity'] = msg[1]
portfolio[market_name]['count'] = 0

print('[BUY]@ ' + str(msg[0]) +\
' > ' + market_name, 1, log_level)
print(f'[BUY]@ {msg[0]} > {market_name}')

else:
print("[XXXX] Could not buy @ " + str(data.Ask.iloc[-1] * 1.01) +\
"\n[MSG>] " + msg, 0, log_level)
print(f"[XXXX] Could not buy @ {data.Ask.iloc[-1] * 1.01} \
[MSG>] {msg}")

else:
#SIMULATION
Expand All @@ -474,8 +469,7 @@ def realtime(exchanges,

#print('> https://bittrex.com/Market/Index?MarketName='+market_name)

print('[BUY]@ ' + str(data.Ask.iloc[-1]) +\
' > ' + market_name, 1, log_level)
print(f'[BUY]@{data.Ask.iloc[-1]} > {market_name}')

# In case of processing time is bigger than *refresh_interval* doesn't sleep.
if refresh_interval - (time()-start_time) > 0:
Expand Down
4 changes: 2 additions & 2 deletions cryptoalgotrading/var.py
Expand Up @@ -22,7 +22,7 @@
db_name = environ['DB_NAME']

except Exception as e:
print("Could not use environment user and password variables.", e)
print(f"Could not use environment user and password variables-> {e}")
db_user = "user"
db_password = "passwd"
db_name = "bd"
Expand Down Expand Up @@ -65,7 +65,7 @@
ky = environ['API_KEY']
sct= environ['API_SECRET']
except Exception as e:
print("Could not use environment variables for key and secret.", e)
print(f"Could not use environment variables for key and secret->{e}")
#pass

# Add API Key and API Secret as variables if needed.
Expand Down

0 comments on commit d30a12c

Please sign in to comment.