Skip to content

Commit 3bca2d8

Browse files
committed
w
1 parent c3560fc commit 3bca2d8

11 files changed

Lines changed: 443 additions & 309 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Drakkar-Software OctoBot
2+
# Copyright (c) Drakkar-Software, All rights reserved.
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 3.0 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library.
16+
import decimal
17+
18+
# Rebalance planner thresholds
19+
ALLOWED_1_TO_1_SWAP_COUNTS = 1
20+
MIN_RATIO_TO_SELL = decimal.Decimal("0.0001") # 1/10000
21+
QUOTE_ASSET_TO_TARGETED_SWAP_RATIO_THRESHOLD = decimal.Decimal("0.1") # 10%
22+
23+
# Index / rebalancing trading config keys (shared by planner, index trading mode, profiles).
24+
CONFIG_INDEX_CONTENT = "index_content"
25+
CONFIG_REBALANCE_TRIGGER_MIN_PERCENT = "rebalance_trigger_min_percent"
26+
CONFIG_REBALANCE_TRIGGER_PROFILES = "rebalance_trigger_profiles"
27+
CONFIG_SELECTED_REBALANCE_TRIGGER_PROFILE = "selected_rebalance_trigger_profile"
28+
CONFIG_REBALANCE_TRIGGER_PROFILE_NAME = "name"
29+
CONFIG_REBALANCE_TRIGGER_PROFILE_MIN_PERCENT = "min_percent"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from octobot_copy.exchange.exchange_interface import ExchangeInterface
2+
3+
__all__ = [
4+
"ExchangeInterface",
5+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import typing
2+
3+
import octobot_commons.symbols
4+
5+
if typing.TYPE_CHECKING:
6+
import octobot_trading.exchanges
7+
8+
class ExchangeInterface:
9+
def __init__(self, exchange_manager: "octobot_trading.exchanges.ExchangeManager"):
10+
self._exchange_manager: "octobot_trading.exchanges.ExchangeManager" = exchange_manager
11+
12+
@property
13+
def exchange_name(self) -> str:
14+
return self._exchange_manager.exchange_name
15+
16+
def get_traded_symbols(self) -> typing.Iterable[octobot_commons.symbols.Symbol]:
17+
return self._exchange_manager.exchange_config.traded_symbols
18+
19+
def get_time(self) -> float:
20+
return self._exchange_manager.exchange.get_exchange_current_time()

packages/copy/octobot_copy/rebalancing/planner/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
# License along with this library.
1616

1717
from octobot_copy.rebalancing.planner.rebalance_actions_planner import RebalanceActionsPlanner
18+
from octobot_copy.rebalancing.planner.distributions import get_uniform_distribution
1819

19-
__all__ = ["RebalanceActionsPlanner"]
20+
__all__ = [
21+
"RebalanceActionsPlanner",
22+
"get_uniform_distribution",
23+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Drakkar-Software OctoBot
2+
# Copyright (c) Drakkar-Software, All rights reserved.
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 3.0 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library.
16+
import decimal
17+
import typing
18+
19+
import octobot_copy.enums as copy_enums
20+
import octobot_trading.constants
21+
22+
MAX_DISTRIBUTION_AFTER_COMMA_DIGITS = 1
23+
24+
25+
def get_uniform_distribution(
26+
coins,
27+
price_by_coin: typing.Optional[dict[str, decimal.Decimal]] = None,
28+
) -> typing.List:
29+
if not coins:
30+
return []
31+
ratio = float(
32+
round(
33+
octobot_trading.constants.ONE / decimal.Decimal(str(len(coins))) * octobot_trading.constants.ONE_HUNDRED,
34+
MAX_DISTRIBUTION_AFTER_COMMA_DIGITS,
35+
)
36+
)
37+
if not ratio:
38+
return []
39+
return [
40+
{
41+
copy_enums.DistributionKeys.NAME.value: coin,
42+
copy_enums.DistributionKeys.VALUE.value: ratio,
43+
copy_enums.DistributionKeys.PRICE.value: price_by_coin.get(coin) if price_by_coin else None,
44+
}
45+
for coin in coins
46+
]

0 commit comments

Comments
 (0)