Skip to content

Commit

Permalink
3.0.0rc17
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Mar 10, 2024
1 parent eb31668 commit 4ecf887
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.0.0rc17 - 2024-03-10
### Update
* Refine grid orders control

### Added for new features
* `Backtesting`: save session collected date to `session_root/raw_bak.zip`

## 3.0.0rc14 - 2024-03-09
### Update
* Up requirements for exchanges-wrapper==2.0.0
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.0rc16"
__version__ = "3.0.0rc17"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down
48 changes: 14 additions & 34 deletions martin_binance/executor.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.0rc12"
__version__ = "3.0.0rc17"
__maintainer__ = "Jerry Fedorenko"
__contact__ = 'https://github.com/DogsTailFarmer'

Expand Down Expand Up @@ -94,15 +94,12 @@ def __init__(self):
self.cycle_time_reverse = None # + Reverse cycle start time
self.first_run = True # -
self.grid_only_restart = None # -
self.grid_place_flag = False # - Flag when placed next part of grid orders
self.grid_remove = None # - Flag when starting cancel grid orders
self.grid_update_started = None # - Flag when grid update process started
self.heartbeat_counter = 0 # -
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
self.pr_tlg = None # - Process for sending message to Telegram
Expand Down Expand Up @@ -554,8 +551,6 @@ def start(self, profit_f: Decimal = O_DEC, profit_s: Decimal = O_DEC) -> None:
self.tp_order_hold.clear()
self.tp_hold = False
self.tp_was_filled = ()
self.order_q_placed = False
self.grid_place_flag = False
if self.tp_order_id:
self.tp_cancel = True
if not self.cancel_order_id:
Expand Down Expand Up @@ -1176,7 +1171,6 @@ def place_grid(self,
#
self.start_after_shift = False
if self.grid_update_started:
self.grid_place_flag = False
self.grid_update_started = None
else:
self.grid_hold = {'buy_side': buy_side,
Expand Down Expand Up @@ -1831,16 +1825,13 @@ def reverse_after_grid_ending(self):
self.start(profit_f, profit_s)

def place_grid_part(self) -> None:
if not self.grid_remove:
self.grid_place_flag = True
if self.orders_hold and not self.orders_init and not self.grid_remove:
n = len(self.orders_grid) + len(self.orders_init)
if n < ORDER_Q:
self.message_log(f"Place next part of grid orders, hold {len(self.orders_hold)}", color=Style.B_WHITE)
k = 0
for i in self.orders_hold:
if k == GRID_MAX_COUNT or k + n >= ORDER_Q:
if k + n >= ORDER_Q:
self.order_q_placed = True
break
waiting_order_id = self.place_limit_order_check(
i['buy'],
Expand All @@ -1855,6 +1846,11 @@ def place_grid_part(self) -> None:
else:
break
del self.orders_hold.orders_list[:k]
if self.orders_hold:
self.message_log(f"Part of grid orders are placed. Left: {len(self.orders_hold)}",
color=Style.B_WHITE)
else:
self.message_log('All grid orders place successfully', color=Style.B_WHITE)

def grid_only_stop(self) -> None:
tcm = self.get_trading_capability_manager()
Expand Down Expand Up @@ -1944,8 +1940,7 @@ def grid_handler(
self.reverse_after_grid_ending()
else:
self.restore_orders_fire()
if after_full_fill and self.orders_hold and self.order_q_placed and not self.grid_remove:
# PLace one hold grid order and remove it from hold list
if after_full_fill:
self.place_grid_part()
if self.tp_was_filled:
# Exist filled but non processing TP
Expand Down Expand Up @@ -2067,7 +2062,6 @@ 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 = False
if self.tp_was_filled:
self.grid_update_started = None
self.after_filled_tp(one_else_grid=False)
Expand Down Expand Up @@ -2486,33 +2480,20 @@ def on_place_order_success(self, place_order_id: int, order: Order) -> None:
self.orders_init.remove(place_order_id)
if not self.orders_init:
self.last_shift_time = self.get_time()
if GRID_ONLY and self.orders_hold:
# Place next part of grid orders
if self.cancel_grid_hold:
self.message_log('Continue remove grid orders', color=Style.B_WHITE)
self.cancel_grid_hold = False
self.cancel_grid()
elif GRID_ONLY or not self.shift_grid_threshold:
self.place_grid_part()
else:
if self.grid_place_flag or not self.orders_hold:
if self.orders_hold:
self.message_log(f"Part of grid orders are placed. Left: {len(self.orders_hold)}",
color=Style.B_WHITE)
else:
self.order_q_placed = True
self.message_log('All grid orders place successfully', color=Style.B_WHITE)
elif not self.order_q_placed and not self.shift_grid_threshold:
self.place_grid_part()
if self.cancel_grid_hold:
self.message_log('Continue remove grid orders', color=Style.B_WHITE)
self.cancel_grid_hold = False
self.cancel_grid()
elif place_order_id == self.tp_wait_id:
self.tp_wait_id = None
self.tp_order_id = order.id
if self.tp_hold or self.tp_cancel or self.tp_cancel_from_grid_handler:
self.cancel_order_id = self.tp_order_id
self.cancel_order(self.tp_order_id)
else:
# Place next part of grid orders
if self.orders_hold and not self.order_q_placed and not self.orders_init:
self.place_grid_part()
self.place_grid_part()
else:
self.message_log(f"Did not have waiting order id for {place_order_id}", logging.ERROR)

Expand Down Expand Up @@ -2571,7 +2552,6 @@ def on_cancel_order_success(self, order_id: int, cancel_all=False) -> None:
self.restore_orders = False
self.orders_hold.sort(self.cycle_buy)
self.grid_remove = None
self.order_q_placed = False
self.place_profit_order()
elif self.grid_remove:
self.cancel_grid(cancel_all=cancel_all)
Expand Down

0 comments on commit 4ecf887

Please sign in to comment.