-
Notifications
You must be signed in to change notification settings - Fork 75
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
[DCA][Staggered] init health check #1114
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import octobot_trading.enums as trading_enums | ||
import octobot_trading.personal_data as trading_personal_data | ||
import octobot_trading.errors as trading_errors | ||
import octobot_trading.exchanges.util as exchange_util | ||
|
||
|
||
class StrategyModes(enum.Enum): | ||
|
@@ -119,11 +120,13 @@ class StaggeredOrdersTradingMode(trading_modes.AbstractTradingMode): | |
CONFIG_SELL_VOLUME_PER_ORDER = "sell_volume_per_order" | ||
CONFIG_BUY_VOLUME_PER_ORDER = "buy_volume_per_order" | ||
CONFIG_IGNORE_EXCHANGE_FEES = "ignore_exchange_fees" | ||
ENABLE_UPWARDS_PRICE_FOLLOW = "enable_upwards_price_follow" | ||
CONFIG_USE_FIXED_VOLUMES_FOR_MIRROR_ORDERS = "use_fixed_volume_for_mirror_orders" | ||
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 | ||
SUPPORTS_HEALTH_CHECK = False # set True when self.health_check is implemented | ||
|
||
def init_user_inputs(self, inputs: dict) -> None: | ||
""" | ||
|
@@ -251,6 +254,23 @@ 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 single_exchange_process_health_check(self, chained_orders: list, tickers: dict) -> list: | ||
created_orders = [] | ||
if await self._should_rebalance_orders(): | ||
target_asset = exchange_util.get_common_traded_quote(self.exchange_manager) | ||
created_orders += await self.single_exchange_process_optimize_initial_portfolio([], target_asset, tickers) | ||
for producer in self.producers: | ||
await producer.trigger_staggered_orders_creation() | ||
return created_orders | ||
|
||
async def _should_rebalance_orders(self): | ||
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. 👍 |
||
for producer in self.producers: | ||
if producer.enable_upwards_price_follow: | ||
# trigger rebalance when current price is beyond the highest sell order | ||
if await producer.is_price_beyond_boundaries(): | ||
return True | ||
return False | ||
|
||
async def single_exchange_process_optimize_initial_portfolio( | ||
self, sellable_assets, target_asset: str, tickers: dict | ||
) -> list: | ||
|
@@ -515,6 +535,7 @@ def __init__(self, channel, config, trading_mode, exchange_manager): | |
|
||
self.use_existing_orders_only = self.limit_orders_count_if_necessary = \ | ||
self.ignore_exchange_fees = self.use_fixed_volume_for_mirror_orders = False | ||
self.enable_upwards_price_follow = True | ||
self.mode = self.spread \ | ||
= self.increment = self.operational_depth \ | ||
= self.lowest_buy = self.highest_sell \ | ||
|
@@ -591,6 +612,9 @@ def read_config(self): | |
# end tmp | ||
self.ignore_exchange_fees = self.symbol_trading_config.get(self.trading_mode.CONFIG_IGNORE_EXCHANGE_FEES, | ||
self.ignore_exchange_fees) | ||
self.enable_upwards_price_follow = self.symbol_trading_config.get( | ||
self.trading_mode.ENABLE_UPWARDS_PRICE_FOLLOW, self.enable_upwards_price_follow | ||
) | ||
|
||
async def start(self) -> None: | ||
await super().start() | ||
|
@@ -617,6 +641,18 @@ async def set_final_eval(self, matrix_id: str, cryptocurrency: str, symbol: str, | |
# nothing to do: this is not a strategy related trading mode | ||
pass | ||
|
||
async def is_price_beyond_boundaries(self): | ||
open_orders = self.exchange_manager.exchange_personal_data.orders_manager.get_open_orders(self.symbol) | ||
price = await trading_personal_data.get_up_to_date_price( | ||
self.exchange_manager, self.symbol, timeout=self.PRICE_FETCHING_TIMEOUT | ||
) | ||
max_order_price = max( | ||
order.origin_price for order in open_orders | ||
) | ||
# price is above max order price | ||
if max_order_price < price and self.enable_upwards_price_follow: | ||
return True | ||
|
||
def _schedule_order_refresh(self): | ||
# schedule order creation / health check | ||
asyncio.create_task(self._ensure_staggered_orders_and_reschedule()) | ||
|
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.
Why isn't it the same implementation as staggered?
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.
staggered have min and max prices boundaries, it makes orders "grid" translation much more complicated
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.
Oh right, I see