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