Skip to content

Commit 996200c

Browse files
author
DUYN
committed
Remove bot.py reference
1 parent 6ade86c commit 996200c

File tree

6 files changed

+173
-105
lines changed

6 files changed

+173
-105
lines changed

bot/bot.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

bot/configuration/resolvers.py

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
from typing import Dict, Any, List
2+
3+
from bot.strategies import Strategy
4+
from bot.data import DataProvider
5+
from bot import DependencyException, OperationalException
6+
from bot.remote_loaders import StrategyRemoteLoader, DataProviderRemoteLoader
7+
8+
9+
def get_data_provider_configurations(config: Dict[str, Any]) -> List[Dict[str, Any]]:
10+
data_provider_configurations = config.get('data_providers', {})
11+
12+
entries = []
13+
14+
if not data_provider_configurations:
15+
raise DependencyException(
16+
"Could not resolve data providers, please provide the data provider configurations in your config file. "
17+
"You could also use de default data providers, that can be found in the data/data_provider/templates"
18+
" directory. If you have difficulties creating your own data provider, please see the documentation"
19+
)
20+
21+
for data_provider_entry in data_provider_configurations.keys():
22+
entry = {
23+
'key': data_provider_entry,
24+
'class_name': data_provider_configurations[data_provider_entry].get('class_name', None),
25+
'enabled': bool(data_provider_configurations[data_provider_entry].get('enabled', False)),
26+
'plugin': bool(data_provider_configurations[data_provider_entry].get('plugin', False))
27+
}
28+
entries.append(entry)
29+
30+
return entries
31+
32+
33+
def get_strategy_configurations(config: Dict[str, Any]) -> List[Dict[str, Any]]:
34+
strategy_configurations = config.get('strategies', {})
35+
36+
entries = []
37+
38+
if not strategy_configurations:
39+
raise DependencyException(
40+
"Could not resolve strategies, please provide the strategy configurations in your config file. "
41+
"You could also use de default strategies, that can be found in the "
42+
"strategies/strategy/templates directory. If you have difficulties creating "
43+
"your own strategies, please see the documentation"
44+
)
45+
46+
for strategy_entry in strategy_configurations.keys():
47+
entry = {
48+
'key': strategy_entry,
49+
'class_name': strategy_configurations[strategy_entry].get('class_name', None),
50+
'enabled': bool(strategy_configurations[strategy_entry].get('enabled', False)),
51+
'plugin': bool(strategy_configurations[strategy_entry].get('plugin', False))
52+
}
53+
entries.append(entry)
54+
55+
return entries
56+
57+
58+
def get_data_provider_plugins(data_provider_configurations: List[Dict[str, Any]]) -> List[DataProvider]:
59+
remote_loader = DataProviderRemoteLoader()
60+
data_providers = []
61+
62+
for entry in data_provider_configurations:
63+
64+
if not entry.get('enabled', False):
65+
continue
66+
67+
if not entry.get('key', None):
68+
raise DependencyException("Configured data provider must specify a identifier name")
69+
70+
if not entry.get('class_name', None):
71+
raise DependencyException(
72+
"Configured data provider {} must specify a class name corresponding "
73+
"to the data provider implementation".format(entry)
74+
)
75+
76+
if not bool(entry.get('plugin', False)):
77+
continue
78+
79+
data_provider: DataProvider = remote_loader.load_data_provider(entry.get('class_name'))
80+
data_providers.append(data_provider)
81+
82+
return data_providers
83+
84+
85+
def get_data_provider_templates(data_provider_configurations: List[Dict[str, Any]]) -> List[DataProvider]:
86+
data_providers = []
87+
88+
for entry in data_provider_configurations:
89+
90+
if not entry.get('key', None):
91+
raise DependencyException("Configured data provider must specify a identifier name")
92+
93+
if bool(entry.get('plugin', False)):
94+
continue
95+
96+
if entry.get("key") == "":
97+
continue
98+
99+
# data_provider: DataProvider = remote_loader.load_data_provider(entry.get('class_name'))
100+
# data_providers.append(data_provider)
101+
102+
return None
103+
104+
105+
def get_strategy_plugins(strategy_configurations: List[Dict[str, Any]]) -> List[Strategy]:
106+
remote_loader = StrategyRemoteLoader()
107+
strategies = []
108+
109+
for entry in strategy_configurations:
110+
111+
if not entry.get('enabled', False):
112+
continue
113+
114+
if not entry.get('key', None):
115+
raise DependencyException("Configured strategy must specify a identifier name")
116+
117+
if not entry.get('class_name', None):
118+
raise DependencyException(
119+
"Configured strategy {} must specify a class name corresponding "
120+
"to the strategy implementation".format(entry)
121+
)
122+
123+
if not bool(entry.get('plugin', False)):
124+
continue
125+
126+
strategy: Strategy = remote_loader.load_strategy(entry.get('class_name'))
127+
strategies.append(strategy)
128+
129+
return strategies
130+
131+
132+
def get_strategy_templates(strategy_configurations: List[Dict[str, Any]]) -> List[Strategy]:
133+
strategies = []
134+
135+
for entry in strategy_configurations:
136+
137+
if not entry.get('key', None):
138+
raise DependencyException("Configured data provider must specify a identifier name")
139+
140+
if bool(entry.get('plugin', False)):
141+
continue
142+
143+
if entry.get("key") == "":
144+
continue
145+
146+
# data_provider: DataProvider = remote_loader.load_data_provider(entry.get('class_name'))
147+
# data_providers.append(data_provider)
148+
149+
return None
150+
151+
152+

