Skip to content

Commit

Permalink
3.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Nov 1, 2024
1 parent d8da227 commit 3e9ae23
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 54 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`

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.15"
__version__ = "3.0.16"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down
73 changes: 38 additions & 35 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.13post1"
__version__ = "3.0.16"
__maintainer__ = "Jerry Fedorenko"
__contact__ = 'https://github.com/DogsTailFarmer'
##################################################################
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) \
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions martin_binance/params.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.11"
__version__ = "3.0.16"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand All @@ -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()
Expand All @@ -40,6 +40,7 @@
'target_amount': '0',
'tranche_volume': '0'
}
SAVE_ASSET = True
GRID_MAX_COUNT = int()
# Trade parameter
START_ON_BUY = bool()
Expand Down
5 changes: 3 additions & 2 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.13"
__version__ = "3.0.16"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion martin_binance/templates/cli_0_BTCUSDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion martin_binance/templates/cli_1_BTCUSDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion martin_binance/templates/cli_2_TESTBTCTESTUSDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion martin_binance/templates/cli_3_BTCUSDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e9ae23

Please sign in to comment.