Browse Source

feat: ther is no strat

pull/14/head
QuentinN42 1 year ago
parent
commit
8075571674
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 4
      auto_trading/interfaces.py
  2. 3
      auto_trading/main.py
  3. 0
      auto_trading/strat/__init__.py
  4. 21
      auto_trading/strat/all_in.py

4
auto_trading/interfaces.py

@ -28,7 +28,7 @@ class Strategy(ABC):
"""When do I buy and how many ?"""
@abstractmethod
def run(self, result: dict, ptf: Portfolio) -> None:
def run(self, ptf: Portfolio, result: dict, current_conversion_rate: dict) -> None:
"""Run the strategy"""
@ -40,7 +40,7 @@ class Broker(ABC):
"""Return True if the broker has data to retrive"""
@abstractmethod
def next(self):
def next(self) -> dict:
"""Return the next data to process"""

3
auto_trading/main.py

@ -22,7 +22,8 @@ class Bot:
def run_once(self):
"""run the bot once"""
self.strategy.run(self.predictor.predict(self.broker.next()), self.ptf)
data = self.broker.next()
self.strategy.run(self.ptf, self.predictor.predict(data), data)
def print_results(self):
"""print the results"""

0
auto_trading/strat/__init__.py

21
auto_trading/strat/all_in.py

@ -0,0 +1,21 @@
from ..interfaces import Strategy, Portfolio
class AllIn(Strategy):
"""Just all in the greatest result"""
def __init__(self):
"""Initialise the anti strat"""
def run(self, ptf: Portfolio, result: dict, current_conversion_rate: dict) -> None:
"""Run the strategy"""
# first sell all the stocks
money = 0
for stock, amount in filter(lambda kv: kv[1], ptf.content().items()):
money += current_conversion_rate[stock]*amount
ptf.widraw(stock, amount)
# after get the greatest result
greatest = max(result, key=lambda k: result[k])
# then buy all the greatest result
ptf.deposit(amount/current_conversion_rate[greatest], greatest)
Loading…
Cancel
Save