diff --git a/bot.py b/bot.py index 4650b4a..ca57f65 100644 --- a/bot.py +++ b/bot.py @@ -1,17 +1,18 @@ from abc import ABC, abstractmethod -from model import Model -from position import Position +from .model import Model +from .position import Position class Bot(ABC): - def __init__(self, model: Model, nolog=False): + def __init__(self, model: Model, config: dict, nolog=False): self.previous_obs = None self.positions = list() self.num_open_pos = 0 self.nUnits_available = 0 # the number of tokens in the denominating unit that the bot can work with self.model = model self.nolog = nolog + self.config = config def update_num_open_pos(self): self.num_open_pos = 0 @@ -50,7 +51,7 @@ for p in self.positions: if p.open: p.set_position_closed(current_price=current_price) - self.nUnits += p.nUnits + self.nUnits_available += p.nUnits def log_msg(self, msg): """ write message to log """ diff --git a/model.py b/model.py index d80bc05..a42f277 100644 --- a/model.py +++ b/model.py @@ -3,6 +3,9 @@ class Model(ABC): + def __init__(self, config: dict): + self.config = config + @abstractmethod def plot_model(self): pass diff --git a/position.py b/position.py index 508c9a5..3bb48c2 100644 --- a/position.py +++ b/position.py @@ -15,7 +15,7 @@ self.performance = 0 self.nolog = nolog - def set_position_open(self, nUnits, current_price, current_reg_fun_vals: list): + def set_position_open(self, nUnits, current_price): self.open = True self.ts_opened = datetime.datetime.now() self.opened_at_price = current_price @@ -23,7 +23,6 @@ self.log_msg(self.to_str() + "| Position opened. nUnits: " + str(round(self.nUnits, 4)) + " opened at price: " + str(round(self.opened_at_price, 4))) - self.set_tp_io(current_price, current_reg_fun_vals) def set_position_closed(self, current_price): self.ts_closed = datetime.datetime.now() @@ -31,6 +30,9 @@ self.nUnits = self.nUnits * self.closed_at_price/self.opened_at_price * (1-self.fee) self.performance = (current_price/self.opened_at_price - 1) * 100 self.open = False + self.log_msg(self.to_str() + + "| Position closed. nUnits: " + str(round(self.nUnits, 4)) + + " closed at price: " + str(round(self.closed_at_price, 4))) @abstractmethod def update_position(self):