Skip to content
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

Issue#150 #152

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,6 @@ database/datasets/
dump.rdb
crypto_bot.dump

database/local_db
database/local_db

model/strategies/models/
4 changes: 2 additions & 2 deletions dashboard/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class App extends Component<Props, State> {
key: index + 1,
text: resource !== 'candleSizes' ? resources[resource][name].name : name,
value: index + 1,
...(resource !== 'candleSizes' && resources[resource][name])
...(resource !== 'candleSizes' && resources[resource][name]),
...(resource !== 'candleSizes' && resources[resource][name].className && {strategyName: name})
}))
}
}, {}) : []
Expand Down Expand Up @@ -527,7 +528,6 @@ class App extends Component<Props, State> {
match={match}
symbolsOptions={symbolsOptions}
strategiesOptions={strategiesOptions}

candleSizeOptions={candleSizeOptions}
exchangeOptions={exchangeOptions}
pipelines={pipelines}
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/reducers/modalReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export const getInitialState = (
(strategiesArray: any, pipelineStrategy: RawStrategy) => {
const strategy = strategies.find((strategy: Strategy) => strategy.className === pipelineStrategy.name)

if (!strategy) {
return strategiesArray
}

let strategyValue = strategy.value

while (strategiesArray.includes(strategyValue)) {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export type Strategy = {

export type RawStrategy = {
name: string | undefined
className: string | undefined
params: any
}


export type Pipeline = {
id: number
strategy: RawStrategy[]
Expand Down
18 changes: 16 additions & 2 deletions dashboard/src/utils/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,21 @@ export const validatePipelineCreation = async (
const strategy = dynamicStrategies.find(strategy => strategy.value === index)

return {
name: strategy?.className,
params: strategy?.selectedParams
name: strategy?.strategyName,
className: strategy?.className,
params: Object.keys(strategy?.selectedParams).reduce((acc, param) => {
const paramsObj = {
...strategy?.params,
...strategy?.optionalParams
}

return {
...acc,
[param]: paramsObj[param].options ?
paramsObj[param].options[strategy?.selectedParams[param]] :
strategy?.selectedParams[param]
}
}, {})
}
})

Expand Down Expand Up @@ -121,6 +134,7 @@ export const validateParams = (strategy: any) => {
const params = strategy.selectedParams

const requiredParams = strategy.paramsOrder.reduce((reduced: any, param: string) => {

if (!params.hasOwnProperty(param) || (params[param] === "")) {
return {
success: false,
Expand Down
400 changes: 243 additions & 157 deletions data/poetry.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions data/service/helpers/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ def check_input(strategies, edit_pipeline=False, **kwargs):
raise StrategyInvalid(strategy_input)

for strategy in strategy_input:

try:
strategy_name = strategy["name"]
except KeyError:
raise StrategyInvalid(strategy_input)

if strategy_name in strategies:

try:
params = strategy["params"]
except KeyError:
Expand Down Expand Up @@ -148,7 +146,7 @@ def get_existing_pipeline(fields):
def add_strategies(strategies):
strategies_objs = []
for strategy in strategies:
strategy_obj = Strategy.objects.create(name=strategy["name"], params=json.dumps(strategy["params"]))
strategy_obj = Strategy.objects.create(name=strategy["className"], params=json.dumps(strategy["params"]))
strategies_objs.append(strategy_obj)

return strategies_objs
Expand Down
3 changes: 2 additions & 1 deletion data/sources/binance/_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,10 @@ def _process_new_data(

def get_start_date(self):

max_window = get_pipeline_max_window(self.pipeline_id)
max_window = get_pipeline_max_window(self.pipeline_id, config_vars.default_min_rows)

earliest_date = get_earliest_date(ExchangeData, self.symbol, self.base_candle_size)

minimum_lookback_date = get_minimum_lookback_date(max_window, self.candle_size)

if self.start_date is not None and self.start_date < minimum_lookback_date:
Expand Down
16 changes: 13 additions & 3 deletions data/tests/service/blueprints/test_bots_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,11 @@ def test_start_bot_ongoing_pipeline(
"color": "purple",
"name": "Hello World",
"symbol": "BTCUSDT",
"strategy": [{"name": "MovingAverage", "params": {"ma": 30}}],
"strategy": [{
"name": "MovingAverage",
"className": "MovingAverage",
"params": {"ma": 30}
}],
"candleSize": "1h",
"exchanges": "Binance",
"leverage": 3,
Expand Down Expand Up @@ -380,7 +384,9 @@ def test_start_bot_new_pipeline(

assert pipeline.symbol.name == params["symbol"]
assert pipeline.exchange.name == params["exchanges"].lower()
assert pipeline.as_json()["strategy"] == params["strategy"]

strategy = [{k: v for k, v in strat.items() if k in ["name", "params"]} for strat in params["strategy"]]
assert pipeline.as_json()["strategy"] == strategy
assert len(pipeline.strategy.all()) == len(strategies)

assert pipeline.interval == params["candleSize"]
Expand All @@ -393,7 +399,11 @@ def test_start_bot_new_pipeline(
"color": "purple",
"name": "Hello World",
"symbol": "BTCUSDT",
"strategy": [{"name": "MovingAverage", "params": {"ma": 30}}],
"strategy": [{
"name": "MovingAverage",
"className": "MovingAverage",
"params": {"ma": 30}
}],
"candleSize": "1h",
"exchanges": "Binance",
"equity": 1000
Expand Down
18 changes: 15 additions & 3 deletions data/tests/service/blueprints/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ def test_delete_pipelines_endpoint(
"color": "purple",
"name": "Hello World",
"symbol": "BTCUSDT",
"strategy": [{"name": "MovingAverage", "params": {"ma": 30}}],
"strategy": [{
"name": "MovingAverage",
"className": "MovingAverage",
"params": {"ma": 30}
}],
"candleSize": "1h",
"exchanges": "Binance",
"leverage": 3,
Expand All @@ -409,7 +413,11 @@ def test_delete_pipelines_endpoint(
"color": "purple",
"name": "New pipeline",
"symbol": "BTCUSDT",
"strategy": [{"name": "MovingAverage", "params": {"ma": 30}}],
"strategy": [{
"name": "MovingAverage",
"className": "MovingAverage",
"params": {"ma": 30}
}],
"candleSize": "1h",
"exchanges": "Binance",
"leverage": 3,
Expand All @@ -428,7 +436,11 @@ def test_delete_pipelines_endpoint(
"color": "purple",
"name": "New pipeline",
"symbol": "BTCUSDT",
"strategy": [{"name": "MovingAverage", "params": {"ma": 30}}],
"strategy": [{
"name": "MovingAverage",
"className": "MovingAverage",
"params": {"ma": 30}
}],
"candleSize": "1h",
"exchanges": "Binance",
"leverage": 3,
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ services:
- LOGGER_LEVEL=DEBUG
volumes:
- ./database/model:/usr/src/app/database/model
- ./model/strategies/models:/usr/src/app/model/strategies/models
model-worker:
build:
context: .
Expand All @@ -63,6 +64,9 @@ services:
- EXECUTION_APP_URL=http://execution-service:5000
depends_on:
- redis
volumes:
- ./database/model:/usr/src/app/database/model
- ./model/strategies/models:/usr/src/app/model/strategies/models
execution-service:
build:
context: .
Expand Down
2 changes: 2 additions & 0 deletions execution/exchanges/binance/futures/_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def stop_symbol_trading(self, pipeline_id, header=''):
self.close_pos(symbol, date=datetime.now(tz=pytz.UTC), header=header, pipeline_id=pipeline_id)
except NoUnits:
logging.info(header + "There's no position to be closed.")
except KeyError:
logging.info(header + "There's no position to be closed.")

self.symbols.pop(symbol)

Expand Down
Loading
Loading