renamed main to bfxbox. minor cleanup
This commit is contained in:
parent
07eba48250
commit
ffdfd6fb9c
44
main.py → bfxbot.py
Normal file → Executable file
44
main.py → bfxbot.py
Normal file → Executable file
@ -1,22 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import asyncio
|
||||
from asyncio import events
|
||||
from hashlib import blake2b
|
||||
import shutil
|
||||
import time
|
||||
from enum import Enum
|
||||
from os import system, terminal_size
|
||||
from os import system
|
||||
from time import sleep
|
||||
from bfxapi import Client
|
||||
from bfxapi.models.order import Order
|
||||
from bfxapi.models.position import Position
|
||||
from termcolor import colored
|
||||
import shutil
|
||||
import termplotlib
|
||||
import numpy
|
||||
from playsound import playsound
|
||||
from asciimatics.screen import ManagedScreen, Screen
|
||||
from typing import Dict, List
|
||||
|
||||
import dotenv
|
||||
import termplotlib
|
||||
from asciimatics.screen import Screen
|
||||
from bfxapi import Client
|
||||
from bfxapi.models.position import Position
|
||||
from playsound import playsound
|
||||
from termcolor import colored
|
||||
|
||||
|
||||
class Ticker():
|
||||
@ -100,9 +98,9 @@ class Printer():
|
||||
class Status():
|
||||
def __init__(self, tick_duration, symbol, printer):
|
||||
self.ticker: Ticker = Ticker(tick_duration)
|
||||
self.events: list[Event] = []
|
||||
self.events: List[Event] = []
|
||||
self.symbol = symbol
|
||||
self.ticks: dict[int, (float, Position)] = {}
|
||||
self.ticks: Dict[int, (float, Position)] = {}
|
||||
self.current_state: State = State.LOSS
|
||||
self.printer: Printer = printer
|
||||
self.stop_percentage: float = None
|
||||
@ -128,13 +126,11 @@ class Status():
|
||||
eh.call_event(event, self)
|
||||
|
||||
async def last_price(self) -> float:
|
||||
if self.get_current_tick() not in self.ticks.keys():
|
||||
return await get_current_price(self.symbol)
|
||||
self.ticks[self.get_current_tick()]
|
||||
|
||||
def set_state(self, state: State):
|
||||
if self.current_state != state:
|
||||
event: EventKind = None
|
||||
event: Event = None
|
||||
|
||||
if state == State.CRITICAL:
|
||||
event = Event(EventKind.REACHED_MAX_LOSS,
|
||||
@ -187,6 +183,7 @@ class EventHandler:
|
||||
else:
|
||||
self.event_handlers[value] = [handler]
|
||||
return handler
|
||||
|
||||
return registerhandler
|
||||
|
||||
def on_state(self, state: State):
|
||||
@ -196,6 +193,7 @@ class EventHandler:
|
||||
else:
|
||||
self.state_handlers[state] = [handler]
|
||||
return handler
|
||||
|
||||
return registerhandler
|
||||
|
||||
|
||||
@ -316,10 +314,12 @@ async def main(screen: Screen):
|
||||
current_price = await status.last_price()
|
||||
|
||||
screen.clear()
|
||||
printer.print_next_line("Balance: ${} | Current {} price: {} | Current tick ({} sec): {}".format(colored_float(balance, "white"),
|
||||
printer.print_next_line(
|
||||
"Balance: ${} | Current {} price: {} | Current tick ({} sec): {}".format(colored_float(balance, "white"),
|
||||
symbol,
|
||||
colored_float(
|
||||
current_price, "white", attrs=["bold"]),
|
||||
current_price, "white",
|
||||
attrs=["bold"]),
|
||||
status.ticker.seconds,
|
||||
status.get_current_tick(),
|
||||
))
|
||||
@ -337,11 +337,11 @@ async def main(screen: Screen):
|
||||
|
||||
if plfees_percentage > GOOD_PROFIT_PERC:
|
||||
status.set_state(State.PROFIT)
|
||||
elif plfees_percentage >= MIN_PROFIT_PERC and plfees_percentage < GOOD_PROFIT_PERC:
|
||||
elif MIN_PROFIT_PERC <= plfees_percentage < GOOD_PROFIT_PERC:
|
||||
status.set_state(State.MINIMUM_PROFIT)
|
||||
elif plfees_percentage >= 0.0 and plfees_percentage < MIN_PROFIT_PERC:
|
||||
elif 0.0 <= plfees_percentage < MIN_PROFIT_PERC:
|
||||
status.set_state(State.BREAK_EVEN)
|
||||
elif plfees_percentage < 0.0 and plfees_percentage > MAX_LOSS_PERC:
|
||||
elif MAX_LOSS_PERC < plfees_percentage < 0.0:
|
||||
status.set_state(State.LOSS)
|
||||
else:
|
||||
status.set_state(State.CRITICAL)
|
Loading…
Reference in New Issue
Block a user