Skip to content

Commit

Permalink
Merge branch 'master' into 44-check-api-keys-for-permissions-to-endpo…
Browse files Browse the repository at this point in the history
…ints-before-starting-the-websocket-connection
  • Loading branch information
btschwertfeger authored Jan 13, 2025
2 parents e546127 + 03b75f8 commit c34f7f8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ these steps:
| `KRAKEN_RUN_BASE_CURRENCY` | `str` | The base currency e.g., `BTC`. |
| `KRAKEN_RUN_QUOTE_CURRENCY` | `str` | The quote currency e.g., `USD`. |
| `KRAKEN_RUN_AMOUNT_PER_GRID` | `float` | The amount to use per grid interval e.g., `100` (USD). |
| `KRAKEN_RUN_INTERVAL` | `float` | The interval between orders e.g., `0.04` to have 4 % intervals). |
| `KRAKEN_RUN_INTERVAL` | `float` | The interval between orders e.g., `0.04` to have 4 % intervals. |
| `KRAKEN_RUN_N_OPEN_BUY_ORDERS` | `int` | The number of concurrent open buy orders, e.g., `3`. |
| `KRAKEN_RUN_MAX_INVESTMENT` | `str` | The maximum investment amount, e.g. `1000` USD. |
| `KRAKEN_RUN_FEE` | `float` | A custom fee percentage, e.g. `0.0026` for 0.26 % fee. |
| `KRAKEN_RUN_STRATEGY` | `str` | The trading strategy (e.g., `GridHODL`, `GridSell`, `SWING`, or `DCA`). |
| `KRAKEN_RUN_TELEGRAM_TOKEN` | `str` | The Telegram bot token for notifications. |
| `KRAKEN_RUN_TELEGRAM_CHAT_ID` | `str` | The Telegram chat ID for notifications. |
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ package-dir = { "" = "src" }
[tool.setuptools.packages.find]
where = ["src"]
include = ["kraken_infinity_grid*"]
exclude = [".env"]
exclude = [".env", "tests"]

[tool.setuptools_scm]
write_to = "src/kraken_infinity_grid/_version.py"
Expand Down
26 changes: 24 additions & 2 deletions src/kraken_infinity_grid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ def ensure_larger_than_zero(
) -> Any: # noqa: ANN401
"""Ensure the value is larger than 0"""
if value <= 0:
ctx.fail(f"Value for option '{param.name}' must be larger than 0")
ctx.fail(f"Value for option '{param.name}' must be larger than 0!")
return value


def ensure_larger_equal_zero(
ctx: Context,
param: Any, # noqa: ANN401
value: Any, # noqa: ANN401
) -> Any: # noqa: ANN401
"""Ensure the value is larger than 0"""
if value is not None and value < 0:
ctx.fail(f"Value for option '{param.name}' must be larger then or equal to 0!")
return value


