-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't use DEFAULT_CANDLES if Hexital.timeframe is given #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ class Hexital: | |
candle_life: Optional[timedelta] = None | ||
candlestick: Optional[CandlestickType] = None | ||
|
||
default_tf: str = DEFAULT_CANDLES | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this a private attribute and rename it -> This is because it's just |
||
|
||
def __init__( | ||
self, | ||
name: str, | ||
|
@@ -53,16 +55,19 @@ def __init__( | |
if candlestick: | ||
self.candlestick = validate_candlesticktype(candlestick) | ||
|
||
if self._timeframe is not None: | ||
self.default_tf = self.timeframe | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think this is correct, self._timeframe_name = timedelta_to_str(self._timeframe) |
||
|
||
self._candles = { | ||
DEFAULT_CANDLES: CandleManager( | ||
self.default_tf: CandleManager( | ||
candles if isinstance(candles, list) else [], | ||
candle_life=self.candle_life, | ||
timeframe=self._timeframe, | ||
timeframe_fill=self.timeframe_fill, | ||
candlestick=self.candlestick, | ||
) | ||
} | ||
self._candles[DEFAULT_CANDLES].name = DEFAULT_CANDLES | ||
self._candles[self.default_tf].name = self.default_tf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we need this line at all, not your fault of course. |
||
|
||
self._indicators = self._validate_indicators(indicators) if indicators else {} | ||
|
||
|
@@ -92,7 +97,7 @@ def has_reading(self, name: str) -> bool: | |
|
||
def candles(self, name: Optional[str | TimeFrame | timedelta | int] = None) -> List[Candle]: | ||
"""Get a set of candles by using either a Timeframe or Indicator name""" | ||
name_ = name if name else DEFAULT_CANDLES | ||
name_ = name if name else self.default_tf | ||
timeframe_name = self._parse_timeframe(name) | ||
|
||
name_ = timeframe_name if timeframe_name else name_ | ||
|
@@ -118,7 +123,7 @@ def reading(self, name: str, index: int = -1) -> float | dict | None: | |
"""Attempts to retrieve a reading with a given Indicator name. | ||
`name` can use '.' to find nested reading, E.G `MACD_12_26_9.MACD` | ||
""" | ||
reading = reading_by_index(self._candles[DEFAULT_CANDLES].candles, name, index=index) | ||
reading = reading_by_index(self._candles[self.default_tf].candles, name, index=index) | ||
|
||
if reading is not None: | ||
return reading | ||
|
@@ -240,7 +245,7 @@ def _validate_indicators(self, indicators: List[dict | Indicator]) -> Dict[str, | |
|
||
for indicator in valid_indicators.values(): | ||
if not indicator.timeframe: | ||
indicator.candle_manager = self._candles[DEFAULT_CANDLES] | ||
indicator.candle_manager = self._candles[self.default_tf] | ||
elif indicator.timeframe and indicator.timeframe in self._candles: | ||
indicator.candle_manager = self._candles[indicator.timeframe] | ||
else: | ||
|
@@ -251,7 +256,7 @@ def _validate_indicators(self, indicators: List[dict | Indicator]) -> Dict[str, | |
timeframe_fill=self.timeframe_fill, | ||
candlestick=self.candlestick, | ||
) | ||
manager.append(self._candles[DEFAULT_CANDLES].candles) | ||
manager.append(self._candles[self.default_tf].candles) | ||
self._candles[manager.name] = manager | ||
indicator.candle_manager = self._candles[manager.name] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property
Can just be updated now: