Browse Source

feat(wip): start indicators draw

Signed-off-by: QuentinN42 <quentin@lieumont.fr>
indic-draw
QuentinN42 6 months ago
parent
commit
362555e9be
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 44
      auto_trading/indicators_draw.py

44
auto_trading/indicators_draw.py

@ -0,0 +1,44 @@
"""Draw all indicators on a graph.
https://git.rezel.net/TBF/AutoTrading/pulls/22
"""
import logging
from typing import Dict, Tuple
from pandas import DataFrame, Series # type: ignore
from auto_trading.interfaces import DataBroker, Indicator
class IndicDraw:
"""Plot indicators"""
def __init__(
self,
broker: DataBroker,
on_price_indicators: Dict[str, Indicator],
others_indicators: Dict[str, Indicator],
):
"""Initialize the bot."""
self.logger = logging.getLogger(self.__class__.__name__)
self.broker = broker
self.on_price_indicators = on_price_indicators
self.others_indicators = others_indicators
def run(self):
"""run the bot"""
for data in self.broker:
self.run_once(data)
def run_once(self, data: DataFrame) -> Tuple[Series, Series]:
"""run the bot once"""
on_price_indicators_results = DataFrame(
{k: v(data) for k, v in self.on_price_indicators.items()}
).T
others_indicators_results = DataFrame(
{k: v(data) for k, v in self.others_indicators.items()}
).T
return (
on_price_indicators_results,
others_indicators_results
)
Loading…
Cancel
Save