calling event handlers on add_event
This commit is contained in:
parent
04c5279826
commit
d3208835e2
24
main.py
24
main.py
@ -125,6 +125,7 @@ class Status():
|
|||||||
|
|
||||||
def add_event(self, event: Event):
|
def add_event(self, event: Event):
|
||||||
self.events.append(event)
|
self.events.append(event)
|
||||||
|
eh.call_event(event, self)
|
||||||
|
|
||||||
async def last_price(self) -> float:
|
async def last_price(self) -> float:
|
||||||
if self.get_current_tick() not in self.ticks.keys():
|
if self.get_current_tick() not in self.ticks.keys():
|
||||||
@ -224,23 +225,11 @@ TRAIL_STOP_PERCENTAGES = {
|
|||||||
|
|
||||||
@eh.on_event(EventKind.REACHED_GOOD_PROFIT)
|
@eh.on_event(EventKind.REACHED_GOOD_PROFIT)
|
||||||
def on_good_profit(event: Event, status: Status):
|
def on_good_profit(event: Event, status: Status):
|
||||||
pos_pl_perc = net_pl_percentage(
|
|
||||||
event.position.profit_loss_percentage, TAKER_FEE)
|
|
||||||
|
|
||||||
if status.stop_percentage < pos_pl_perc:
|
|
||||||
status.printer.print_next_line("I WOULD SELL NOW!")
|
|
||||||
else:
|
|
||||||
playsound("sounds/coin.mp3")
|
playsound("sounds/coin.mp3")
|
||||||
|
|
||||||
|
|
||||||
@eh.on_event(EventKind.REACHED_MIN_PROFIT)
|
@eh.on_event(EventKind.REACHED_MIN_PROFIT)
|
||||||
def on_min_profit(event: Event, status: Status):
|
def on_min_profit(event: Event, status: Status):
|
||||||
pos_pl_perc = net_pl_percentage(
|
|
||||||
event.position.profit_loss_percentage, TAKER_FEE)
|
|
||||||
|
|
||||||
if status.stop_percentage < pos_pl_perc:
|
|
||||||
status.printer.print_next_line("I WOULD SELL NOW!")
|
|
||||||
else:
|
|
||||||
playsound("sounds/1up.mp3")
|
playsound("sounds/1up.mp3")
|
||||||
|
|
||||||
|
|
||||||
@ -286,20 +275,27 @@ def update_stop_percentage(state: State, status: Status):
|
|||||||
|
|
||||||
# set stop percentage for first time
|
# set stop percentage for first time
|
||||||
if not status.stop_percentage:
|
if not status.stop_percentage:
|
||||||
status.add_event(Event(EventKind.TRAILING_STOP_SET, status.get_current_tick()))
|
status.add_event(Event(EventKind.TRAILING_STOP_SET,
|
||||||
|
status.get_current_tick()))
|
||||||
status.stop_percentage = last_pl_net_perc - \
|
status.stop_percentage = last_pl_net_perc - \
|
||||||
TRAIL_STOP_PERCENTAGES[state]
|
TRAIL_STOP_PERCENTAGES[state]
|
||||||
return
|
return
|
||||||
|
|
||||||
# moving trailing stop
|
# moving trailing stop
|
||||||
if last_pl_net_perc - TRAIL_STOP_PERCENTAGES[state] > status.stop_percentage:
|
if last_pl_net_perc - TRAIL_STOP_PERCENTAGES[state] > status.stop_percentage:
|
||||||
status.add_event(Event(EventKind.TRAILING_STOP_MOVED, status.get_current_tick()))
|
status.add_event(Event(EventKind.TRAILING_STOP_MOVED,
|
||||||
|
status.get_current_tick()))
|
||||||
status.stop_percentage = last_pl_net_perc - \
|
status.stop_percentage = last_pl_net_perc - \
|
||||||
TRAIL_STOP_PERCENTAGES[state]
|
TRAIL_STOP_PERCENTAGES[state]
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@eh.on_event(EventKind.CLOSE_POSITION)
|
||||||
|
def on_close_position(event: Event, status: Status):
|
||||||
|
status.printer.print_next_line("I WOULD HAVE CLOSED THE POSITION HERE"*100)
|
||||||
|
|
||||||
|
|
||||||
def net_pl_percentage(perc: float, reference_fee_perc: float):
|
def net_pl_percentage(perc: float, reference_fee_perc: float):
|
||||||
return perc - reference_fee_perc
|
return perc - reference_fee_perc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user