Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scout margin formula #10

Open
wants to merge 4 commits into
base: wip/order_book
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
enable_paper_trading=False
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ Create a .cfg file named `user.cfg` based off `.user.cfg.example`, then add your
- **bridge** - Your bridge currency of choice. Notice that different bridges will allow different sets of supported coins. For example, there may be a Binance particular-coin/USDT pair but no particular-coin/BUSD pair.
- **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.
- **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
- **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.
- **enable_paper_trading** - (`True` or `False` default `False`) run bot with virtual wallet to check its performance without risking any money.
Expand Down
17 changes: 11 additions & 6 deletions binance_trade_bot/auto_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,18 @@ def _get_ratios(
# Obtain (current coin)/(optional coin)
coin_opt_coin_ratio = coin_sell_price / optional_coin_buy_price

transaction_fee = self.manager.get_fee(coin.symbol, self.config.BRIDGE.symbol, True) + self.manager.get_fee(
to_coin.symbol, self.config.BRIDGE.symbol, False
)
from_fee = self.manager.get_fee(coin.symbol, self.config.BRIDGE.symbol, True)
to_fee = self.manager.get_fee(to_coin.symbol, self.config.BRIDGE.symbol, False)
transaction_fee = from_fee + to_fee - from_fee * to_fee

ratio_dict[(coin.idx, to_coin.idx)] = (
coin_opt_coin_ratio - transaction_fee * self.config.SCOUT_MULTIPLIER * coin_opt_coin_ratio
) - ratio
if self.config.USE_MARGIN == "yes":
ratio_dict[(coin.idx, to_coin.idx)] = (
(1 - transaction_fee) * coin_opt_coin_ratio / ratio - 1 - self.config.SCOUT_MARGIN / 100
)
else:
ratio_dict[(coin.idx, to_coin.idx)] = (
coin_opt_coin_ratio - transaction_fee * self.config.SCOUT_MULTIPLIER * coin_opt_coin_ratio
) - ratio

if len(scout_logs) > 0:
self.db.batch_log_scout(scout_logs)
Expand Down
6 changes: 6 additions & 0 deletions binance_trade_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def __init__(self):
config = configparser.ConfigParser()
config["DEFAULT"] = {
"bridge": "USDT",
"use_margin": "no",
"scout_multiplier": "5",
"scout_margin": "0.8",
"scout_sleep_time": "1",
"hourToKeepScoutHistory": "1",
"tld": "com",
Expand Down Expand Up @@ -43,6 +45,10 @@ def __init__(self):
os.environ.get("SCOUT_SLEEP_TIME") or config.get(USER_CFG_SECTION, "scout_sleep_time")
)

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")
self.SCOUT_MARGIN = float(self.SCOUT_MARGIN)

# Get config for binance
self.BINANCE_API_KEY = os.environ.get("API_KEY") or config.get(USER_CFG_SECTION, "api_key")
self.BINANCE_API_SECRET_KEY = os.environ.get("API_SECRET_KEY") or config.get(USER_CFG_SECTION, "api_secret_key")
Expand Down