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.
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):
Trading Positions
STAY =
<Position.STAY: 1>
BUY =
<Position.BUY: 2>
SELL =
<Position.SELL: 3>
@define
class
StrategySignal:
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 = '')
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.
position: Position
class
Strategy:
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