-
-
Notifications
You must be signed in to change notification settings - Fork 819
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
Simulator #2470
Merged
Merged
Simulator #2470
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a1dbd3
[Community] support simulator settings
GuillaumeDSM 168a90c
[Requirements] bump
GuillaumeDSM b55c0d8
[Community] add get_bot_deployment_value
GuillaumeDSM 9c3c36f
[Community] add use_as_singleton param
GuillaumeDSM 3313b6f
[Requirements] bump
GuillaumeDSM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -69,6 +69,11 @@ def format_orders(orders: list, exchange_name: str) -> list: | |
), | ||
backend_enums.OrderKeys.QUANTITY.value: storage_order[trading_constants.STORAGE_ORIGIN_VALUE][ | ||
trading_enums.ExchangeConstantsOrderColumns.AMOUNT.value], | ||
backend_enums.OrderKeys.EXCHANGE_ID.value: storage_order[trading_constants.STORAGE_ORIGIN_VALUE][ | ||
trading_enums.ExchangeConstantsOrderColumns.EXCHANGE_ID.value], | ||
backend_enums.OrderKeys.CHAINED.value: format_orders( | ||
storage_order.get(trading_enums.StoredOrdersAttr.CHAINED_ORDERS.value, []), exchange_name | ||
) if storage_order.get(trading_enums.StoredOrdersAttr.CHAINED_ORDERS.value, []) else [] | ||
} | ||
for storage_order in orders | ||
if storage_order.get(trading_constants.STORAGE_ORIGIN_VALUE, {}).get( | ||
|
@@ -133,3 +138,13 @@ def format_portfolio_history(history: dict, unit: str, portfolio_id: str) -> lis | |
] | ||
except KeyError: | ||
return [] | ||
|
||
|
||
def get_adapted_portfolio(usd_like_asset, portfolio): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
formatted = {} | ||
for asset in portfolio: | ||
currency = asset[backend_enums.PortfolioAssetKeys.ASSET.value] | ||
if currency == "USD-like": | ||
currency = usd_like_asset | ||
formatted[currency] = asset[backend_enums.PortfolioAssetKeys.VALUE.value] | ||
return formatted |
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 |
---|---|---|
|
@@ -29,8 +29,10 @@ | |
import octobot_commons.profiles as commons_profiles | ||
import octobot_commons.enums as commons_enums | ||
import octobot_commons.constants as commons_constants | ||
import octobot_trading.api as trading_api | ||
import octobot.constants as constants | ||
import octobot.community.errors as errors | ||
import octobot.community.models.formatters as formatters | ||
import octobot.community.supabase_backend.enums as enums | ||
import octobot.community.supabase_backend.supabase_client as supabase_client | ||
import octobot.community.supabase_backend.configuration_storage as configuration_storage | ||
|
@@ -247,6 +249,7 @@ async def fetch_bot_profile_data(self, bot_config_id: str) -> commons_profiles.P | |
"bot_id, " | ||
"options, " | ||
"exchanges, " | ||
"is_simulated, " | ||
"product_config:product_configs(" | ||
" config, " | ||
" version, " | ||
|
@@ -263,10 +266,30 @@ async def fetch_bot_profile_data(self, bot_config_id: str) -> commons_profiles.P | |
].get("minimal_funds", []) | ||
] if bot_config[enums.BotConfigKeys.EXCHANGES.value] else [] | ||
profile_data.profile_details.version = bot_config["product_config"][enums.ProfileConfigKeys.VERSION.value] | ||
profile_data.trader_simulator.enabled = bot_config.get("is_simulated", False) | ||
if profile_data.trader_simulator.enabled: | ||
portfolio = (bot_config.get( | ||
enums.BotConfigKeys.OPTIONS.value | ||
) or {}).get("portfolio") | ||
if trading_api.is_usd_like_coin(profile_data.trading.reference_market): | ||
usd_like_asset = profile_data.trading.reference_market | ||
Comment on lines
+274
to
+275
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
else: | ||
usd_like_asset = "USDT" # todo use dynamic value when exchange is not supporting USDT | ||
profile_data.trader_simulator.starting_portfolio = formatters.get_adapted_portfolio( | ||
usd_like_asset, portfolio | ||
) | ||
exchanges_config = ( | ||
# use product config exchanges when no exchange is set in bot_config and when in simulator mode | ||
bot_config["product_config"][enums.ProfileConfigKeys.CONFIG.value]["exchanges"] | ||
if profile_data.trader_simulator.enabled | ||
# otherwise use botconfig exchange id | ||
else bot_config[enums.BotConfigKeys.EXCHANGES.value] if bot_config[enums.BotConfigKeys.EXCHANGES.value] | ||
else [] | ||
) | ||
profile_data.exchanges = [ | ||
commons_profiles.ExchangeData.from_dict(exchange_data) | ||
for exchange_data in bot_config[enums.BotConfigKeys.EXCHANGES.value] | ||
] if bot_config[enums.BotConfigKeys.EXCHANGES.value] else [] | ||
for exchange_data in exchanges_config | ||
] | ||
if options := bot_config.get(enums.BotConfigKeys.OPTIONS.value): | ||
profile_data.options = commons_profiles.OptionsData.from_dict(options) | ||
profile_data.profile_details.id = bot_config_id | ||
|
@@ -287,17 +310,22 @@ async def fetch_product_config(self, product_id: str) -> commons_profiles.Profil | |
profile_data.profile_details.version = product["product_config"][enums.ProfileConfigKeys.VERSION.value] | ||
return profile_data | ||
|
||
async def fetch_configs(self, bot_id) -> list: | ||
async def fetch_configs(self, bot_id: str) -> list: | ||
# use a new current portfolio for the given bot | ||
return (await self.table("bot_configs").select("*").eq( | ||
enums.BotConfigKeys.BOT_ID.value, bot_id | ||
).execute()).data | ||
|
||
async def fetch_portfolios(self, bot_id) -> list: | ||
async def fetch_portfolios(self, bot_id: str) -> list: | ||
return (await self.table("bot_portfolios").select("*").eq( | ||
enums.PortfolioKeys.BOT_ID.value, bot_id | ||
).execute()).data | ||
|
||
async def fetch_portfolio_from_id(self, portfolio_id: str) -> list: | ||
return (await self.table("bot_portfolios").select("*").eq( | ||
enums.PortfolioKeys.ID.value, portfolio_id | ||
).execute()).data | ||
|
||
async def update_portfolio(self, portfolio) -> list: | ||
# use a new current portfolio for the given bot | ||
return (await self.table("bot_portfolios").update(portfolio).eq( | ||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also check that
self.user_account.bot_id
is not None ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's initialized in constructor, it should never be None, we are fine :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!