Skip to content

Commit

Permalink
2.1.0rc29
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Feb 9, 2024
1 parent 733109f commit b69f6e0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.0rc29 - 2024-02-09
### Update
* `check_min_amount()`: refine check min trade amount for SELL cycle
* Up requirements for exchanges-wrapper==1.4.10

## 2.1.0rc28 - 2024-02-07
### Update
* Up requirements for exchanges-wrapper==1.4.9
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__ = "2.1.0rc28"
__version__ = "2.1.0rc29"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down
2 changes: 1 addition & 1 deletion martin_binance/backtest/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def objective(_trial):
try:
_study.optimize(objective, n_trials=n_trials, gc_after_trial=True, show_progress_bar=show_progress_bar)
except KeyboardInterrupt:
pass
pass # ignore
return _study


Expand Down
27 changes: 18 additions & 9 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__ = "2.1.0rc27"
__version__ = "2.1.0rc29"
__maintainer__ = "Jerry Fedorenko"
__contact__ = 'https://github.com/DogsTailFarmer'
##################################################################
Expand Down Expand Up @@ -1794,14 +1794,16 @@ def set_profit(self, amount: Decimal, by_market: bool) -> Decimal:
profit = PROFIT + fee
return profit.quantize(Decimal("1.0123"), rounding=ROUND_CEILING)

def calc_profit_order(self, buy_side: bool, by_market: bool = False) -> Dict[str, Decimal]:
def calc_profit_order(self, buy_side: bool, by_market=False, out=True) -> Dict[str, Decimal]:
"""
Calculation based on amount value
:param buy_side: for take profit order, inverse to current cycle
:param by_market:
:param out:
:return:
"""
self.message_log(f"calc_profit_order: buy_side: {buy_side}, by_market: {by_market}", LogLevel.DEBUG)
if out:
self.message_log(f"calc_profit_order: buy_side: {buy_side}, by_market: {by_market}", LogLevel.DEBUG)
tcm = self.get_trading_capability_manager()
step_size_f = tcm.get_minimal_amount_change()
if buy_side:
Expand Down Expand Up @@ -1831,9 +1833,10 @@ def calc_profit_order(self, buy_side: bool, by_market: bool = False) -> Dict[str
target = amount * price
# Calc real margin for TP
profit = (100 * (target - self.tp_amount) / self.tp_amount).quantize(Decimal("1.0123"), rounding=ROUND_FLOOR)
self.message_log(f"calc_profit_order: Initial depo for TP: {self.tp_amount},"
f" target {'first' if buy_side else 'second'}: {target}",
log_level=LogLevel.DEBUG)
if out:
self.message_log(f"calc_profit_order: Initial depo for TP: {self.tp_amount},"
f" target {'first' if buy_side else 'second'}: {target}",
log_level=LogLevel.DEBUG)
return {'price': price, 'amount': amount, 'profit': profit, 'target': target}

def calc_over_price(self,
Expand Down Expand Up @@ -2394,7 +2397,7 @@ def cancel_grid(self, cancel_all=False):
else:
self.grid_remove = None

def check_min_amount(self, amount=O_DEC, price=O_DEC, for_tp=True) -> bool:
def check_min_amount(self, amount=O_DEC, price=O_DEC, for_tp=True, by_market=False) -> bool:
_price = price or self.avg_rate
if not _price:
return False
Expand All @@ -2407,7 +2410,13 @@ def check_min_amount(self, amount=O_DEC, price=O_DEC, for_tp=True) -> bool:
else:
min_trade_amount = tcm.get_min_buy_amount(_price)
if not _amount:
_amount = (self.sum_amount_second / _price) if for_tp else self.deposit_first
if for_tp:
_tp = self.calc_profit_order(not self.cycle_buy, by_market=by_market, out=False)
if _tp['target'] * _tp['price'] < tcm.min_notional:
return False
_amount = _tp['amount']
else:
_amount = self.deposit_first
_amount = self.round_truncate(_amount, base=True)
return _amount >= min_trade_amount

Expand Down Expand Up @@ -2737,7 +2746,7 @@ def on_order_update(self, update: OrderUpdate) -> None:
self.initial_second += amount_second_fee
else:
# Get min trade amount
if self.check_min_amount():
if self.check_min_amount(by_market=by_market):
self.shift_grid_threshold = None
self.grid_handler(by_market=by_market, after_full_fill=False)
else:
Expand Down
4 changes: 2 additions & 2 deletions 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==1.4.9",
"exchanges-wrapper==1.4.10",
"margin-strategy-sdk==0.0.11",
"jsonpickle==3.0.2",
"psutil==5.9.6",
Expand All @@ -28,7 +28,7 @@ dependencies = [
"optuna==3.4.0",
"plotly==5.18.0",
"pandas==2.1.2",
"dash==2.14.1",
"dash>=2.15.0",
"future==0.18.3",
"inquirer==3.1.3",
"scikit-learn==1.3.2",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exchanges-wrapper==1.4.9
exchanges-wrapper==1.4.10
margin-strategy-sdk==0.0.11
jsonpickle==3.0.2
psutil==5.9.6
Expand All @@ -9,7 +9,7 @@ prometheus-client==0.18.0
optuna==3.4.0
plotly==5.18.0
pandas==2.1.2
dash==2.14.1
dash>=2.15.0
future==0.18.3
inquirer==3.1.3
scikit-learn==1.3.2
Expand Down

0 comments on commit b69f6e0

Please sign in to comment.