diff --git a/martin_binance/__init__.py b/martin_binance/__init__.py index e1d7451..c15a37c 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.0rc15" +__version__ = "3.0.0rc16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" diff --git a/martin_binance/executor.py b/martin_binance/executor.py index 654b555..7de1039 100755 --- a/martin_binance/executor.py +++ b/martin_binance/executor.py @@ -101,6 +101,7 @@ def __init__(self): self.last_ticker_update = 0 # - self.martin = Decimal(0) # + Operational increment volume of orders in the grid self.order_q = None # + Adaptive order quantity + # TODO Change on func calc active orders num self.order_q_placed = False # - Flag initial number of orders placed self.over_price = None # + Adaptive over price self.pr_db = None # - Process for save data to .db @@ -140,7 +141,9 @@ def init(self, check_funds: bool = True) -> None: # skipcq: PYL-W0221 self.message_log(f"Incorrect value for {init_params_error}", log_level=logging.ERROR) raise SystemExit(1) if MODE == 'S': - self.sum_profit_first = self.sum_profit_second = self.profit_first = self.profit_second = O_DEC + self.profit_first = self.profit_second = O_DEC + self.sum_profit_first = self.sum_profit_second = O_DEC + self.part_profit_first = self.part_profit_second = O_DEC else: db_management(EXCHANGE) tcm = self.get_trading_capability_manager() @@ -527,16 +530,8 @@ def restore_strategy_state(self, strategy_state: Dict[str, str] = None, restore= self.avg_rate = self.get_buffered_ticker().last_price # open_orders = self.get_buffered_open_orders() - tp_order = None - # Separate TP order - if self.tp_order_id: - for i, o in enumerate(open_orders): - if o.id == self.tp_order_id: - tp_order = open_orders[i] - del open_orders[i] # skipcq: PYL-E1138 - break # Possible strategy states in compare with saved one - grid_open_orders_len = len(open_orders) + grid_open_orders_len = len(open_orders) - 1 if self.tp_order_id else 0 # if not grid_open_orders_len and self.orders_hold: self.message_log("Restore, no grid orders, place from hold now", tlg=True) @@ -544,7 +539,7 @@ def restore_strategy_state(self, strategy_state: Dict[str, str] = None, restore= elif not self.orders_grid and not self.orders_hold and not self.orders_save and not self.tp_order_id: self.message_log("Restore, Restart", tlg=True) self.start() - if not GRID_ONLY and self.shift_grid_threshold is None and not tp_order: + if not GRID_ONLY and self.shift_grid_threshold is None and not self.tp_order_id: self.message_log("Restore, no TP order, replace", tlg=True) self.place_profit_order() # @@ -1181,7 +1176,7 @@ def place_grid(self, # self.start_after_shift = False if self.grid_update_started: - self.grid_place_flag = None + self.grid_place_flag = False self.grid_update_started = None else: self.grid_hold = {'buy_side': buy_side, @@ -2072,7 +2067,7 @@ def cancel_grid(self, cancel_all=False): self.orders_save.orders_list.clear() self.orders_hold.orders_list.clear() self.grid_remove = None - self.order_q_placed = None + self.order_q_placed = False if self.tp_was_filled: self.grid_update_started = None self.after_filled_tp(one_else_grid=False) diff --git a/martin_binance/strategy_base.py b/martin_binance/strategy_base.py index 22b700e..cd267c9 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.0rc15" +__version__ = "3.0.0rc16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" @@ -15,6 +15,7 @@ import queue import os import random +import shutil import sqlite3 import time import traceback @@ -418,6 +419,7 @@ def session_data_handler(self): df_grid_buy.index = pd.to_datetime(df_grid_buy.index, unit='ms') df_grid_buy.to_pickle(Path(session_data, "buy.pkl")) + shutil.make_archive(str(Path(self.session_root, "raw_bak")), 'zip', self.session_root, 'raw') self.message_log(f"Stream data for backtesting saved to {self.session_root}") def parquet_declare(self, raw_path): @@ -432,8 +434,6 @@ def parquet_declare(self, raw_path): raw_path, f"candles_{i.value}.parquet"), schema=schema ) - ### - def back_test_handler(self): # Test result handler s_profit = prm.SESSION_RESULT['profit'] = f"{self.get_sum_profit()}" @@ -1588,7 +1588,15 @@ async def main(self, _symbol): self.start_time_ms = json.loads( last_state.pop('ms_start_time_ms', str(int(time.time() * 1000))) ) - self.orders = jsonpickle.decode(last_state.pop(MS_ORDERS, '{}'), keys=True) + + # TODO Replace after update + # self.orders = jsonpickle.decode(last_state.pop(MS_ORDERS, '{}'), keys=True) + + _orders = last_state.pop(MS_ORDERS, '{}') + _orders = _orders.replace('margin_wrapper', 'lib') + self.orders = jsonpickle.decode(_orders, keys=True) + # + orders_keys = self.orders.keys() for _id in exch_orders_ids: if _id not in orders_keys: diff --git a/pyproject.toml b/pyproject.toml index 67de48c..b6f7f80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ dynamic = ["version", "description"] requires-python = ">=3.9" dependencies = [ - "exchanges-wrapper==2.0.0", + "exchanges-wrapper==2.0.0.post1", "jsonpickle==3.0.2", "psutil==5.9.6", "requests==2.31.0", diff --git a/requirements.txt b/requirements.txt index 98b6fe3..e0d11aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -exchanges-wrapper==2.0.0 +exchanges-wrapper==2.0.0.post1 jsonpickle==3.0.2 psutil==5.9.6 requests==2.31.0