Skip to content

Commit

Permalink
[TradingModes] init optimize_initial_portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Oct 8, 2023
1 parent dda460a commit 7df8fb2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
9 changes: 9 additions & 0 deletions Trading/Mode/dca_trading_mode/dca_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import octobot_trading.constants as trading_constants
import octobot_trading.util as trading_util
import octobot_trading.errors as trading_errors
import octobot_trading.exchanges.util.exchange_util as exchange_util
import octobot_trading.personal_data as trading_personal_data
import octobot_trading.modes.script_keywords as script_keywords

Expand Down Expand Up @@ -662,3 +663,11 @@ def get_current_state(self) -> (str, float):
",".join([str(e) for e in self.producers[0].final_eval]) if self.producers[0].final_eval
else self.producers[0].final_eval
)

async def optimize_initial_portfolio(self, sellable_assets: list):
target_asset = exchange_util.get_common_traded_quote(self.exchange_manager)
if target_asset is None:
self.logger.error(f"Impossible to optimize initial portfolio with different quotes in traded pairs")
return
self.logger.info(f"Optimizing portfolio: selling {sellable_assets} to buy {target_asset}")
await trading_modes.convert_to_target_asset(self, sellable_assets, target_asset)
21 changes: 12 additions & 9 deletions Trading/Mode/grid_trading_mode/grid_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,18 @@ def get_user_commands(cls) -> dict:
:return: the commands dict
"""
return {
GridTradingMode.USER_COMMAND_CREATE_ORDERS: {
GridTradingMode.USER_COMMAND_TRADING_PAIR: "text"
},
GridTradingMode.USER_COMMAND_STOP_ORDERS_CREATION: {
GridTradingMode.USER_COMMAND_TRADING_PAIR: "text"
},
GridTradingMode.USER_COMMAND_PAUSE_ORDER_MIRRORING: {
GridTradingMode.USER_COMMAND_TRADING_PAIR: "text",
GridTradingMode.USER_COMMAND_PAUSE_TIME: "number"
**super().get_user_commands(),
**{
GridTradingMode.USER_COMMAND_CREATE_ORDERS: {
GridTradingMode.USER_COMMAND_TRADING_PAIR: "text"
},
GridTradingMode.USER_COMMAND_STOP_ORDERS_CREATION: {
GridTradingMode.USER_COMMAND_TRADING_PAIR: "text"
},
GridTradingMode.USER_COMMAND_PAUSE_ORDER_MIRRORING: {
GridTradingMode.USER_COMMAND_TRADING_PAIR: "text",
GridTradingMode.USER_COMMAND_PAUSE_TIME: "number"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class StaggeredOrdersTradingMode(trading_modes.AbstractTradingMode):
CONFIG_DEFAULT_SPREAD_PERCENT = 1.5
CONFIG_DEFAULT_INCREMENT_PERCENT = 0.5
REQUIRE_TRADES_HISTORY = True # set True when this trading mode needs the trade history to operate
SUPPORTS_INITIAL_PORTFOLIO_OPTIMIZATION = True # set True when self._optimize_initial_portfolio is implemented

def init_user_inputs(self, inputs: dict) -> None:
"""
Expand Down Expand Up @@ -251,6 +252,9 @@ def get_is_symbol_wildcard(cls) -> bool:
def set_default_config(self):
raise RuntimeError(f"Impossible to start {self.get_name()} without a valid configuration file.")

async def optimize_initial_portfolio(self, sellable_assets: list):
print("optimize_initial_portfolio")


class StaggeredOrdersTradingModeConsumer(trading_modes.AbstractTradingModeConsumer):
ORDER_DATA_KEY = "order_data"
Expand Down

0 comments on commit 7df8fb2

Please sign in to comment.