From 3e9ae23aa718e841f997866da07c65ee63ba034c Mon Sep 17 00:00:00 2001 From: DogsTailFarmer Date: Fri, 1 Nov 2024 18:36:47 +0300 Subject: [PATCH] 3.0.16 --- CHANGELOG.md | 9 ++- martin_binance/__init__.py | 2 +- martin_binance/executor.py | 73 ++++++++++--------- martin_binance/params.py | 21 +++--- martin_binance/strategy_base.py | 5 +- martin_binance/templates/cli_0_BTCUSDT.py | 3 +- martin_binance/templates/cli_1_BTCUSDT.py | 3 +- .../templates/cli_2_TESTBTCTESTUSDT.py | 3 +- martin_binance/templates/cli_3_BTCUSDT.py | 3 +- 9 files changed, 68 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2cad43..10d6d3c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ -## 3.0.15- 2024-09-14 +## 3.0.16 - 2024-11-01 +### Fix +* Unnecessary restart when updating assets +* Add parameter `SAVE_ASSET`, to selectively suppress this [feature](https://github.com/DogsTailFarmer/martin-binance/wiki/How-it's-work#save-data-for-external-analytics) + +## 3.0.15 - 2024-09-14 ### Update * Up requirements for exchanges-wrapper==2.1.20 * Add `betterproto` to requirements -## 3.0.14- 2024-09-13 +## 3.0.14 - 2024-09-13 ### Fix * `pyproject.toml` diff --git a/martin_binance/__init__.py b/martin_binance/__init__.py index d87163c..60fce09 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.15" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" diff --git a/martin_binance/executor.py b/martin_binance/executor.py index 4534d21..8cf4b06 100644 --- 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.13post1" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = 'https://github.com/DogsTailFarmer' ################################################################## @@ -47,6 +47,7 @@ def get_mode_details(mode): return mode_mapping.get(mode, ("Unknown Mode", Style.RESET)) +# noinspection PyTypeChecker class Strategy(StrategyBase): def __init__(self, call_super=True): if call_super: @@ -674,7 +675,6 @@ def start(self, profit_f: Decimal = O_DEC, profit_s: Decimal = O_DEC) -> None: _ff = ff - profit_f _fs = fs if go_trade: - self.wait_refunding_for_start = False if MODE in ('T', 'TC') and not GRID_ONLY: if self.cycle_buy: df = O_DEC @@ -722,6 +722,7 @@ def start(self, profit_f: Decimal = O_DEC, profit_s: Decimal = O_DEC) -> None: self.message_log(f"Wait refunding for start, having now: first: {ff}, second: {fs}") return # + self.wait_refunding_for_start = False self.avg_rate = self.get_buffered_ticker().last_price if GRID_ONLY: if (START_ON_BUY and AMOUNT_FIRST and (ff >= AMOUNT_FIRST or fs < AMOUNT_SECOND)) \ @@ -761,40 +762,41 @@ def start(self, profit_f: Decimal = O_DEC, profit_s: Decimal = O_DEC) -> None: self.command = 'stopped' self.start_collect = 1 self.message_log('Stop, waiting manual action', tlg=True) + return + + self.message_log(f"Number of unreachable objects collected by GC: {gc.collect(generation=2)}") + if self.first_run or self.restart: + self.message_log(f"Initial first: {ff}, second: {fs}", color=Style.B_WHITE) + self.restart = None + # Init variable + self.profit_first = O_DEC + self.profit_second = O_DEC + self.over_price = OVER_PRICE + self.order_q = ORDER_Q + self.grid_update_started = None + # + start_cycle_output = not self.start_after_shift or self.first_run + if self.cycle_buy: + amount = self.deposit_second + if start_cycle_output: + self.message_log(f"Start Buy{' Reverse' if self.reverse else ''}" + f" {'asset' if GRID_ONLY else 'cycle'} with {amount} {self.s_currency} depo\n" + f"{'' if GRID_ONLY else self.get_free_assets(ff, fs, mode='free')[3]}", tlg=True) else: - self.message_log(f"Number of unreachable objects collected by GC: {gc.collect(generation=2)}") - if self.first_run or self.restart: - self.message_log(f"Initial first: {ff}, second: {fs}", color=Style.B_WHITE) - self.restart = None - # Init variable - self.profit_first = O_DEC - self.profit_second = O_DEC - self.over_price = OVER_PRICE - self.order_q = ORDER_Q - self.grid_update_started = None - # - start_cycle_output = not self.start_after_shift or self.first_run - if self.cycle_buy: - amount = self.deposit_second - if start_cycle_output: - self.message_log(f"Start Buy{' Reverse' if self.reverse else ''}" - f" {'asset' if GRID_ONLY else 'cycle'} with {amount} {self.s_currency} depo\n" - f"{'' if GRID_ONLY else self.get_free_assets(ff, fs, mode='free')[3]}", tlg=True) - else: - amount = self.deposit_first - if start_cycle_output: - self.message_log(f"Start Sell{' Reverse' if self.reverse else ''}" - f" {'asset' if GRID_ONLY else 'cycle'} with {amount} {self.f_currency} depo\n" - f"{'' if GRID_ONLY else self.get_free_assets(ff, fs, mode='free')[3]}", tlg=True) - # - if self.reverse: - self.message_log(f"For Reverse cycle target return amount: {self.reverse_target_amount}", - color=Style.B_WHITE) - self.debug_output() - if MODE in ('TC', 'S') and self.start_collect is None: - self.start_collect = True - self.first_run = False - self.place_grid(self.cycle_buy, amount, self.reverse_target_amount) + amount = self.deposit_first + if start_cycle_output: + self.message_log(f"Start Sell{' Reverse' if self.reverse else ''}" + f" {'asset' if GRID_ONLY else 'cycle'} with {amount} {self.f_currency} depo\n" + f"{'' if GRID_ONLY else self.get_free_assets(ff, fs, mode='free')[3]}", tlg=True) + # + if self.reverse: + self.message_log(f"For Reverse cycle target return amount: {self.reverse_target_amount}", + color=Style.B_WHITE) + self.debug_output() + if MODE in ('TC', 'S') and self.start_collect is None: + self.start_collect = True + self.first_run = False + self.place_grid(self.cycle_buy, amount, self.reverse_target_amount) def stop(self) -> None: self.message_log('Stop') @@ -2390,6 +2392,7 @@ def on_new_funds(self, funds: Dict[str, FundsEntry]) -> None: tf = ff.total_for_currency if ff else O_DEC go_trade = tf >= (self.initial_reverse_first if self.reverse else self.initial_first) if go_trade: + self.wait_refunding_for_start = False self.message_log("Started after receipt of funds") self.start() return diff --git a/martin_binance/params.py b/martin_binance/params.py index cca93e9..92b7431 100644 --- a/martin_binance/params.py +++ b/martin_binance/params.py @@ -4,7 +4,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.11" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" @@ -14,15 +14,15 @@ __all__ = [ 'SYMBOL', 'EXCHANGE', 'ID_EXCHANGE', 'FEE_MAKER', 'FEE_TAKER', 'FEE_FIRST', 'FEE_SECOND', 'FEE_BNB', - 'GRID_MAX_COUNT', 'START_ON_BUY', 'AMOUNT_FIRST', 'USE_ALL_FUND', 'AMOUNT_SECOND', 'PRICE_SHIFT', - 'PRICE_LIMIT_RULES', 'ROUND_BASE', 'ROUND_QUOTE', 'PROFIT', 'PROFIT_MAX', 'OVER_PRICE', 'ORDER_Q', 'MARTIN', - 'SHIFT_GRID_DELAY', 'GRID_UPDATE_INTERVAL', 'STATUS_DELAY', 'GRID_ONLY', 'LOG_LEVEL', 'HOLD_TP_ORDER_TIMEOUT', - 'COLLECT_ASSETS', 'GRID_ONLY_DELAY', 'ADAPTIVE_TRADE_CONDITION', 'BB_CANDLE_SIZE_IN_MINUTES', - 'BB_NUMBER_OF_CANDLES', 'KBB', 'LINEAR_GRID_K', 'ADX_CANDLE_SIZE_IN_MINUTES', 'ADX_NUMBER_OF_CANDLES', - 'ADX_PERIOD', 'ADX_THRESHOLD', 'ADX_PRICE_THRESHOLD', 'REVERSE', 'REVERSE_TARGET_AMOUNT', 'REVERSE_INIT_AMOUNT', - 'REVERSE_STOP', 'HEAD_VERSION', 'LOAD_LAST_STATE', 'LAST_STATE_FILE', 'VPS_NAME', 'PARAMS', 'TELEGRAM_URL', 'TOKEN', - 'CHANNEL_ID', 'STOP_TLG', 'INLINE_BOT', 'MODE', 'XTIME', 'SAVE_DS', 'SAVE_PERIOD', 'LOGGING', 'SELF_OPTIMIZATION', - 'N_TRIALS', 'SESSION_RESULT' + 'SAVE_ASSET', 'GRID_MAX_COUNT', 'START_ON_BUY', 'AMOUNT_FIRST', 'USE_ALL_FUND', 'AMOUNT_SECOND', + 'PRICE_SHIFT', 'PRICE_LIMIT_RULES', 'ROUND_BASE', 'ROUND_QUOTE', 'PROFIT', 'PROFIT_MAX', 'OVER_PRICE', 'ORDER_Q', + 'MARTIN', 'SHIFT_GRID_DELAY', 'GRID_UPDATE_INTERVAL', 'STATUS_DELAY', 'GRID_ONLY', 'LOG_LEVEL', + 'HOLD_TP_ORDER_TIMEOUT', 'COLLECT_ASSETS', 'GRID_ONLY_DELAY', 'ADAPTIVE_TRADE_CONDITION', + 'BB_CANDLE_SIZE_IN_MINUTES', 'BB_NUMBER_OF_CANDLES', 'KBB', 'LINEAR_GRID_K', 'ADX_CANDLE_SIZE_IN_MINUTES', + 'ADX_NUMBER_OF_CANDLES', 'ADX_PERIOD', 'ADX_THRESHOLD', 'ADX_PRICE_THRESHOLD', 'REVERSE', 'REVERSE_TARGET_AMOUNT', + 'REVERSE_INIT_AMOUNT', 'REVERSE_STOP', 'HEAD_VERSION', 'LOAD_LAST_STATE', 'LAST_STATE_FILE', 'VPS_NAME', 'PARAMS', + 'TELEGRAM_URL', 'TOKEN', 'CHANNEL_ID', 'STOP_TLG', 'INLINE_BOT', 'MODE', 'XTIME', 'SAVE_DS', 'SAVE_PERIOD', + 'LOGGING', 'SELF_OPTIMIZATION', 'N_TRIALS', 'SESSION_RESULT' ] SYMBOL = str() @@ -40,6 +40,7 @@ 'target_amount': '0', 'tranche_volume': '0' } +SAVE_ASSET = True GRID_MAX_COUNT = int() # Trade parameter START_ON_BUY = bool() diff --git a/martin_binance/strategy_base.py b/martin_binance/strategy_base.py index f753806..ab7dbf4 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.13" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" @@ -43,6 +43,7 @@ from martin_binance.client import Trade from martin_binance.lib import Candle, TradingCapabilityManager, Ticker, FundsEntry, OrderBook, Style, \ any2str, PrivateTrade, Order, convert_from_minute, OrderUpdate, load_file, load_last_state, Klines +from martin_binance.params import SAVE_ASSET if prm.MODE == 'S': logger = logging.getLogger('logger_S') @@ -1754,7 +1755,7 @@ async def main(self, _symbol): await self.wss_init() self.tasks_manage(save_to_csv()) self.tasks_manage(self.buffered_orders(), add_done_callback=False) - if self.session.client.real_market: + if self.session.client.real_market and SAVE_ASSET: self.tasks_manage(self.save_asset(), add_done_callback=False) if prm.MODE == 'TC': self.tasks_manage(self.backtest_control(), add_done_callback=False) diff --git a/martin_binance/templates/cli_0_BTCUSDT.py b/martin_binance/templates/cli_0_BTCUSDT.py index 6b4acb0..29eb418 100644 --- a/martin_binance/templates/cli_0_BTCUSDT.py +++ b/martin_binance/templates/cli_0_BTCUSDT.py @@ -7,7 +7,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.11" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" """ @@ -50,6 +50,7 @@ 'target_amount': '0', # BNB in USD equivalent, no less than min_notional 'tranche_volume': '0' # BNB in USD equivalent, no less than min_notional } +ex.SAVE_ASSET = True # Save account asset list and value in funds_rate.db ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders # Trade parameter ex.START_ON_BUY = True # First cycle direction diff --git a/martin_binance/templates/cli_1_BTCUSDT.py b/martin_binance/templates/cli_1_BTCUSDT.py index 6cc9744..eaef648 100644 --- a/martin_binance/templates/cli_1_BTCUSDT.py +++ b/martin_binance/templates/cli_1_BTCUSDT.py @@ -7,7 +7,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.11" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" """ @@ -50,6 +50,7 @@ 'target_amount': '0', # BNB in USD equivalent, no less than min_notional 'tranche_volume': '0' # BNB in USD equivalent, no less than min_notional } +ex.SAVE_ASSET = True # Save account asset list and value in funds_rate.db ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders # Trade parameter ex.START_ON_BUY = True # First cycle direction diff --git a/martin_binance/templates/cli_2_TESTBTCTESTUSDT.py b/martin_binance/templates/cli_2_TESTBTCTESTUSDT.py index afa3317..41b670d 100644 --- a/martin_binance/templates/cli_2_TESTBTCTESTUSDT.py +++ b/martin_binance/templates/cli_2_TESTBTCTESTUSDT.py @@ -7,7 +7,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.11" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" """ @@ -50,6 +50,7 @@ 'target_amount': '0', # BNB in USD equivalent, no less than min_notional 'tranche_volume': '0' # BNB in USD equivalent, no less than min_notional } +ex.SAVE_ASSET = True # Save account asset list and value in funds_rate.db ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders # Trade parameter ex.START_ON_BUY = True # First cycle direction diff --git a/martin_binance/templates/cli_3_BTCUSDT.py b/martin_binance/templates/cli_3_BTCUSDT.py index a4b9c43..86a5cb8 100755 --- a/martin_binance/templates/cli_3_BTCUSDT.py +++ b/martin_binance/templates/cli_3_BTCUSDT.py @@ -7,7 +7,7 @@ __author__ = "Jerry Fedorenko" __copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM" __license__ = "MIT" -__version__ = "3.0.11" +__version__ = "3.0.16" __maintainer__ = "Jerry Fedorenko" __contact__ = "https://github.com/DogsTailFarmer" """ @@ -50,6 +50,7 @@ 'target_amount': '0', # BNB in USD equivalent, no less than min_notional 'tranche_volume': '0' # BNB in USD equivalent, no less than min_notional } +ex.SAVE_ASSET = True # Save account asset list and value in funds_rate.db ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders # Trade parameter ex.START_ON_BUY = True # First cycle direction