Skip to content

Commit

Permalink
3.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed May 2, 2024
1 parent bc0ca3c commit c796d64
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 13 deletions.
15 changes: 15 additions & 0 deletions .run/martin-binance-image.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="martin-binance-image" type="docker-deploy" factoryName="dockerfile" editBeforeRun="true" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="martin-binance:latest" />
<option name="buildCliOptions" value="--network=host" />
<option name="buildOnly" value="true" />
<option name="containerName" value="" />
<option name="showCommandPreview" value="true" />
<option name="sourceFilePath" value="Dockerfile" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>
33 changes: 33 additions & 0 deletions .run/martin-binance.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="exchanges-wrapper" type="docker-deploy" factoryName="docker-image" editBeforeRun="true" server-name="Docker">
<deployment type="docker-image">
<settings>
<option name="imageTag" value="ghcr.io/dogstailfarmer/exchanges-wrapper:latest" />
<option name="containerName" value="exchanges-wrapper" />
<option name="commandLineOptions" value="-i -t -P" />
<option name="showCommandPreview" value="true" />
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="$PROJECT_DIR$/../../../appuser/.MartinBinance" />
<option name="hostPath" value="$USER_HOME$/.MartinBinance" />
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2" />
</configuration>
<configuration default="false" name="martin-binance" type="docker-deploy" factoryName="docker-image" editBeforeRun="true" server-name="Docker">
<deployment type="docker-image">
<settings>
<option name="imageTag" value="martin-binance:last" />
<option name="command" value="$PROJECT_DIR$/../../../appuser/.MartinBinance/cli_7_BTCUSDT.py" />
<option name="containerName" value="7-BTCUSDT" />
<option name="commandLineOptions" value="-i -t -P --mount type=bind,source=$USER_HOME$/.MartinBinance,target=$PROJECT_DIR$/../../../appuser/.MartinBinance --network=host" />
<option name="showCommandPreview" value="true" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion martin_binance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 5 additions & 1 deletion martin_binance/backtest/optimizer.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 14 additions & 4 deletions martin_binance/executor.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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'
##################################################################
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions martin_binance/strategy_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c796d64

Please sign in to comment.