|
| 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