new sounds

This commit is contained in:
Giulio De Pasquale 2020-11-28 15:10:02 +00:00
parent aa4db10d5b
commit fb1433a13d
3 changed files with 44 additions and 20 deletions

64
main.py
View File

@ -2,6 +2,7 @@
import asyncio
from asyncio import events
from hashlib import blake2b
import time
from enum import Enum
from os import system, terminal_size
@ -124,24 +125,25 @@ class Status():
return await get_current_price(self.symbol)
self.ticks[self.get_current_tick()]
def set_state(self, state: State):
def set_state(self, state: State, position: Position):
if self.current_state != state:
event: EventKind = None
if state == State.CRITICAL:
event = Event(EventKind.REACHED_MAX_LOSS,
self.get_current_tick())
self.get_current_tick(), position)
elif state == State.LOSS:
event = Event(EventKind.REACHED_LOSS, self.get_current_tick())
event = Event(EventKind.REACHED_LOSS,
self.get_current_tick(), position)
elif state == State.BREAK_EVEN:
event = Event(EventKind.REACHED_BREAK_EVEN,
self.get_current_tick())
self.get_current_tick(), position)
elif state == State.MINIMUM_PROFIT:
event = Event(EventKind.REACHED_MIN_PROFIT,
self.get_current_tick())
self.get_current_tick(), position)
elif state == State.PROFIT:
event = Event(EventKind.REACHED_GOOD_PROFIT,
self.get_current_tick())
self.get_current_tick(), position)
self.events.append(event)
eh.call(event, self)
@ -216,7 +218,12 @@ def on_min_profit(event: Event, status: Status):
if status.stop_percentage < pos_pl_perc:
status.printer.print_next_line("I WOULD SELL NOW!")
else:
playsound("sounds/letsgo.mp3")
playsound("sounds/1up.mp3")
@eh.on_event(EventKind.REACHED_MAX_LOSS)
def on_critical(event: Event, status: Status):
playsound("sounds/gameover.mp3")
def net_pl_percentage(perc: float, reference_fee_perc: float):
@ -230,6 +237,7 @@ async def main(screen: Screen):
printer = Printer(screen)
status = Status(20, symbol, printer)
balance = await get_usd_balance()
while True:
positions = [p for p in await bfx.get_active_position() if p.symbol == status.symbol]
@ -238,12 +246,13 @@ async def main(screen: Screen):
last_price = await status.last_price()
screen.clear()
printer.print_next_line("Current {} price: {} | Current tick ({} sec): {}".format(symbol,
colored_float(
last_price, "white", attrs=["bold"]),
status.ticker.seconds,
status.get_current_tick(),
))
printer.print_next_line("Balance: ${} | Current {} price: {} | Current tick ({} sec): {}".format(colored_float(balance, "white"),
symbol,
colored_float(
last_price, "white", attrs=["bold"]),
status.ticker.seconds,
status.get_current_tick(),
))
if positions:
printer.print_next_line("")
@ -255,15 +264,15 @@ async def main(screen: Screen):
p.profit_loss_percentage, TAKER_FEE)
if plfees_percentage > GOOD_PROFIT_PERC:
status.set_state(State.PROFIT)
status.set_state(State.PROFIT, p)
elif plfees_percentage >= MIN_PROFIT_PERC and plfees_percentage < GOOD_PROFIT_PERC:
status.set_state(State.MINIMUM_PROFIT)
status.set_state(State.MINIMUM_PROFIT, p)
elif plfees_percentage >= 0.0 and plfees_percentage < MIN_PROFIT_PERC:
status.set_state(State.BREAK_EVEN)
status.set_state(State.BREAK_EVEN, p)
elif plfees_percentage < 0.0 and plfees_percentage > MAX_LOSS_PERC:
status.set_state(State.LOSS)
status.set_state(State.LOSS, p)
else:
status.set_state(State.CRITICAL)
status.set_state(State.CRITICAL, p)
status_color = status.get_current_state().color()
@ -273,11 +282,11 @@ async def main(screen: Screen):
if plfees_percentage > max_perc:
max_perc = plfees_percentage
status.add_event(Event(EventKind.NEW_MAXIMUM,
status.get_current_tick()))
status.get_current_tick(), p))
if plfees_percentage < min_perc:
min_perc = plfees_percentage
status.add_event(Event(EventKind.NEW_MINIMUM,
status.get_current_tick()))
status.get_current_tick(), p))
min_perc_colored = colored_percentage(
min_perc, "red") if min_perc < 0.0 else colored_percentage(min_perc, "green")
@ -349,6 +358,21 @@ async def get_current_price(symbol):
return tickers[6]
async def get_usd_balance():
balance = 0.0
wallets = await bfx.get_wallets()
for w in wallets:
if w.currency == "USD":
balance += w.balance
else:
current_price = await get_current_price(f"t{w.currency}USD")
balance += current_price * w.balance
return balance
def clear():
system("clear")

Binary file not shown.

Binary file not shown.