Expand Down Expand Up @@ -136,7 +147,7 @@ def cli(ctx: Context, **kwargs: dict) -> None:
"--name",
required=True,
type=STRING,
help="The name of the bot.",
help="The name of the instance, displayed in telegram messages.",
)
@option(
"--base-currency",
Expand Down Expand Up @@ -219,6 +230,17 @@ def cli(ctx: Context, **kwargs: dict) -> None:
callback=ensure_larger_than_zero,
help="A reference number to identify the bots orders with.",
)
@option(
"--fee",
type=FLOAT,
required=False,
callback=ensure_larger_equal_zero,
help="""
The fee percentage to respect, e.g. '0.0026' for 0.26 %. This value does not
change the actual paid fee, instead it used to estimate order sizes. If not
passed, the highest maker fee will be used.
""",
)
@option(
"--sqlite-file",
type=STRING,
Expand Down
2 changes: 1 addition & 1 deletion src/kraken_infinity_grid/gridbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(
self.interval: float = float(config["interval"])
self.amount_per_grid: float = float(config["amount_per_grid"])

self.amount_per_grid_plus_fee: float | None = None
self.amount_per_grid_plus_fee: float | None = config.get("fee")

self.max_investment: float = config["max_investment"]
self.n_open_buy_orders: int = config["n_open_buy_orders"]
Expand Down
7 changes: 6 additions & 1 deletion src/kraken_infinity_grid/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ def __check_asset_pair_parameter(self: Self) -> None:
self.__s.zbase_currency = data["base"] # XXBT
self.__s.xquote_currency = data["quote"] # ZEUR
self.__s.cost_decimals = data["cost_decimals"] # 5, i.e., 0.00001 EUR
self.__s.fee = float(data["fees_maker"][0][1]) / 100

if self.__s.fee is None:
# This is the case if the '--fee' parameter was not passed, then we
# take the highest maker fee.
self.__s.fee = float(data["fees_maker"][0][1]) / 100

self.__s.amount_per_grid_plus_fee = self.__s.amount_per_grid * (
1 + self.__s.fee
)
Expand Down
2 changes: 1 addition & 1 deletion src/kraken_infinity_grid/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def send_bot_update(self: Self) -> None: # noqa: C901
)
message += f"├ Available {self.__s.base_currency} » {balances['base_available'] - float(self.__s.configuration.get()['vol_of_unfilled_remaining'])}\n" # noqa: E501
message += f"├ Unfilled surplus of {self.__s.base_currency} » {self.__s.configuration.get()['vol_of_unfilled_remaining']}\n" # noqa: E501
message += f"├ Bot-managed wealth » {round(balances['base_balance'] * self.__s.ticker.last + balances['quote_balance'], self.__s.cost_decimals)} {self.__s.quote_currency}\n" # noqa: E501
message += f"├ Wealth » {round(balances['base_balance'] * self.__s.ticker.last + balances['quote_balance'], self.__s.cost_decimals)} {self.__s.quote_currency}\n" # noqa: E501
message += f"└ Investment » {round(self.__s.investment, self.__s.cost_decimals)} / {self.__s.max_investment} {self.__s.quote_currency}\n\n" # noqa: E501

message += "💠 Orders\n"
Expand Down
13 changes: 11 additions & 2 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,15 @@ def test_update_order_book(
)


@pytest.mark.wip
@pytest.mark.parametrize(
"input_fee,asset_fee,order_size", # noqa: PT006
[(None, 0.0026, 100.26), (0.02, 0.02, 102)],
)
def test_check_asset_pair_parameter(
input_fee: float,
asset_fee: float,
order_size: float,
setup_manager: SetupManager,
strategy: mock.Mock,
) -> None:
Expand All @@ -246,15 +254,16 @@ def test_check_asset_pair_parameter(
}
strategy.symbol = "BTC/USD"
strategy.amount_per_grid = 100
strategy.fee = input_fee

setup_manager._SetupManager__check_asset_pair_parameter()

assert strategy.fee == 0.0026
assert strategy.fee == asset_fee
assert strategy.altname == "BTC/USD"
assert strategy.zbase_currency == "XXBT"
assert strategy.xquote_currency == "ZEUR"
assert strategy.cost_decimals == 5
assert strategy.amount_per_grid_plus_fee == pytest.approx(100.26)
assert strategy.amount_per_grid_plus_fee == pytest.approx(order_size)


def test_check_configuration_changes(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_send_bot_update(
assert "├ Available USD » 50.0" in message
assert "├ Available BTC » 0.4" in message
assert "├ Unfilled surplus of BTC » 0.1" in message
assert "├ Bot-managed wealth » 50100.0 USD" in message
assert "├ Wealth » 50100.0 USD" in message
assert "└ Investment » 1000.0 / 2000.0 USD" in message
assert "💠 Orders" in message
assert "├ Amount per Grid » 10.0 USD" in message
Expand Down

0 comments on commit c34f7f8

Please sign in to comment.