-
Notifications
You must be signed in to change notification settings - Fork 7
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
17 changed files
with
175 additions
and
76 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
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,24 @@ | ||
from loguru import logger | ||
|
||
|
||
class ComponentManager: | ||
|
||
_components = [] | ||
|
||
@classmethod | ||
def register(cls, component): | ||
if component in cls._components: | ||
return | ||
cls._components.append(component) | ||
logger.debug(f'Registered component {component} ({component.__module__})') | ||
|
||
@classmethod | ||
def all(cls): | ||
return [o() for o in cls._components] | ||
|
||
@classmethod | ||
def get(cls, name): | ||
for component in cls._components: | ||
if component.__name__ == name: | ||
return component() | ||
raise ValueError(f'Component {name} not found.') |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from components.ohlc import CSVAdapter | ||
from components.ohlc.data_adapters.api_adapter import APIDataAdapter | ||
|
||
# add any custom data adapters here | ||
DATA_ADAPTERS = [ | ||
CSVAdapter, | ||
APIDataAdapter | ||
] |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from datetime import datetime | ||
|
||
from components.orders.order import Order, OrderSide as Side, OrderType | ||
|
||
|
||
class TestOrders: | ||
def test_hashing(self): | ||
ts = datetime.now().timestamp() | ||
fake_order_1 = Order( | ||
symbol='BTCUSDT', | ||
side=Side.BUY, | ||
type=OrderType.MARKET, | ||
qty=1, | ||
timestamp=ts, | ||
) | ||
fake_order_2 = Order( | ||
symbol='BTCUSDT', | ||
side=Side.BUY, | ||
type=OrderType.MARKET, | ||
qty=1, | ||
timestamp=ts, | ||
) | ||
assert fake_order_1 == fake_order_2 | ||
|
||
fake_order_3 = Order( | ||
symbol='BTCUSDT', | ||
side=Side.BUY, | ||
type=OrderType.MARKET, | ||
qty=2, | ||
datetime=ts, | ||
) | ||
|
||
assert fake_order_1 != fake_order_3 | ||
|
||
# test IDs | ||
assert fake_order_1.get_id() == fake_order_2.get_id() | ||
assert fake_order_1.get_id() != fake_order_3.get_id() |
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,36 @@ | ||
import inspect | ||
from pathlib import Path | ||
from importlib import import_module | ||
|
||
from loguru import logger | ||
|
||
from components.ohlc import DataAdapter | ||
from components.strategy.strategy import BaseStrategy | ||
|
||
|
||
def import_components(path, component_type): | ||
logger.debug(f'Importing {component_type.__name__}(s) from {path}...') | ||
components = [] | ||
app_path = Path(__file__).parent.parent.parent | ||
paths = app_path.joinpath(path).rglob('*.py') | ||
for path in paths: | ||
module_name = path.as_posix().replace('/', '.').replace('.py', '').split('app.')[1] | ||
module = import_module(module_name) | ||
|
||
for name, obj in inspect.getmembers(module): | ||
if inspect.isclass(obj) and issubclass(obj, component_type): | ||
if obj.__name__ != component_type.__name__: | ||
components.append(obj) | ||
logger.info(f'\t->\t{obj.__name__} ({obj.__module__})') | ||
return components | ||
|
||
# load all components | ||
data_adapters = import_components('components/ohlc/data_adapters', DataAdapter) | ||
strategies = import_components('storage/strategies', BaseStrategy) | ||
|
||
# register all components | ||
for adapter in data_adapters: | ||
adapter.register() | ||
|
||
for strategy in strategies: | ||
strategy.register() |
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.