bot/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from enum import Enum
2-
2+
from bot.settings import BASE_DIR, PLUGIN_STRATEGIES_DIR, PLUGIN_DATA_PROVIDERS_DIR
33
"""
44
bot constants
55
"""
66
DEFAULT_CONFIG = 'config.json'
77
DEFAULT_MAX_WORKERS = 2
8+
BASE_DIR = BASE_DIR
9+
PLUGIN_STRATEGIES_DIR = PLUGIN_STRATEGIES_DIR
10+
PLUGIN_DATA_PROVIDERS_DIR = PLUGIN_DATA_PROVIDERS_DIR
811

912

1013
class TimeUnit(Enum):

bot/main.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ def main(sysargv: List[str] = None) -> None:
2828
else:
2929
# No subcommand was issued.
3030
raise OperationalException(
31-
"Usage of Freqtrade requires a subcommand to be specified.\n"
32-
"To have the previous behavior (bot executing trades in live/dry-run modes, "
33-
"depending on the value of the `dry_run` setting in the config), run freqtrade "
34-
"as `freqtrade trade [options...]`.\n"
31+
"Usage of the bot requires a sub command to be specified.\n"
3532
"To see the full list of options available, please use "
36-
"`freqtrade --help` or `freqtrade <command> --help`."
33+
"`bot --help` or `bot <command> --help`."
3734
)
3835

3936
except SystemExit as e:

bot/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
55
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
66
PARENT_DIR = os.path.dirname(BASE_DIR)
7+
PLUGIN_STRATEGIES_DIR = os.path.abspath(os.path.join(PARENT_DIR, 'plugins/strategies'))
8+
PLUGIN_DATA_PROVIDERS_DIR = os.path.abspath(os.path.join(PARENT_DIR, 'plugins/data_providers'))
79

810
# Change this when not in development, feature or hot-fix branch
911
DEBUG = int(os.environ.get('DEBUG', True))

bot/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
from wrapt import synchronized
44
from threading import Thread
5+
from pandas import DataFrame
56

67

78
class Singleton(type):
@@ -46,6 +47,18 @@ def kill(self):
4647
self.killed = True
4748

4849

50+
class DataSource:
4951

52+
def __init__(self, data: DataFrame, data_provider_id: str) -> None:
53+
self._data = data
54+
self._data_provider_id = data_provider_id
55+
56+
@property
57+
def data(self) -> DataFrame:
58+
return self._data
59+
60+
@property
61+
def data_provider_id(self) -> str:
62+
return self._data_provider_id
5063

5164

0 commit comments

Comments
 (0)