pybottrader.strategies API documentation

# pybottrader.strategies

# Strategies

A strategy model, so the user of this library can implement it owns strategies (this is the purpose of this library). A strategy is built to consume a data stream, compute indicators, and produce BUY/SELL signals.

View Source

     1"""
     2# Strategies
     3
     4A strategy model, so the user of this library can implement it owns strategies
     5(this is the purpose of this library).  A strategy is built to consume a data
     6stream, compute indicators, and produce BUY/SELL signals.
     7
     8"""
     9
    10from typing import Union
    11from enum import Enum
    12from datetime import datetime
    13from attrs import define
    14
    15
    16class Position(Enum):
    17    """Trading Positions"""
    18
    19    STAY = 1
    20    BUY = 2
    21    SELL = 3
    22
    23
    24@define
    25class StrategySignal:
    26    """To report computations of an strategy"""
    27
    28    time: datetime = datetime.now()
    29    position: Position = Position.STAY
    30    price: float = 0.0
    31    ticker: str = ""
    32    exchange: str = ""
    33
    34
    35class Strategy:
    36    """Base class for strategies"""
    37
    38    def __init__(self, *args, **kwargs):
    39        """
    40        Init Method. Included for future support.
    41        """
    42
    43    def evaluate(self, data: Union[dict, None]) -> StrategySignal:
    44        """
    45        Evaluate method. Include for future support
    46        """
    47        # The default position is STAY
    48        return StrategySignal()

class Position(enum.Enum): View Source

    17class Position(Enum):
    18    """Trading Positions"""
    19
    20    STAY = 1
    21    BUY = 2
    22    SELL = 3

Trading Positions

STAY = <Position.STAY: 1>
BUY = <Position.BUY: 2>
SELL = <Position.SELL: 3>
@define
class StrategySignal: View Source

    25@define
    26class StrategySignal:
    27    """To report computations of an strategy"""
    28
    29    time: datetime = datetime.now()
    30    position: Position = Position.STAY
    31    price: float = 0.0
    32    ticker: str = ""
    33    exchange: str = ""

To report computations of an strategy

StrategySignal( time: datetime.datetime = datetime.datetime(2024, 12, 21, 9, 21, 19, 698119), position: Position = <Position.STAY: 1>, price: float = 0.0, ticker: str = '', exchange: str = '') View Source

    2def __init__(self, time=attr_dict['time'].default, position=attr_dict['position'].default, price=attr_dict['price'].default, ticker=attr_dict['ticker'].default, exchange=attr_dict['exchange'].default):
    3    self.time = time
    4    self.position = position
    5    self.price = price
    6    self.ticker = ticker
    7    self.exchange = exchange

Method generated by attrs for class StrategySignal.

time: datetime.datetime
position: Position
price: float
ticker: str
exchange: str
class Strategy: View Source

    36class Strategy:
    37    """Base class for strategies"""
    38
    39    def __init__(self, *args, **kwargs):
    40        """
    41        Init Method. Included for future support.
    42        """
    43
    44    def evaluate(self, data: Union[dict, None]) -> StrategySignal:
    45        """
    46        Evaluate method. Include for future support
    47        """
    48        # The default position is STAY
    49        return StrategySignal()

Base class for strategies

Strategy(*args, **kwargs) View Source

    39    def __init__(self, *args, **kwargs):
    40        """
    41        Init Method. Included for future support.
    42        """

Init Method. Included for future support.

def evaluate(self, data: Optional[dict]) -> StrategySignal: View Source

    44    def evaluate(self, data: Union[dict, None]) -> StrategySignal:
    45        """
    46        Evaluate method. Include for future support
    47        """
    48        # The default position is STAY
    49        return StrategySignal()

Evaluate method. Include for future support