Skip to content

Commit

Permalink
3.0.0rc16
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Mar 10, 2024
1 parent 4d8dae8 commit eb31668
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
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.0rc15"
__version__ = "3.0.0rc16"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down
21 changes: 8 additions & 13 deletions martin_binance/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -527,24 +530,16 @@ 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)
self.place_grid_part()
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()
#
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 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.0rc15"
__version__ = "3.0.0rc16"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand All @@ -15,6 +15,7 @@
import queue
import os
import random
import shutil
import sqlite3
import time
import traceback
Expand Down Expand Up @@ -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):
Expand All @@ -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()}"
Expand Down Expand Up @@ -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:
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.0.0",
"exchanges-wrapper==2.0.0.post1",
"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.0.0
exchanges-wrapper==2.0.0.post1
jsonpickle==3.0.2
psutil==5.9.6
requests==2.31.0
Expand Down

0 comments on commit eb31668

Please sign in to comment.