Browse Source

début spread

thibaudlabat-spread
thibaudlabat 10 months ago
parent
commit
1728727be9
  1. 4
      auto_trading/orders.py
  2. 8
      auto_trading/ptf/in_memory.py
  3. 2
      main.py

4
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:

8
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}

2
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)

Loading…
Cancel
Save