minor cleanup
This commit is contained in:
parent
3277392b8b
commit
6db7c2fc15
16
bfxbot.py
16
bfxbot.py
@ -5,7 +5,6 @@ import inspect
|
|||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from os import system
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ from playsound import playsound
|
|||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
||||||
|
|
||||||
class Ticker():
|
class Ticker:
|
||||||
def __init__(self, sec) -> None:
|
def __init__(self, sec) -> None:
|
||||||
self.seconds: int = sec
|
self.seconds: int = sec
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
@ -39,7 +38,7 @@ class EventKind(Enum):
|
|||||||
ORDER_SUBMITTED = 11,
|
ORDER_SUBMITTED = 11,
|
||||||
|
|
||||||
|
|
||||||
class Event():
|
class Event:
|
||||||
def __init__(self, kind: EventKind, tick: int) -> None:
|
def __init__(self, kind: EventKind, tick: int) -> None:
|
||||||
self.kind: EventKind = kind
|
self.kind: EventKind = kind
|
||||||
self.tick: int = tick
|
self.tick: int = tick
|
||||||
@ -64,7 +63,7 @@ class State(Enum):
|
|||||||
return "green"
|
return "green"
|
||||||
|
|
||||||
|
|
||||||
class Printer():
|
class Printer:
|
||||||
def __init__(self, screen: Screen):
|
def __init__(self, screen: Screen):
|
||||||
self.screen: Screen = screen
|
self.screen: Screen = screen
|
||||||
self.current_line: int = 0
|
self.current_line: int = 0
|
||||||
@ -96,7 +95,7 @@ class Printer():
|
|||||||
(self.current_width, self.current_height) = shutil.get_terminal_size()
|
(self.current_width, self.current_height) = shutil.get_terminal_size()
|
||||||
|
|
||||||
|
|
||||||
class Status():
|
class Status:
|
||||||
def __init__(self, tick_duration, symbol, printer):
|
def __init__(self, tick_duration, symbol, printer):
|
||||||
self.ticker: Ticker = Ticker(tick_duration)
|
self.ticker: Ticker = Ticker(tick_duration)
|
||||||
self.events: List[Event] = []
|
self.events: List[Event] = []
|
||||||
@ -243,6 +242,7 @@ def on_min_profit(event: Event, status: Status):
|
|||||||
def on_critical(event: Event, status: Status):
|
def on_critical(event: Event, status: Status):
|
||||||
playsound("sounds/gameover.mp3")
|
playsound("sounds/gameover.mp3")
|
||||||
|
|
||||||
|
|
||||||
@eh.on_state(State.MINIMUM_PROFIT)
|
@eh.on_state(State.MINIMUM_PROFIT)
|
||||||
def on_state_min_profit(status: Status):
|
def on_state_min_profit(status: Status):
|
||||||
update_stop_percentage(State.MINIMUM_PROFIT, status)
|
update_stop_percentage(State.MINIMUM_PROFIT, status)
|
||||||
@ -304,11 +304,13 @@ async def on_close_position(event: Event, status: Status):
|
|||||||
await bfx.submit_order(status.symbol, closing_price, amount, Order.Type.LIMIT)
|
await bfx.submit_order(status.symbol, closing_price, amount, Order.Type.LIMIT)
|
||||||
await status.add_event(Event(EventKind.ORDER_SUBMITTED, status.get_current_tick()))
|
await status.add_event(Event(EventKind.ORDER_SUBMITTED, status.get_current_tick()))
|
||||||
|
|
||||||
|
|
||||||
@eh.on_event(EventKind.ORDER_SUBMITTED)
|
@eh.on_event(EventKind.ORDER_SUBMITTED)
|
||||||
def on_order_submitted(event: Event, status: Status):
|
def on_order_submitted(event: Event, status: Status):
|
||||||
status.printer.print_next_line("ORDER SUBMITTED!")
|
status.printer.print_next_line("ORDER SUBMITTED!")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def calculate_best_closing_price(status: Status):
|
async def calculate_best_closing_price(status: Status):
|
||||||
p: Position = status.last_position()
|
p: Position = status.last_position()
|
||||||
|
|
||||||
@ -479,9 +481,5 @@ async def get_usd_balance():
|
|||||||
return balance
|
return balance
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
|
||||||
system("clear")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(Screen.wrapper(main))
|
asyncio.run(Screen.wrapper(main))
|
||||||
|
Loading…
Reference in New Issue
Block a user