Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

[Service][Web] Add prediction market web distribution#1693

Closed
Herklos wants to merge 1 commit into
devfrom
feature/add-prediction-market-web-distribution
Closed

[Service][Web] Add prediction market web distribution#1693
Herklos wants to merge 1 commit into
devfrom
feature/add-prediction-market-web-distribution

Conversation

@Herklos
Copy link
Copy Markdown
Contributor

@Herklos Herklos commented Jan 27, 2026

No description provided.

@Herklos Herklos self-assigned this Jan 27, 2026
@Herklos Herklos force-pushed the feature/add-prediction-market-web-distribution branch 4 times, most recently from ea9da19 to 8bdf610 Compare January 29, 2026 19:16
@Herklos Herklos changed the title Feature/add prediction market web distribution [Service][Web] Add prediction market web distribution Jan 29, 2026
@Herklos Herklos force-pushed the feature/add-prediction-market-web-distribution branch 4 times, most recently from 37a98da to 2033ff9 Compare January 30, 2026 23:21
@Herklos Herklos force-pushed the feature/add-prediction-market-web-distribution branch from 2033ff9 to 8863296 Compare January 30, 2026 23:23
@Herklos Herklos requested a review from GuillaumeDSM January 30, 2026 23:24
@Herklos Herklos marked this pull request as ready for review January 30, 2026 23:24
@Herklos
Copy link
Copy Markdown
Contributor Author

Herklos commented Jan 30, 2026

PR is ready

Comment on lines +60 to +148
def _save_user_config(
enabled_exchange: typing.Optional[str],
trading_pair: typing.Optional[str],
exchange_configurations: list[dict],
trading_simulator_configuration: dict,
simulated_portfolio_configuration: list[dict],
) -> None:
current_edited_config = interfaces_util.get_edited_config(dict_only=False)

# exchanges: regenerate the whole configuration
exchange_config_update = json_schemas.json_exchange_config_to_config(
exchange_configurations, False
)
if exchange_config_update and enabled_exchange not in exchange_config_update:
# removed enabled exchange from exchange configs: use 1st exchange instead
enabled_exchange = next(iter(exchange_config_update))

if enabled_exchange and enabled_exchange in exchange_config_update:
# only enable selected exchange, force spot trading
exchange_config_update[enabled_exchange].update({
commons_constants.CONFIG_ENABLED_OPTION: True,
commons_constants.CONFIG_EXCHANGE_TYPE: commons_constants.CONFIG_EXCHANGE_SPOT,
})
current_exchanges_config = copy.deepcopy(current_edited_config.config[commons_constants.CONFIG_EXCHANGES])
# nested_update_dict to keep nested key/val that might have been in previous config but are not in update
# don't pass current_exchanges_config directly to really delete exchanges
updated_exchange_config = {
exchange: exchange_config
for exchange, exchange_config in current_exchanges_config.items()
if exchange in exchange_config_update
}
dict_util.nested_update_dict(updated_exchange_config, exchange_config_update)

# currencies: regenerate the whole configuration
updated_currencies_config = {
trading_pair: {
commons_constants.CONFIG_ENABLED_OPTION: True,
commons_constants.CONFIG_CRYPTO_PAIRS: [trading_pair]
}
} if trading_pair else {}

# trader simulator
simulated_enabled = trading_simulator_configuration[commons_constants.CONFIG_ENABLED_OPTION]
updated_simulator_config = copy.deepcopy(current_edited_config.config[commons_constants.CONFIG_SIMULATOR])
previous_simulated_portfolio = copy.deepcopy(
updated_simulator_config.get(commons_constants.CONFIG_STARTING_PORTFOLIO)
)
simulator_config_update = {
**trading_simulator_configuration, **{
commons_constants.CONFIG_STARTING_PORTFOLIO: json_schemas.json_simulated_portfolio_to_config(
simulated_portfolio_configuration
)
}
}
updated_portfolio = simulator_config_update[commons_constants.CONFIG_STARTING_PORTFOLIO]
changed_portfolio = _filter_0_values(previous_simulated_portfolio) != _filter_0_values(updated_portfolio)
# replace portfolio to allow asset removal (otherwise nested_update_dict will never remove assets)
updated_simulator_config[commons_constants.CONFIG_STARTING_PORTFOLIO] = updated_portfolio
dict_util.nested_update_dict(updated_simulator_config, simulator_config_update)

# real trader
updated_trader_config = copy.deepcopy(current_edited_config.config[commons_constants.CONFIG_TRADER])
# only update the "enabled" state
updated_trader_config[commons_constants.CONFIG_ENABLED_OPTION] = not simulated_enabled

# trading
updated_trading_config = copy.deepcopy(current_edited_config.config[commons_constants.CONFIG_TRADING])
if trading_pair:
# only update the reference market
updated_trading_config[commons_constants.CONFIG_TRADER_REFERENCE_MARKET] = (
symbol_utils.parse_symbol(trading_pair).quote
)

update = {
commons_constants.CONFIG_CRYPTO_CURRENCIES: updated_currencies_config,
commons_constants.CONFIG_EXCHANGES: updated_exchange_config,
commons_constants.CONFIG_TRADING: updated_trading_config,
commons_constants.CONFIG_TRADER: updated_trader_config,
commons_constants.CONFIG_SIMULATOR: updated_simulator_config,
}
# apply & save changes
current_edited_config.config.update(update)
current_edited_config.save()
_get_logger().info(
f"Configuration updated. Current profile: {current_edited_config.profile.name}"
)
if changed_portfolio:
_get_logger().info("Simulated portfolio changed: resetting simulated portfolio content.")
models_trading.clear_exchanges_portfolio_history(simulated_only=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like the same code as the market_making distribution _save_user_config
If it actually is, I think we should factorize it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be re-used from the MM distrib somehow? maybe it makes sens to have some kind of common things between MM & PR when it comes to configuration if they use the same system.
But if they will evolve differently, then we should keep it this way

@Herklos
Copy link
Copy Markdown
Contributor Author

Herklos commented Feb 3, 2026

Replaced by Drakkar-Software/OctoBot#3215

@Herklos Herklos closed this Feb 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants