diff --git a/auto_trading/orders.py b/auto_trading/orders.py index 69c354b..77ee437 100644 --- a/auto_trading/orders.py +++ b/auto_trading/orders.py @@ -3,14 +3,14 @@ from dataclasses import dataclass from .interfaces import Order - @dataclass class Long(Order): """Buy stock.""" stock: str amount: float - price: float + price:float + @property def amount_usd(self) -> float: diff --git a/auto_trading/ptf/in_memory.py b/auto_trading/ptf/in_memory.py index 36f7b43..bee335b 100644 --- a/auto_trading/ptf/in_memory.py +++ b/auto_trading/ptf/in_memory.py @@ -43,12 +43,14 @@ class InMemoryPortfolio(PTF): def execute_long(self, order: Long) -> None: """Buy actions.""" - if self.balance < order.amount * order.price: + SPREAD=1.0001 + PRICE = order.price * SPREAD + if self.balance < order.amount * PRICE: raise OrderFails("Not enough money.") - if self.change_rate.get(order.stock, 0) > order.price: + if self.change_rate.get(order.stock, 0) > PRICE: raise OrderFails("You buy it too low.") - self._balance -= order.price * order.amount + self._balance -= PRICE * order.amount self._stocks[order.stock] = order.amount + self._stocks.get(order.stock, 0) executors = {Short: execute_short, Long: execute_long} diff --git a/main.py b/main.py index 75bd8fc..fca37c6 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ if __name__ == "__main__": ) #strategy = Hold("GOOGL", {"dumb": Dumb(bt.data.close)}) - strategy = BuyUpSellDown("GOOGL", {"slopy": Slopy()}) + strategy = BuyUpSellDown("GOOG", {"slopy": Slopy()}) bot = Bot(ptf, strategy, bt)