-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
432 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from typing import Literal | ||
|
||
from algotrader.entities.attachments.technicals import IndicatorValue | ||
from algotrader.entities.generic_candle_attachment import GenericCandleAttachment | ||
|
||
|
||
class AssetCorrelation(GenericCandleAttachment[IndicatorValue]): | ||
type: Literal["AssetCorrelation"] = "AssetCorrelation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal | ||
|
||
from pydantic import Field | ||
|
||
from algotrader.entities.base_dto import BaseEntity | ||
|
||
|
||
class NothingClass(BaseEntity): | ||
type: Literal["NothingClass"] = "NothingClass" | ||
nothing: str = Field(default="nothing-at-all") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal | ||
|
||
from algotrader.entities.generic_candle_attachment import GenericCandleAttachment | ||
|
||
|
||
class Returns(GenericCandleAttachment[float]): | ||
type: Literal["Returns"] = "Returns" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal, Union, List | ||
|
||
from algotrader.entities.generic_candle_attachment import GenericCandleAttachment | ||
|
||
IndicatorValue = Union[List[float], float] | ||
|
||
|
||
class Indicators(GenericCandleAttachment[IndicatorValue]): | ||
type: Literal["Indicators"] = "Indicators" |
8 changes: 8 additions & 0 deletions
8
src/algotrader/entities/attachments/technicals_buckets_matcher.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from typing import Union, List, Literal | ||
|
||
from algotrader.entities.bucket import Bucket | ||
from algotrader.entities.generic_candle_attachment import GenericCandleAttachment | ||
|
||
|
||
class IndicatorsMatchedBuckets(GenericCandleAttachment[Union[List[Bucket], Bucket]]): | ||
type: Literal["IndicatorsMatchedBuckets"] = "IndicatorsMatchedBuckets" |
10 changes: 10 additions & 0 deletions
10
src/algotrader/entities/attachments/technicals_normalizer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal | ||
|
||
from algotrader.entities.attachments.technicals import IndicatorValue | ||
from algotrader.entities.generic_candle_attachment import GenericCandleAttachment | ||
|
||
|
||
class NormalizedIndicators(GenericCandleAttachment[IndicatorValue]): | ||
type: Literal["NormalizedIndicators"] = "NormalizedIndicators" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from datetime import datetime | ||
from typing import ClassVar | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class BaseEntity(BaseModel): | ||
_types: ClassVar[dict[str, type]] = {} | ||
|
||
created_at: datetime = Field(default_factory=datetime.utcnow) | ||
updated_at: datetime = Field(default_factory=datetime.utcnow) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Dict, List, Union | ||
import math | ||
from typing import List, Union, Optional | ||
|
||
from algotrader.entities.serializable import Serializable, Deserializable | ||
from pydantic import Field | ||
|
||
from algotrader.entities.base_dto import BaseEntity | ||
|
||
class Bucket(Serializable, Deserializable): | ||
def __init__(self, ident: int, start: float = float("-inf"), end: float = float("inf")) -> None: | ||
super().__init__() | ||
self.ident = ident | ||
self.start = start | ||
self.end = end | ||
|
||
@classmethod | ||
def deserialize(cls, data: Dict) -> Bucket: | ||
return Bucket(data["ident"], data["start"], data["end"]) | ||
class Bucket(BaseEntity): | ||
ident: float | ||
start: Optional[float] = Field(default=-math.inf) | ||
end: Optional[float] = Field(default=math.inf) | ||
|
||
def serialize(self) -> Dict: | ||
obj = super().serialize() | ||
obj.update({"ident": self.ident, "start": self.start, "end": self.end}) | ||
@property | ||
def get_start(self): | ||
return self.start or -math.inf | ||
|
||
return obj | ||
@property | ||
def get_end(self): | ||
return self.end or math.inf | ||
|
||
|
||
BucketList = List[Bucket] | ||
CompoundBucketList = Union[List[BucketList], BucketList] | ||
|
||
Bucket(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Dict, TypeVar, Generic, Optional, ItemsView, Union | ||
from typing import Dict, TypeVar, Generic, Optional, ItemsView | ||
|
||
from algotrader.entities.serializable import Serializable, Deserializable | ||
from pydantic import Field | ||
|
||
from algotrader.entities.base_dto import BaseEntity | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class GenericCandleAttachment(Generic[T], Serializable, Deserializable): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
self._data: Dict[str, T] = {} | ||
class GenericCandleAttachment(Generic[T], BaseEntity): | ||
data: Dict[str, T] = Field(default_factory=dict) | ||
|
||
def __getitem__(self, key): | ||
return self._data[key] | ||
return self.data[key] | ||
|
||
def set(self, key: str, value: T): | ||
self._data[key] = value | ||
self.data[key] = value | ||
|
||
def get(self, key: str) -> Optional[T]: | ||
return self._data[key] | ||
return self.data[key] | ||
|
||
def items(self) -> ItemsView[str, T]: | ||
data = {} | ||
for k, v in self._data.items(): | ||
for k, v in self.data.items(): | ||
if k == "__class__": | ||
continue | ||
data.update({k: v}) | ||
|
||
return data.items() | ||
|
||
@classmethod | ||
def deserialize(cls, data: Dict) -> GenericCandleAttachment: | ||
obj = GenericCandleAttachment() | ||
obj._data = data | ||
return obj | ||
|
||
def serialize(self) -> Dict: | ||
obj = super().serialize() | ||
for k, v in self._data.items(): | ||
if v: | ||
if isinstance(v, list): | ||
obj[k] = [self._serialized_value(x) for x in v] | ||
else: | ||
obj[k] = self._serialized_value(v) | ||
|
||
return obj | ||
|
||
@staticmethod | ||
def _serialized_value(value: Union[any, Serializable]): | ||
return value.serialize() if isinstance(value, Serializable) else value | ||
|
||
def has(self, key: str): | ||
return key in self._data and self._data[key] is not None | ||
return key in self.data and self.data[key] is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.