Skip to content

Commit

Permalink
3.0.1rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Mar 19, 2024
1 parent 893ba25 commit b51f242
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 129 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
## 3.0.0rc21 - 2024-03-13
## 3.0.1rc1 - 2024-03-19
### Fix
* Cyclic Backtesting workflow

### Update
* Up requirements for exchanges-wrapper==2.1.2


## 3.0.0rc22 - 2024-03-13
### Fix
* `Analytics`: Refine unload and processing assets data

### Update
* Up requirements for exchanges-wrapper==2.1.0

## 3.0.0rc20 - 2024-03-12
### Fix
* `cancel_order_call()`: incorrect using asyncio.wait_for()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ All risks and possible losses associated with use of this strategy lie with you.
Strongly recommended that you test the strategy in the demo mode before using real bidding.

## Important notices
* After update to `3.0.0`, the configuration files `cli_XX_AAABBB.py` for all running trading pairs
* After update to `3.0.1`, the configuration files `cli_XX_AAABBB.py` for all running trading pairs
should be updated. Use templates for reference.

* You cannot run multiple pairs with overlapping currencies on the same account!
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.0rc21"
__version__ = "3.0.1rc1"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down
3 changes: 2 additions & 1 deletion martin_binance/backtest/OoTSP.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.1rc1"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down Expand Up @@ -67,6 +67,7 @@ def main():
print_study_result(study)
print(f"Study instance saved to {storage_name} for later use")
elif answers.get('mode') == 'Analise saved study session':
# noinspection PyArgumentList
study = optuna.load_study(study_name=study_name, storage=storage_name)

print(f"Best value: {study.best_value}")
Expand Down
50 changes: 33 additions & 17 deletions martin_binance/backtest/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__author__ = "Jerry Fedorenko"
__copyright__ = "Copyright © 2024 Jerry Fedorenko aka VM"
__license__ = "MIT"
__version__ = "3.0.0rc4"
__version__ = "3.0.1rc1"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down Expand Up @@ -49,8 +49,9 @@ def try_trade(mbs, skip_log, **kwargs):
return float(mbs.ex.SESSION_RESULT.get('profit', 0)) + float(mbs.ex.SESSION_RESULT.get('free', 0))


def optimize(study_name, cli, n_trials, storage_name=None, skip_log=True, show_progress_bar=False):
def optimize(study_name, cli, n_trials, storage_name=None, prm_best=None, skip_log=True, show_progress_bar=False):
sys.excepthook = notify_exception
optuna.logging.set_verbosity(optuna.logging.WARNING)

