Skip to content

Commit

Permalink
Better formula
Browse files Browse the repository at this point in the history
Using the scout margin,
- the bot performs more consistently when trade fees vary.
- Easy to understand.
- Fixes instant/unnecessary trade bug.
- ratio_dict will also represent which coins are closest to trading.
  • Loading branch information
bamooxa authored and edeng23 committed Nov 13, 2021
1 parent 7b5a5d4 commit 57df16f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .user.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ current_coin=
bridge=USDT
tld=com
hourToKeepScoutHistory=1
use_margin=no
scout_multiplier=5
scout_margin=0.8
scout_sleep_time=1
strategy=default
buy_timeout=0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ Create a .cfg file named `user.cfg` based off `.user.cfg.example`, then add your
- **tld** - 'com' or 'us', depending on your region. Default is 'com'.
- **hourToKeepScoutHistory** - Controls how many hours of scouting values are kept in the database. After the amount of time specified has passed, the information will be deleted.
- **scout_sleep_time** - Controls how many seconds are waited between each scout.
- **use_margin** - 'yes' to use scout_margin. 'no' to use scout_multiplier.
- **scout_multiplier** - Controls the value by which the difference between the current state of coin ratios and previous state of ratios is multiplied. For bigger values, the bot will wait for bigger margins to arrive before making a trade.
- **scout_margin** - Minimum percentage coin gain per trade. 0.8 translates to a scout multiplier of 5 at 0.1% fee.
- **strategy** - The trading strategy to use. See [`binance_trade_bot/strategies`](binance_trade_bot/strategies/README.md) for more information
- **buy_timeout/sell_timeout** - Controls how many minutes to wait before cancelling a limit order (buy/sell) and returning to "scout" mode. 0 means that the order will never be cancelled prematurely.
- **scout_sleep_time** - Controls how many seconds bot should wait between analysis of current prices. Since the bot now operates on websockets this value should be set to something low (like 1), the reasons to set it above 1 are when you observe high CPU usage by bot or you got api errors about requests weight limit.
Expand Down
20 changes: 13 additions & 7 deletions binance_trade_bot/auto_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ def _get_ratios(self, coin: Coin, coin_price):
# Obtain (current coin)/(optional coin)
coin_opt_coin_ratio = coin_price / optional_coin_price

transaction_fee = self.manager.get_fee(pair.from_coin, self.config.BRIDGE, True) + self.manager.get_fee(
pair.to_coin, self.config.BRIDGE, False
)

ratio_dict[pair] = (
coin_opt_coin_ratio - transaction_fee * self.config.SCOUT_MULTIPLIER * coin_opt_coin_ratio
) - pair.ratio
# Fees
from_fee = self.manager.get_fee(pair.from_coin, self.config.BRIDGE, True)
to_fee = self.manager.get_fee(pair.to_coin, self.config.BRIDGE, False)
transaction_fee = from_fee + to_fee - from_fee * to_fee

if self.config.USE_MARGIN == "yes":
ratio_dict[pair] = (
(1- transaction_fee) * coin_opt_coin_ratio / pair.ratio - 1 - self.CONFIG.SCOUT_MARGIN
)
else:
ratio_dict[pair] = (
coin_opt_coin_ratio - transaction_fee * self.config.SCOUT_MULTIPLIER * coin_opt_coin_ratio
) - pair.ratio
return ratio_dict

def _jump_to_best_coin(self, coin: Coin, coin_price: float):
Expand Down
5 changes: 5 additions & 0 deletions binance_trade_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def __init__(self):
config = configparser.ConfigParser()
config["DEFAULT"] = {
"bridge": "USDT",
"use_margin": "no",
"scout_multiplier": "5",
"scout_margin": "0.8",
"scout_sleep_time": "5",
"hourToKeepScoutHistory": "1",
"tld": "com",
Expand Down Expand Up @@ -70,3 +72,6 @@ def __init__(self):

self.SELL_TIMEOUT = os.environ.get("SELL_TIMEOUT") or config.get(USER_CFG_SECTION, "sell_timeout")
self.BUY_TIMEOUT = os.environ.get("BUY_TIMEOUT") or config.get(USER_CFG_SECTION, "buy_timeout")

self.USE_MARGIN = os.environ.get("USE_MARGIN") or config.get(USER_CFG_SECTION, "use_margin")
self.SCOUT_MARGIN = os.environ.get("SCOUT_MARGIN") or config.get(USER_CFG_SECTION, "scout_margin")

0 comments on commit 57df16f

Please sign in to comment.