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
Closed
Conversation
ea9da19 to
8bdf610
Compare
37a98da to
2033ff9
Compare
2033ff9 to
8863296
Compare
Contributor
Author
|
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) |
Member
There was a problem hiding this comment.
this looks like the same code as the market_making distribution _save_user_config
If it actually is, I think we should factorize it
Member
There was a problem hiding this comment.
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
Contributor
Author
|
Replaced by Drakkar-Software/OctoBot#3215 |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.