def objective(_trial):
params = {
Expand All @@ -70,12 +71,13 @@ def objective(_trial):
spec = iu.spec_from_file_location("strategy", cli)
mbs = iu.module_from_spec(spec)
spec.loader.exec_module(mbs)
optuna.logging.set_verbosity(optuna.logging.WARNING)
_study = optuna.create_study(study_name=study_name, storage=storage_name, direction="maximize")
try:
_study.optimize(objective, n_trials=n_trials, gc_after_trial=True, show_progress_bar=show_progress_bar)
except KeyboardInterrupt:
pass # ignore

if prm_best:
logger.info(f"Previous best params: {prm_best}")
_study.enqueue_trial(prm_best)

_study.optimize(objective, n_trials=n_trials, gc_after_trial=True, show_progress_bar=show_progress_bar)
return _study


Expand All @@ -90,18 +92,32 @@ async def run_optimize(*args):
logger.level = logging.INFO
formatter = logging.Formatter(fmt="[%(asctime)s: %(levelname)s] %(message)s")
#
fh = logging.handlers.RotatingFileHandler(Path(LOG_PATH, sys.argv[5]), maxBytes=500000, backupCount=5)
fh = logging.handlers.RotatingFileHandler(Path(LOG_PATH, sys.argv[6]), maxBytes=500000, backupCount=5)
fh.setFormatter(formatter)
fh.setLevel(logging.INFO)
logger.addHandler(fh)
#
study = optimize(sys.argv[1], sys.argv[2], int(sys.argv[3]), storage_name=sys.argv[4])
logger.info(f"Optimal parameters: {study.best_params} for get {study.best_value}")
new_value = study.best_value
_value = study.get_trials()[0].value
if new_value > _value:
res = study.best_params
res |= {'new_value': any2str(new_value), '_value': any2str(_value)}
print(json.dumps(res))
prm_best = None
try:
prm_best = json.loads(sys.argv[5])
study = optimize(
sys.argv[1],
sys.argv[2],
int(sys.argv[3]),
storage_name=sys.argv[4],
prm_best=prm_best
)
except KeyboardInterrupt:
pass # ignore
except Exception as ex:
logger.info(f"optimizer: {ex}")
else:
print(json.dumps({}))
logger.info(f"Optimal parameters: {study.best_params} for get {study.best_value}")
new_value = study.best_value
_value = study.get_trials()[0].value
if new_value > _value or not prm_best:
res = study.best_params
res |= {'new_value': any2str(new_value), '_value': any2str(_value)}
print(json.dumps(res))
else:
print(json.dumps({}))
9 changes: 3 additions & 6 deletions martin_binance/cli_0_BTCUSDT.py.template
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.0"
__version__ = "3.0.1"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"
"""
Expand Down Expand Up @@ -37,11 +37,10 @@ import martin_binance.params as ex
ex.SYMBOL = 'BTCUSDT'
# Exchange setup, see list of exchange in ms_cfg.toml
ex.ID_EXCHANGE = 0 # See ms_cfg.toml Use for collection of statistics *and get client connection*
ex.FEE_IN_PAIR = True # Fee pays in pair
ex.FEE_MAKER = Decimal('0.1') # standard exchange Fee for maker
ex.FEE_TAKER = Decimal('0.1') # standard exchange Fee for taker
ex.FEE_SECOND = False # On KRAKEN fee always in second coin
ex.FEE_BNB_IN_PAIR = False # Binance fee in BNB and BNB is base asset
ex.FEE_FIRST = False # For example fee in BNB and BNB in pair, and it is base asset
ex.FEE_SECOND = False # For example fee in BNB and BNB in pair, and it is quote asset
ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders
# Trade parameter
ex.START_ON_BUY = True # First cycle direction
Expand Down Expand Up @@ -147,8 +146,6 @@ def trade(strategy=None):
except Exception as _err:
print(f"Error: {_err}")
loop.run_until_complete(loop.shutdown_asyncgens())
if ex.MODE in ('T', 'TC'):
loop.close()
return strategy


Expand Down
11 changes: 4 additions & 7 deletions martin_binance/cli_1_BTCUSDT.py.template
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.0"
__version__ = "3.0.1"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"
"""
Expand Down Expand Up @@ -37,12 +37,11 @@ import martin_binance.params as ex
ex.SYMBOL = 'BTCUSDT'
# Exchange setup, see list of exchange in ms_cfg.toml
ex.ID_EXCHANGE = 1 # See ms_cfg.toml Use for collection of statistics *and get client connection*
ex.FEE_IN_PAIR = True # Fee pays in pair
ex.FEE_MAKER = Decimal('0.08') # standard exchange Fee for maker
ex.FEE_TAKER = Decimal('0.1') # standard exchange Fee for taker
ex.FEE_SECOND = False # On KRAKEN fee always in second coin
ex.FEE_BNB_IN_PAIR = False # Binance fee in BNB and BNB is base asset
ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders
ex.FEE_FIRST = False # For example fee in BNB and BNB in pair, and it is base asset
ex.FEE_SECOND = False # For example fee in BNB and BNB in pair, and it is quote asset
ex.GRID_MAX_COUNT = 3 # Maximum counts for placed grid orders
# Trade parameter
ex.START_ON_BUY = True # First cycle direction
ex.AMOUNT_FIRST = Decimal('0.05') # Deposit for Sale cycle in first currency
Expand Down Expand Up @@ -147,8 +146,6 @@ def trade(strategy=None):
except Exception as _err:
print(f"Error: {_err}")
loop.run_until_complete(loop.shutdown_asyncgens())
if ex.MODE in ('T', 'TC'):
loop.close()
return strategy


Expand Down
9 changes: 3 additions & 6 deletions martin_binance/cli_2_TESTBTCTESTUSDT.py.template
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.0"
__version__ = "3.0.1"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"
"""
Expand Down Expand Up @@ -37,11 +37,10 @@ import martin_binance.params as ex
ex.SYMBOL = 'TESTBTCTESTUSDT'
# Exchange setup, see list of exchange in ms_cfg.toml
ex.ID_EXCHANGE = 2 # See ms_cfg.toml Use for collection of statistics *and get client connection*
ex.FEE_IN_PAIR = True # Fee pays in pair
ex.FEE_MAKER = Decimal('0.1') # standard exchange Fee for maker
ex.FEE_TAKER = Decimal('0.17') # standard exchange Fee for taker
ex.FEE_SECOND = False # On KRAKEN fee always in second coin
ex.FEE_BNB_IN_PAIR = False # Binance fee in BNB and BNB is base asset
ex.FEE_FIRST = False # For example fee in BNB and BNB in pair, and it is base asset
ex.FEE_SECOND = False # For example fee in BNB and BNB in pair, and it is quote asset
ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders
# Trade parameter
ex.START_ON_BUY = True # First cycle direction
Expand Down Expand Up @@ -147,8 +146,6 @@ def trade(strategy=None):
except Exception as _err:
print(f"Error: {_err}")
loop.run_until_complete(loop.shutdown_asyncgens())
if ex.MODE in ('T', 'TC'):
loop.close()
return strategy


Expand Down
11 changes: 4 additions & 7 deletions martin_binance/cli_3_BTCUSDT.py.template
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.0"
__version__ = "3.0.1"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"
"""
Expand Down Expand Up @@ -37,11 +37,10 @@ import martin_binance.params as ex
ex.SYMBOL = 'BTCUSDT'
# Exchange setup, see list of exchange in ms_cfg.toml
ex.ID_EXCHANGE = 3 # See ms_cfg.toml Use for collection of statistics *and get client connection*
ex.FEE_IN_PAIR = True # Fee pays in pair
ex.FEE_MAKER = Decimal('0.1') # standard exchange Fee for maker
ex.FEE_TAKER = Decimal('0.15') # standard exchange Fee for taker
ex.FEE_SECOND = False # On KRAKEN fee always in second coin
ex.FEE_BNB_IN_PAIR = False # Binance fee in BNB and BNB is base asset
ex.FEE_FIRST = False # For example fee in BNB and BNB in pair, and it is base asset
ex.FEE_SECOND = False # For example fee in BNB and BNB in pair, and it is quote asset
ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders
# Trade parameter
ex.START_ON_BUY = True # First cycle direction
Expand Down Expand Up @@ -70,7 +69,7 @@ ex.COLLECT_ASSETS = False # Transfer free asset to main account, valid for suba
ex.ADAPTIVE_TRADE_CONDITION = True
ex.BB_CANDLE_SIZE_IN_MINUTES = 60
ex.BB_NUMBER_OF_CANDLES = 20
ex.KBB = 1.0 # k for Bollinger Band
ex.KBB = 2.0 # k for Bollinger Band
# Parameter for calculate price of grid orders by logarithmic scale
# If -1 function is disabled, can take a value from 0 to infinity (in practice no more 1000)
# When 0 - logarithmic scale, increase parameter the result is approaching linear
Expand Down Expand Up @@ -147,8 +146,6 @@ def trade(strategy=None):
except Exception as _err:
print(f"Error: {_err}")
loop.run_until_complete(loop.shutdown_asyncgens())
if ex.MODE in ('T', 'TC'):
loop.close()
return strategy


Expand Down
21 changes: 9 additions & 12 deletions martin_binance/client.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.0rc7"
__version__ = "3.0.0rc22"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand All @@ -14,6 +14,7 @@

import grpclib.exceptions
import shortuuid
import traceback

from exchanges_wrapper import martin as mr, Channel, Status, GRPCError

Expand Down Expand Up @@ -90,24 +91,20 @@ async def send_request(self, _request, _request_type, **kwargs):
except asyncio.CancelledError:
pass # Task cancellation should not be logged as an error
except grpclib.exceptions.StreamTerminatedError:
logger.warning("Have not connection to gRPC server")
raise UserWarning("Have not connection to gRPC server")
except ConnectionRefusedError as ex:
raise UserWarning("Connection to gRPC server broken")
except GRPCError as ex:
status_code = ex.status
if (
(status_code == Status.UNAVAILABLE
and 'failed to connect to all addresses' in ex.message)
or
(status_code == Status.UNKNOWN
and "No client exist" in ex.message)
):
if status_code == Status.UNAVAILABLE:
self.client = None
raise UserWarning(
"Connection to gRPC server failed, wait connection..."
) from ex
if status_code == Status.RESOURCE_EXHAUSTED:
raise
logger.debug(f"Exception on send request {_request}: {status_code.name}, {ex.message}")
logger.debug(f"Send request {_request}: {status_code.name}, {ex.message}")
raise
except Exception as ex:
logger.error(f"Exception on send request {ex}")
else:
if res is None:
self.client = None
Expand Down
Loading

0 comments on commit b51f242

Please sign in to comment.