From c796d646c76a41faebd417c7e638d6bb9ad4f2aa Mon Sep 17 00:00:00 2001 From: DogsTailFarmer Date: Thu, 2 May 2024 22:34:39 +0300 Subject: [PATCH] 3.0.7 --- .run/martin-binance-image.run.xml | 15 +++++++++++++ .run/martin-binance.run.xml | 33 ++++++++++++++++++++++++++++ CHANGELOG.md | 6 ++++- Dockerfile | 6 ++++- README.md | 2 ++ martin_binance/__init__.py | 2 +- martin_binance/backtest/optimizer.py | 6 ++++- martin_binance/executor.py | 18 +++++++++++---- martin_binance/strategy_base.py | 11 +++++++--- pyproject.toml | 2 +- requirements.txt | 2 +- 11 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 .run/martin-binance-image.run.xml create mode 100644 .run/martin-binance.run.xml mode change 100755 => 100644 martin_binance/backtest/optimizer.py mode change 100755 => 100644 martin_binance/executor.py diff --git a/.run/martin-binance-image.run.xml b/.run/martin-binance-image.run.xml new file mode 100644 index 0000000..3152e9f --- /dev/null +++ b/.run/martin-binance-image.run.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/.run/martin-binance.run.xml b/.run/martin-binance.run.xml new file mode 100644 index 0000000..13acbb3 --- /dev/null +++ b/.run/martin-binance.run.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cae5aa9..6719e0e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ -## 3.0.6.post1 - 2024-04-xx +## 3.0.7 - 2024-05-02 +### Fix +* `Docker`: server-client deployment functionality restored (`exchanges-wrapper` and `martin-binance`), also for Windows + ### Update * `RATE_LIMITER` initial settings changed +* Up requirements for exchanges-wrapper==2.1.12 ## 3.0.6 - 2024-04-19 ### Fix diff --git a/Dockerfile b/Dockerfile index 0624001..025f45d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,11 @@ COPY requirements.txt requirements.txt RUN pip3 install --no-cache-dir -r requirements.txt -COPY ./martin_binance/* /home/appuser/.local/lib/python3.10/site-packages/martin_binance/ +COPY ./martin_binance /home/appuser/.local/lib/python3.10/site-packages/martin_binance/ + +USER root +RUN chmod +x /home/appuser/.local/lib/python3.10/site-packages/martin_binance/backtest/optimizer.py +USER appuser WORKDIR "/home/appuser/.local/lib/python3.10/site-packages" diff --git a/README.md b/README.md index 38ec711..adbf9ea 100755 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ should be updated. Use templates for reference. > >As a result of the mutual impact on the operating balance sheet, the liquidity control system will block the work. +* Due to a limitation in the implementation of asyncio under Windows, this program cannot be executed. [Use Docker on Windows instead.](https://github.com/DogsTailFarmer/martin-binance/wiki/Quick-start#docker) + ## References * Detailed information about use this strategy placed to [wiki](https://github.com/DogsTailFarmer/martin-binance/wiki) * [Trade idea](https://github.com/DogsTailFarmer/martin-binance/wiki/Trade-idea) diff --git a/martin_binance/__init__.py b/martin_binance/__init__.py index fdbfe83..d8ef49f 100755 --- a/martin_binance/__init__.py +++ b/martin_binance/__init__.py @@ -6,7 +6,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.6.post1" +__version__ = "3.0.7" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" diff --git a/martin_binance/backtest/optimizer.py b/martin_binance/backtest/optimizer.py old mode 100755 new mode 100644 index c666fcd..4d13348 --- a/martin_binance/backtest/optimizer.py +++ b/martin_binance/backtest/optimizer.py @@ -24,7 +24,11 @@ from martin_binance import LOG_PATH, TRIAL_PARAMS OPTIMIZER = Path(__file__).absolute() -OPTIMIZER.chmod(OPTIMIZER.stat().st_mode | stat.S_IEXEC) +try: + OPTIMIZER.chmod(OPTIMIZER.stat().st_mode | stat.S_IEXEC) +except PermissionError: + pass # if executed in Docker environment + PARAMS_FLOAT = ['KBB'] STRATEGY = None diff --git a/martin_binance/executor.py b/martin_binance/executor.py old mode 100755 new mode 100644 index 5b8ca20..1501a20 --- a/martin_binance/executor.py +++ b/martin_binance/executor.py @@ -4,7 +4,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.6" +__version__ = "3.0.7" __maintainer__ = "Jerry Fedorenko" __contact__ = 'https://github.com/DogsTailFarmer' ################################################################## @@ -38,6 +38,15 @@ O_DEC = Decimal() +def get_mode_details(mode): + mode_mapping = { + 'T': ("Trade", Style.B_WHITE), + 'TC': ("Trade & Collect", Style.B_RED), + 'S': ("Simulate", Style.GREEN) + } + return mode_mapping.get(mode, ("Unknown Mode", Style.RESET)) + + class Strategy(StrategyBase): def __init__(self, call_super=True): if call_super: @@ -167,9 +176,10 @@ def init(self, check_funds=True) -> None: self.message_log(f"Mode for {'Buy' if self.cycle_buy else 'Sell'} {self.f_currency} by grid orders" f" placement ON", color=Style.B_WHITE) - self.message_log(f"This is {'Trade' if MODE == 'T' else ('Trade & Collect' if MODE == 'TC' else 'Simulate')}" - f" mode", - color=Style.B_WHITE if MODE == 'T' else (Style.B_RED if MODE == 'TC' else Style.GREEN)) + + mode_message, mode_color = get_mode_details(MODE) + self.message_log(f"This is {mode_message} mode", color=mode_color) + if MODE == 'TC' and SELF_OPTIMIZATION: self.message_log("Auto update parameters mode!", log_level=logging.WARNING, color=Style.B_RED) # Calculate round float multiplier diff --git a/martin_binance/strategy_base.py b/martin_binance/strategy_base.py index 79123ad..da26662 100644 --- a/martin_binance/strategy_base.py +++ b/martin_binance/strategy_base.py @@ -4,7 +4,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.6.post1" +__version__ = "3.0.7" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" @@ -1031,6 +1031,7 @@ async def on_klines_update(self, _klines: {str: Klines}): async def create_limit_order(self, _id: int, buy: bool, amount: str, price: str) -> None: self.wait_order_id.append(_id) _fetch_order = False + msg = None try: if prm.MODE in ('T', 'TC'): ts = time.time() @@ -1059,26 +1060,30 @@ async def create_limit_order(self, _id: int, buy: bool, amount: str, price: str) except GRPCError as ex: status_code = ex.status if status_code == Status.FAILED_PRECONDITION: + self.message_log(f"Order {_id}: {status_code.name}, {ex.message}") if _id in self.wait_order_id: # Supress call strategy handler self.wait_order_id.remove(_id) else: _fetch_order = True - self.on_place_order_error(_id, f"{status_code.name}, {ex.message}") + msg = f"Create order {_id}: {status_code.name}, {ex.message}" except Exception as _ex: _fetch_order = True - self.message_log(f"Exception creating order {_id}: {_ex}") + msg = f"Exception creating order {_id}: {_ex}" else: if result: await self.create_order_handler(_id, result) else: _fetch_order = True + msg = f"Creating order {_id}: no result getting" finally: if prm.MODE in ('T', 'TC') and _fetch_order: await asyncio.sleep(HEARTBEAT) res = await self.fetch_order(0, str(_id), _filled_update_call=True) if res.get('status') in ('NEW', 'PARTIALLY_FILLED', 'FILLED'): await self.create_order_handler(_id, res) + else: + self.on_place_order_error(_id, msg) async def create_order_handler(self, _id, result): # print(f"create_order_handler.result: {result}") diff --git a/pyproject.toml b/pyproject.toml index 9fe9f42..422d551 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ dynamic = ["version", "description"] requires-python = ">=3.9" dependencies = [ - "exchanges-wrapper==2.1.11", + "exchanges-wrapper==2.1.12", "jsonpickle==3.0.2", "psutil==5.9.6", "requests==2.31.0", diff --git a/requirements.txt b/requirements.txt index dfabbfc..0be91d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -exchanges-wrapper==2.1.11 +exchanges-wrapper==2.1.12 jsonpickle==3.0.2 psutil==5.9.6 requests==2.31.0